示例#1
0
文件: CUDA.cs 项目: rblenis/cudafy
        public CUarray GetGraphicsSubResourceMappedArray(CUgraphicsResource resource, uint arrIndex, uint mipLevel)
        {
            CUarray pArray = new CUarray();

            this.LastError = CUDADriver.cuGraphicsSubResourceGetMappedArray(ref pArray, resource, arrIndex, mipLevel);
            return(pArray);
        }
示例#2
0
文件: CUDA.cs 项目: rblenis/cudafy
        public CUarray GetTextureArray(CUtexref tex)
        {
            CUarray phArray = new CUarray();

            this.LastError = CUDADriver.cuTexRefGetArray(ref phArray, tex);
            return(phArray);
        }
示例#3
0
文件: CUDA.cs 项目: rblenis/cudafy
        public void CopyHostToArray <T>(CUarray devArray, T[] data, uint index)
        {
            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            this.LastError = CUDADriver.cuMemcpyHtoA(devArray, index, handle.AddrOfPinnedObject(), this.GetSize <T>(data));
            handle.Free();
        }
示例#4
0
文件: CUDA.cs 项目: rblenis/cudafy
        public CUDAArrayDescriptor GetArrayDescriptor(CUarray devArr)
        {
            CUDAArrayDescriptor pArrayDescriptor = new CUDAArrayDescriptor();

            this.LastError = CUDADriver.cuArrayGetDescriptor(ref pArrayDescriptor, devArr);
            return(pArrayDescriptor);
        }
示例#5
0
文件: CUDA.cs 项目: rblenis/cudafy
        public CUarray CreateArray(CUDAArrayDescriptor desc)
        {
            CUarray pHandle = new CUarray();

            this.LastError = CUDADriver.cuArrayCreate(ref pHandle, ref desc);
            return(pHandle);
        }
示例#6
0
文件: CUDA.cs 项目: rblenis/cudafy
        public CUarray CopyHostToArray <T>(T[] data, uint index)
        {
            CUarray devArray = this.CreateArray(data);

            this.CopyHostToArray <T>(devArray, data, index);
            return(devArray);
        }
 /// <summary>
 /// Asynchron copy 1D Array to host
 /// </summary>
 /// <param name="deviceArray"></param>
 /// <param name="stream"></param>
 /// <param name="offset">bytes</param>
 public void AsyncCopyFromArray1D(CUarray deviceArray, CUstream stream, SizeT offset)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.AsynchronousMemcpy_v2.cuMemcpyAtoHAsync_v2(this._intPtr, deviceArray, offset, SizeInBytes, stream);
     Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyAtoHAsync", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
示例#8
0
        /// <summary>
        /// Creates a new CUDA array from an existing CUarray.
        /// Array properties are obtained by cuArrayGetDescriptor
        /// </summary>
        /// <param name="cuArray"></param>
        /// <param name="isOwner">The cuArray will be destroyed while disposing, if the CudaArray is the owner</param>
        public CudaArray3D(CUarray cuArray, bool isOwner)
        {
            _cuArray           = cuArray;
            _array3DDescriptor = new CUDAArray3DDescriptor();

            res = DriverAPINativeMethods.ArrayManagement.cuArray3DGetDescriptor_v2(ref _array3DDescriptor, _cuArray);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuArray3DGetDescriptor", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            _isOwner = isOwner;
        }
示例#9
0
        /// <summary>
        /// Gets a CUDA array plane from a CUDA array<para/>
        /// Returns a CUDA array that represents a single format plane
        /// of the CUDA array \p hArray.<para/>
        /// If planeIdx is greater than the maximum number of planes in this array or if the array does
        /// not have a multi-planar format e.g: ::CU_AD_FORMAT_NV12, then::CUDA_ERROR_INVALID_VALUE is returned.<para/>
        /// Note that if the \p hArray has format ::CU_AD_FORMAT_NV12, then passing in 0 for \p planeIdx returns
        /// a CUDA array of the same size as \p hArray but with one channel and::CU_AD_FORMAT_UNSIGNED_INT8 as its format.
        /// If 1 is passed for \p planeIdx, then the returned CUDA array has half the height and width
        /// of \p hArray with two channels and ::CU_AD_FORMAT_UNSIGNED_INT8 as its format.
        /// </summary>
        public CudaArray3D GetPlane(uint planeIdx)
        {
            CUarray arrayPlane = new CUarray();

            res = DriverAPINativeMethods.ArrayManagement.cuArrayGetPlane(ref arrayPlane, _cuArray, planeIdx);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuArrayGetPlane", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            return(new CudaArray3D(arrayPlane, true));
        }
