Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Exports a memory pool to the requested handle type.<para/>
        /// Given an IPC capable mempool, create an OS handle to share the pool with another process.<para/>
        /// A recipient process can convert the shareable handle into a mempool with::cuMemPoolImportFromShareableHandle.
        /// Individual pointers can then be shared with the ::cuMemPoolExportPointer and ::cuMemPoolImportPointer APIs.
        /// The implementation of what the shareable handle is and how it can be transferred is defined by the requested
        /// handle type.<para/>
        /// note: To create an IPC capable mempool, create a mempool with a CUmemAllocationHandleType other than CU_MEM_HANDLE_TYPE_NONE.
        /// </summary>
        /// <param name="handleType">the type of handle to create</param>
        /// <param name="flags">must be 0</param>
        public IntPtr ExportToShareableHandle(CUmemAllocationHandleType handleType, ulong flags)
        {
            IntPtr ret = new IntPtr();

            res = DriverAPINativeMethods.MemoryManagement.cuMemPoolExportToShareableHandle(ref ret, _memoryPool, handleType, flags);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemPoolExportToShareableHandle", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            return(ret);
        }