public void InitializeData(int count) { this.count = count; IntPtr hostPointer = IntPtr.Zero; var res = DriverAPINativeMethods.MemoryManagement.cuMemAllocHost_v2(ref hostPointer, count * sizeof(ResultPoint)); if (res != CUResult.Success) { throw new CudaException(res); } hostBuffer = (ResultPoint *)hostPointer; deviceBuffer = new CudaDeviceVariable <ResultPoint>(count); for (int i = 0; i < count; i++) { hostBuffer[i].X = (uint)i; hostBuffer[i].Y = (uint)i; } defaultStream = new CudaStream(); res = DriverAPINativeMethods.AsynchronousMemcpy_v2.cuMemcpyHtoDAsync_v2( deviceBuffer.DevicePointer, hostPointer, deviceBuffer.SizeInBytes, defaultStream.Stream); if (res != CUResult.Success) { throw new CudaException(res); } IntPtr secondHostPointer = IntPtr.Zero; res = DriverAPINativeMethods.MemoryManagement.cuMemAllocHost_v2(ref secondHostPointer, count * sizeof(ResultPoint)); if (res != CUResult.Success) { throw new CudaException(res); } secondHostBuffer = (ResultPoint *)secondHostPointer; secondDeviceBuffer = new CudaDeviceVariable <ResultPoint>(count); for (int i = 0; i < count; i++) { secondHostBuffer[i].X = (uint)i; secondHostBuffer[i].Y = (uint)i; } defaultStream = new CudaStream(); res = DriverAPINativeMethods.AsynchronousMemcpy_v2.cuMemcpyHtoDAsync_v2( secondDeviceBuffer.DevicePointer, secondHostPointer, secondDeviceBuffer.SizeInBytes, defaultStream.Stream); if (res != CUResult.Success) { throw new CudaException(res); } }
private void Dispose(bool disposing) { if (disposing) { GC.SuppressFinalize(this); } if (secondHostBuffer != default(ResultPoint *)) { var tmp = new IntPtr(secondHostBuffer); secondHostBuffer = default(ResultPoint *); try { DriverAPINativeMethods.MemoryManagement.cuMemFreeHost(tmp); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } if (disposing) { Dispose(ref deviceBuffer); Dispose(ref defaultStream); Dispose(ref ctx); } }