Esempio n. 1
0
        public void cudaHostAlloc_cudaFreeHost_test()
        {
            IntPtr ptr    = IntPtr.Zero;
            var    length = 1024 * 1024;
            var    size   = 1024 * 1024 * sizeof(float);
            var    status = CudaRuntimeApi.cudaHostAlloc(ref ptr, (ulong)size, 0);

            Assert.AreEqual(status, cudaError.cudaSuccess);
            Console.WriteLine($"ptr : {ptr}");

            float[] test   = new float[length];
            float[] result = new float[length];

            for (int i = 0; i < length; i++)
            {
                test[i] = Convert.ToSingle(i);
            }

            Marshal.Copy(test, 0, ptr, length);
            Marshal.Copy(ptr, result, 0, length);

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

            status = CudaRuntimeApi.cudaFreeHost(ptr);
            Assert.AreEqual(status, cudaError.cudaSuccess);
        }