Beispiel #1
0
        /// <summary>
        /// Allocates a block of memory and returns a pointer to it.
        /// </summary>
        /// <param name="sizeInBytes">The ammount of memory to allocate</param>
        /// <returns>A pointer to the new memory</returns>
        public static DevicePtr AllocRaw(uint sizeInBytes)
        {
            DevicePtr result = new DevicePtr();

            CudaUtil.Call(CudaMem.cuMemAlloc(out result.ptr, sizeInBytes));
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Allocates a block of memory sized to hold a 1D array and returns a pointer to it.
        /// </summary>
        /// <param name="elemSizeBytes">The size of each array element in bytes</param>
        /// <param name="width">The number of elements to allocate memory for</param>
        /// <returns>A pointer to the array</returns>
        public static DeviceBuffer Alloc(int elemSizeBytes, int width)
        {
            DeviceBuffer result = new DeviceBuffer();

            result.sizeInBytes = (uint)elemSizeBytes * (uint)width;
            CudaUtil.Call(CudaMem.cuMemAlloc(out result.ptr.ptr, result.sizeInBytes));
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Allocates a 2D block of memory, and returns a pointer pointing to it. Rows are NOT padded,
        /// and may not meet the hardware's alignment requirements.
        /// </summary>
        /// <param name="widthInBytes">The number of bytes to allocate for each row.</param>
        /// <param name="height">The number of rows to allocate</param>
        /// <returns>A pointer to the new block</returns>
        public static DevicePtr2D AllocRaw(uint widthInBytes, uint height)
        {
            DevicePtr2D result = new DevicePtr2D();

            result.pitch = widthInBytes;

            CudaUtil.Call(CudaMem.cuMemAlloc(out result.ptr, widthInBytes * height));
            return(result);
        }