/// <summary> /// imports a memory pool from a shared handle.<para/> /// Specific allocations can be imported from the imported pool with cuMemPoolImportPointer.<para/> /// note Imported memory pools do not support creating new allocations. As such imported memory pools /// may not be used in cuDeviceSetMemPool or ::cuMemAllocFromPoolAsync calls. /// </summary> /// <param name="handle">OS handle of the pool to open</param> /// <param name="handleType">The type of handle being imported</param> /// <param name="flags">must be 0</param> public CudaMemoryPool(IntPtr handle, CUmemAllocationHandleType handleType, ulong flags) { _memoryPool = new CUmemoryPool(); res = DriverAPINativeMethods.MemoryManagement.cuMemPoolImportFromShareableHandle(ref _memoryPool, handle, handleType, flags); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemPoolImportFromShareableHandle", res)); if (res != CUResult.Success) { throw new CudaException(res); } _isOwner = true; }
/// <summary> /// Creates a new CudaMemoryPool. /// </summary> /// <param name="props"></param> public CudaMemoryPool(CUmemPoolProps props) { _memoryPool = new CUmemoryPool(); res = DriverAPINativeMethods.MemoryManagement.cuMemPoolCreate(ref _memoryPool, ref props); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemPoolCreate", res)); if (res != CUResult.Success) { throw new CudaException(res); } _isOwner = true; }
/// <summary> /// Gets the current or default memory pool of the CUdevice. /// </summary> /// <param name="device">The device to the memory pool from</param> /// <param name="isDefault">Get the default or the current memory pool</param> public CudaMemoryPool(CUdevice device, bool isDefault) { _memoryPool = new CUmemoryPool(); if (isDefault) { res = DriverAPINativeMethods.DeviceManagement.cuDeviceGetDefaultMemPool(ref _memoryPool, device); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuDeviceGetDefaultMemPool", res)); if (res != CUResult.Success) { throw new CudaException(res); } _isOwner = false; } else { res = DriverAPINativeMethods.DeviceManagement.cuDeviceGetMemPool(ref _memoryPool, device); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuDeviceGetMemPool", res)); if (res != CUResult.Success) { throw new CudaException(res); } _isOwner = true; } }