示例#10
0
        /// <summary>
        /// Returns a CUDA array that represents a single mipmap level
        /// of the CUDA mipmapped array.
        /// </summary>
        /// <param name="level">Mipmap level</param>
        public CUarray GetLevelAsCUArray(uint level)
        {
            CUarray array = new CUarray();

            res = DriverAPINativeMethods.ArrayManagement.cuMipmappedArrayGetLevel(ref array, _mipmappedArray, level);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMipmappedArrayGetLevel", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            return(array);
        }
 /// <summary>
 /// Synchron copy host to 1D Array
 /// </summary>
 /// <param name="deviceArray"></param>
 /// <param name="offset"></param>
 public void SynchronCopyToArray1D(CUarray deviceArray, SizeT offset)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyHtoA_v2(deviceArray, offset, this._intPtr, SizeInBytes);
     Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyHtoA", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
示例#12
0
        /// <summary>
        /// Creates a new CUDA array.
        /// </summary>
        /// <param name="format"></param>
        /// <param name="width">In elements</param>
        /// <param name="height">In elements</param>
        /// <param name="numChannels"></param>
        public CudaArray2D(CUArrayFormat format, SizeT width, SizeT height, CudaArray2DNumChannels numChannels)
        {
            _arrayDescriptor             = new CUDAArrayDescriptor();
            _arrayDescriptor.Format      = format;
            _arrayDescriptor.Height      = height;
            _arrayDescriptor.Width       = width;
            _arrayDescriptor.NumChannels = (uint)numChannels;

            _cuArray = new CUarray();

            res = DriverAPINativeMethods.ArrayManagement.cuArrayCreate_v2(ref _cuArray, ref _arrayDescriptor);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuArrayCreate", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            _isOwner = true;
        }
        /// <summary>
        /// Returns a CUarray handle through which the subresource of the mapped graphics resource resource which
        /// corresponds to array index <c>arrayIndex</c> and mipmap level <c>mipLevel</c> may be accessed. The pointer value in <c>CUarray</c>
        /// may change every time that <c>resource</c> is mapped.<para/>
        /// If the resource is not a texture then it cannot be accessed via an array and <see cref="CUResult.ErrorNotMappedAsArray"/>
        /// exception is thrwon. If <c>arrayIndex</c> is not a valid array index for the resource then <see cref="CUResult.ErrorInvalidValue"/>
        /// exception is thrwon. If <c>mipLevel</c> is not a valid mipmap level for the resource then <see cref="CUResult.ErrorInvalidValue"/>
        /// exception is thrwon. If the resource is not mapped then <see cref="CUResult.ErrorNotMapped"/> exception is thrwon.
        /// </summary>
        /// <param name="arrayIndex"></param>
        /// <param name="mipLevel"></param>
        /// <returns></returns>
        public CUarray GetMappedCUArray(uint arrayIndex, uint mipLevel)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }

            CUarray array = new CUarray();

            res = DriverAPINativeMethods.GraphicsInterop.cuGraphicsSubResourceGetMappedArray(ref array, _cudaResource, arrayIndex, mipLevel);
            Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphicsSubResourceGetMappedArray", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            return(array);
        }
