Exemplo n.º 1
0
        public void nppsSet_32s_test()
        {
            int    length = 1024;
            int    value  = 75;
            IntPtr ptr    = Npps.nppsMalloc_32s(length);

            int[] result = new int[length];

            GCHandle gcHandle = GCHandle.Alloc(result, GCHandleType.Pinned);
            IntPtr   h_result = Marshal.UnsafeAddrOfPinnedArrayElement(result, 0);
            UInt64   size     = Convert.ToUInt64(sizeof(int) * result.Length);

            NppStatus status = Npps.nppsSet_32s(value, ptr, length);

            if (status != NppStatus.NPP_SUCCESS)
            {
                Assert.Fail(String.Format("Fail {0}", status.ToString()));
            }

            cudaError cudaStatus = CudaRuntimeApi.cudaMemcpy(h_result, ptr, size, cudaMemcpyKind.DeviceToHost);

            if (cudaStatus != cudaError.cudaSuccess)
            {
                Assert.Fail(String.Format("Fail {0}", cudaStatus.ToString()));
            }

            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(value, result[i]);
            }

            gcHandle.Free();
            Npps.nppsFree(ptr);
        }
        public void nppsConvert_32s32f_test()
        {
            NppStatus nppStatus;
            cudaError cudaStatus;
            int       length   = 1024;
            int       value    = 75;
            float     expected = 75.0F;

            IntPtr d_src = Npps.nppsMalloc_32s(length);
            IntPtr d_dst = Npps.nppsMalloc_32f(length);

            float[] result = new float[length];

            GCHandle gcHandle = GCHandle.Alloc(result, GCHandleType.Pinned);
            IntPtr   h_result = Marshal.UnsafeAddrOfPinnedArrayElement(result, 0);
            UInt64   size     = Convert.ToUInt64(sizeof(int) * result.Length);

            nppStatus = Npps.nppsSet_32s(value, d_src, length);
            if (nppStatus != NppStatus.NPP_SUCCESS)
            {
                Assert.Fail(String.Format("Fail {0}", nppStatus.ToString()));
            }

            nppStatus = Npps.nppsConvert_32s32f(d_src, d_dst, length);
            if (nppStatus != NppStatus.NPP_SUCCESS)
            {
                Assert.Fail(String.Format("Fail {0}", nppStatus.ToString()));
            }


            cudaStatus = CudaRuntimeApi.cudaMemcpy(h_result, d_dst, size, cudaMemcpyKind.DeviceToHost);
            if (cudaStatus != cudaError.cudaSuccess)
            {
                Assert.Fail(String.Format("Fail {0}", cudaStatus.ToString()));
            }

            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(expected, result[i]);
            }

            gcHandle.Free();
            Npps.nppsFree(d_src);
            Npps.nppsFree(d_dst);
        }