示例#14
0
        /// <summary>
        /// Asynchron copy 2D Array to host
        /// </summary>
        /// <param name="deviceArray"></param>
        /// <param name="stream"></param>
        public void AsyncCopyFromArray2D(CUarray deviceArray, CUstream stream)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }
            CUDAMemCpy2D cpyProps = new CUDAMemCpy2D();

            cpyProps.srcArray      = deviceArray;
            cpyProps.srcMemoryType = CUMemoryType.Array;
            cpyProps.dstHost       = _intPtr;
            cpyProps.dstMemoryType = CUMemoryType.Host;
            cpyProps.dstPitch      = _pitchInBytes;
            cpyProps.WidthInBytes  = _width * _typeSize;
            cpyProps.Height        = _height;

            res = DriverAPINativeMethods.AsynchronousMemcpy_v2.cuMemcpy2DAsync_v2(ref cpyProps, stream);
            Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpy2DAsync", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
        /// <summary>
        /// Synchron copy host to 3D array
        /// </summary>
        /// <param name="deviceArray"></param>
        public void SynchronCopyToArray3D(CUarray deviceArray)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }
            CUDAMemCpy3D cpyProps = new CUDAMemCpy3D();

            cpyProps.dstArray      = deviceArray;
            cpyProps.dstMemoryType = CUMemoryType.Array;
            cpyProps.srcHost       = _intPtr;
            cpyProps.srcMemoryType = CUMemoryType.Host;
            cpyProps.srcPitch      = _pitchInBytes;
            cpyProps.WidthInBytes  = _width * _typeSize;
            cpyProps.Height        = _height;
            cpyProps.Depth         = _depth;

            res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpy3D_v2(ref cpyProps);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpy3D", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
示例#16
0
文件: CUDA.cs 项目: rblenis/cudafy
 public void SetTextureArray(CUtexref tex, CUarray array)
 {
     this.SetTextureArray(tex, array, 1);
 }
示例#17
0
文件: CUDA.cs 项目: rblenis/cudafy
 public void CopyArrayToHostAsync(CUarray devArray, IntPtr buffer, uint index, uint size, CUstream stream)
 {
     this.LastError = CUDADriver.cuMemcpyAtoHAsync(buffer, devArray, index, size, stream);
 }
示例#18
0
文件: CUDA.cs 项目: rblenis/cudafy
 public void CopyArrayToArray(CUarray src, uint srcIndex, CUarray dst, uint dstIndex, uint bytes)
 {
     this.LastError = CUDADriver.cuMemcpyAtoA(dst, dstIndex, src, srcIndex, bytes);
 }
示例#19
0
文件: CUDA.cs 项目: rblenis/cudafy
 public void CopyHostToArrayAsync(CUarray devArray, IntPtr buffer, uint size, CUstream stream)
 {
     this.CopyHostToArrayAsync(devArray, 0, buffer, size, stream);
 }
示例#20
0
 /// <summary>
 /// Creates a new CUDA array from an existing CUarray.
 /// The CUarray won't be destroyed when disposing.
 /// Array properties are obtained by cuArrayGetDescriptor
 /// </summary>
 /// <param name="cuArray"></param>
 public CudaArray3D(CUarray cuArray)
     : this(cuArray, false)
 {
 }
示例#21
0
 public static extern CUResult cuD3D10ResourceGetMappedArray(ref CUarray pArray, IntPtr pResource, uint SubResource);
示例#22
0
文件: CUDA.cs 项目: rblenis/cudafy
 public void CopyHostToArrayAsync(CUarray devArray, uint index, IntPtr buffer, uint size, CUstream stream)
 {
     this.LastError = CUDADriver.cuMemcpyHtoAAsync(devArray, index, buffer, size, stream);
 }
示例#23
0
 public static extern CUResult cuD3D9ResourceGetMappedArray(ref CUarray pArray, IntPtr pResource, uint Face, uint Level);
示例#24
0
文件: CUDA.cs 项目: rblenis/cudafy
 public void DestroyArray(CUarray devArr)
 {
     this.LastError = CUDADriver.cuArrayDestroy(devArr);
 }
 /// <summary>
 /// Asynchron copy 1D Array to host
 /// </summary>
 /// <param name="deviceArray"></param>
 /// <param name="stream"></param>
 public void AsyncCopyFromArray1D(CUarray deviceArray, CUstream stream)
 {
     AsyncCopyFromArray1D(deviceArray, stream, 0);
 }
示例#26
0
文件: CUDA.cs 项目: rblenis/cudafy
 public void SetTextureArray(CUtexref tex, CUarray array, uint flags)
 {
     this.LastError = CUDADriver.cuTexRefSetArray(tex, array, flags);
 }
 /// <summary>
 /// Synchron copy 1D Array to host
 /// </summary>
 /// <param name="deviceArray"></param>
 public void SynchronCopyFromArray1D(CUarray deviceArray)
 {
     SynchronCopyFromArray1D(deviceArray, 0);
 }