Exemplo n.º 1
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="error"></param>
		public CudaException(CUResult error)
			: base(GetErrorMessageFromCUResult(error))
		{
			this._cudaError = error;
			this._internalDescripton = GetInternalDescriptionFromCUResult(error);
			this._internalName = GetInternalNameFromCUResult(error);
		}
Exemplo n.º 2
0
		/// <summary>
		/// Creates a new surface from array memory. Allocates new array.
		/// </summary>
		/// <param name="kernel"></param>
		/// <param name="surfName"></param>
		/// <param name="flags"></param>
		/// <param name="format"></param>
		/// <param name="width">In elements</param>
		/// <param name="height">In elements</param>
		/// <param name="depth">In elements</param>
		/// <param name="numChannels"></param>
		/// <param name="arrayFlags"></param>
		public CudaSurface(CudaKernel kernel, string surfName, CUSurfRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, SizeT depth, CudaArray3DNumChannels numChannels, CUDAArray3DFlags arrayFlags)
		{
			_surfref = new CUsurfref();
			res = DriverAPINativeMethods.ModuleManagement.cuModuleGetSurfRef(ref _surfref, kernel.CUModule, surfName);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}, Surface name: {3}", DateTime.Now, "cuModuleGetSurfRef", res, surfName));
			if (res != CUResult.Success) throw new CudaException(res);

			_flags = flags;
			_format = format;
			_height = height;
			_width = width;
			_depth = depth;
			_numChannels = (int)numChannels;
			_name = surfName;
			_module = kernel.CUModule;
			_cufunction = kernel.CUFunction;

			_channelSize = CudaHelperMethods.GetChannelSize(format);
			_dataSize = height * width * depth * _numChannels * _channelSize;
			_array = new CudaArray3D(format, width, height, depth, numChannels, arrayFlags);

			res = DriverAPINativeMethods.SurfaceReferenceManagement.cuSurfRefSetArray(_surfref, _array.CUArray, flags);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuSurfRefSetArray", res));
			if (res != CUResult.Success) throw new CudaException(res);
		}
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new Event
        /// </summary>
        /// <param name="flags">Parameters for event creation</param>
        public CudaEvent(CUEventFlags flags)
        {
            _event = new CUevent();

            res = DriverAPINativeMethods.Events.cuEventCreate(ref _event, flags);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuEventCreate", res));
            if (res != CUResult.Success) throw new CudaException(res);
        }
Exemplo n.º 4
0
		/// <summary>
		/// Creates a surface object. <c>ResDesc</c> describes
		/// the data to perform surface load/stores on. <c>ResDesc.resType</c> must be 
		/// <see cref="CUResourceType.Array"/> and  <c>ResDesc.hArray</c>
		/// must be set to a valid CUDA array handle.
		/// </summary>
		/// <param name="array">CudaArray1D</param>
		public CudaSurfObject(CudaArray1D array)
		{
			_resDesc = new CudaResourceDesc(array);

			_surfObject = new CUsurfObject();
			res = DriverAPINativeMethods.SurfaceObjects.cuSurfObjectCreate(ref _surfObject, ref _resDesc);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuSurfObjectCreate", res));
			if (res != CUResult.Success) throw new CudaException(res);
		}
Exemplo n.º 5
0
        /// <summary>
        /// Creates a new Stream
        /// </summary>
        /// <param name="flags">Parameters for stream creation (must be <see cref="CUStreamFlags.None"/>)</param>
        public CudaStream(CUStreamFlags flags)
        {
            _stream = new CUstream();

            res = DriverAPINativeMethods.Streams.cuStreamCreate(ref _stream, flags);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamCreate", res));
            if (res != CUResult.Success) throw new CudaException(res);
			_isOwner = true;
        }
Exemplo n.º 6
0
		/// <summary>
		/// Creates a texture object and returns it in pTexObject. pResDesc describes the data to texture from. pTexDesc
		/// describes how the data should be sampled.
		/// </summary>
		/// <param name="resDesc">CudaResourceDesc</param>
		/// <param name="texDesc">CudaTextureDescriptor</param>
		public CudaTexObject(CudaResourceDesc resDesc, CudaTextureDescriptor texDesc)
		{
			_resDesc = resDesc;
			_texDesc = texDesc;

			_texObject = new CUtexObject();
			res = DriverAPINativeMethods.TextureObjects.cuTexObjectCreate(ref _texObject, ref _resDesc, ref _texDesc, IntPtr.Zero);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexObjectCreate", res));
			if (res != CUResult.Success) throw new CudaException(res);


		}
 /// <summary>
 /// Asynchron copy device to host
 /// </summary>
 /// <param name="devicePtr">Pointer to device memory</param>
 /// <param name="offsetSrc">Offset to source pointer in bytes</param>
 /// <param name="offsetDest">Offset to destination pointer in bytes</param>
 /// <param name="aSizeInBytes">Bytes to copy</param>
 /// <param name="stream"></param>
 public void AsyncCopyFromDevice(CUdeviceptr devicePtr, SizeT offsetSrc, SizeT offsetDest, SizeT aSizeInBytes, CUstream stream)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.AsynchronousMemcpy_v2.cuMemcpyDtoHAsync_v2(new IntPtr(_intPtr.ToInt64() + (long)offsetDest), devicePtr + offsetSrc, aSizeInBytes, stream);
     Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyDtoHAsync", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
 /// <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);
     }
 }
 /// <summary>
 /// Synchron copy host to device
 /// </summary>
 /// <param name="devicePtr">Pointer to device memory</param>
 /// <param name="offsetSrc">Offset to source pointer in bytes</param>
 /// <param name="offsetDest">Offset to destination pointer in bytes</param>
 /// <param name="aSizeInBytes">Bytes to copy</param>
 public void SynchronCopyToDevice(CUdeviceptr devicePtr, SizeT offsetSrc, SizeT offsetDest, SizeT aSizeInBytes)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyHtoD_v2(devicePtr + offsetDest, new IntPtr(this._intPtr.ToInt64() + (long)offsetSrc), aSizeInBytes);
     Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyHtoD", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
 /// <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);
     }
 }
Exemplo n.º 11
0
        public override void CopyFromStorage(IntPtr dst, long storageIndex, long byteCount)
        {
            CUdeviceptr srcPtr = DevicePtrAtElement(storageIndex);

            // Call this method directly instead of CudaContext.CopyToHost because this method supports a long byteCount
            // CopyToHost only supports uint byteCount.
            CUResult res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyDtoH_v2(dst, srcPtr, byteCount);

            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// For IDisposable
 /// </summary>
 /// <param name="fDisposing"></param>
 protected virtual void Dispose(bool fDisposing)
 {
     if (fDisposing && !disposed)
     {
         res = DriverAPINativeMethods.MemoryManagement.cuMemFreeHost(_intPtr);
         Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemFreeHost", res));
         disposed = true;
     }
     if (!fDisposing && !disposed)
     {
         Debug.Write("");//Line(String.Format("ManagedCUDA not-disposed warning: {0}", this.GetType()));
     }
 }
 /// <summary>
 /// Asynchron Copy host to device
 /// </summary>
 /// <param name="devicePtr"></param>
 /// <param name="stream"></param>
 public void AsyncCopyToDevice(CUdeviceptr devicePtr, CUstream stream)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.AsynchronousMemcpy_v2.cuMemcpyHtoDAsync_v2(devicePtr, _intPtr, SizeInBytes, stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyHtoDAsync", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
        /// <summary>
        /// Only for ChildGraphNodes
        /// </summary>
        /// <returns></returns>
        public CudaGraph GetGraph()
        {
            CUgraph  graph = new CUgraph();
            CUResult res   = DriverAPINativeMethods.GraphManagment.cuGraphChildGraphNodeGetGraph(this, ref graph);

            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphChildGraphNodeGetGraph", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            return(new CudaGraph(graph));
        }
Exemplo n.º 15
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));
        }
Exemplo n.º 16
0
 /// <summary>
 /// For IDisposable
 /// </summary>
 /// <param name="fDisposing"></param>
 protected virtual void Dispose(bool fDisposing)
 {
     if (fDisposing && !disposed && _isOwner)
     {
         res = DriverAPINativeMethods.Streams.cuStreamDestroy_v2(_stream);
         Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamDestroy", res));
         disposed = true;
     }
     if (!fDisposing && !disposed && _isOwner)
     {
         Debug.Write("");//Line(String.Format("ManagedCUDA not-disposed warning: {0}", this.GetType()));
     }
 }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Clones a graph<para/>
        /// This function creates a copy of the original Graph.
        /// All parameters are copied into the cloned graph. The original graph may be modified
        /// after this call without affecting the clone.<para/>
        /// Child graph nodes in the original graph are recursively copied into the clone.
        /// </summary>
        public CudaGraph Clone()
        {
            CUgraph clone = new CUgraph();

            res = DriverAPINativeMethods.GraphManagment.cuGraphClone(ref clone, _graph);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphClone", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            return(new CudaGraph(clone));
        }
Exemplo n.º 19
0
        /// <summary>        ///
        /// Returns the layout properties of a sparse CUDA array
        /// Returns the layout properties of a sparse CUDA array in \p sparseProperties
        /// If the CUDA array is not allocated with flag ::CUDA_ARRAY3D_SPARSE ::CUDA_ERROR_INVALID_VALUE will be returned.
        /// If the returned value in ::CUDA_ARRAY_SPARSE_PROPERTIES::flags contains ::CU_ARRAY_SPARSE_PROPERTIES_SINGLE_MIPTAIL,
        /// then::CUDA_ARRAY_SPARSE_PROPERTIES::miptailSize represents the total size of the array.Otherwise, it will be zero.
        /// Also, the returned value in ::CUDA_ARRAY_SPARSE_PROPERTIES::miptailFirstLevel is always zero.
        /// Note that the \p array must have been allocated using ::cuArrayCreate or::cuArray3DCreate.For CUDA arrays obtained
        /// using ::cuMipmappedArrayGetLevel, ::CUDA_ERROR_INVALID_VALUE will be returned.Instead, ::cuMipmappedArrayGetSparseProperties
        /// must be used to obtain the sparse properties of the entire CUDA mipmapped array to which \p array belongs to.
        /// </summary>
        public CudaArraySparseProperties GetSparseProperties()
        {
            CudaArraySparseProperties sparseProperties = new CudaArraySparseProperties();

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

            return(sparseProperties);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Finds a cloned version of a node<para/>
        /// This function returns the node corresponding to originalNode
        /// in the original graph.<para/>
        /// This cloned graph must have been cloned from the original Graph via its Clone() method.
        /// OriginalNode must have been in that graph at the time of the call to
        /// Clone(), and the corresponding cloned node in this graph must not have
        /// been removed. The cloned node is then returned.
        /// </summary>
        /// <param name="originalNode"></param>
        public CUgraphNode NodeFindInClone(CUgraphNode originalNode)
        {
            CUgraphNode clone = new CUgraphNode();

            res = DriverAPINativeMethods.GraphManagment.cuGraphNodeFindInClone(ref clone, originalNode, _graph);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphNodeFindInClone", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            return(clone);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Synchron copy device to host
 /// </summary>
 /// <param name="devicePtr"></param>
 public void SynchronCopyToHost(CUdeviceptr devicePtr)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyDtoH_v2(this._intPtr, devicePtr, SizeInBytes);
     Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyDtoH", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
Exemplo n.º 22
0
 /// <summary>
 /// Synchron copy host to device
 /// </summary>
 /// <param name="devicePtr"></param>
 public void SynchronCopyToDevice(CudaDeviceVariable <T> devicePtr)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyHtoD_v2(devicePtr.DevicePointer, this._intPtr, SizeInBytes);
     Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyHtoD", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
Exemplo n.º 23
0
 /// <summary>
 /// Asynchron copy device to host
 /// </summary>
 /// <param name="devicePtr"></param>
 /// <param name="stream"></param>
 public void AsyncCopyFromDevice(CudaDeviceVariable <T> devicePtr, CUstream stream)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.AsynchronousMemcpy_v2.cuMemcpyDtoHAsync_v2(_intPtr, devicePtr.DevicePointer, SizeInBytes, stream);
     Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpyDtoHAsync", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
Exemplo n.º 24
0
 /// <summary>
 /// Make a compute stream wait on an event<para/>
 /// Makes all future work submitted to the Stream wait until <c>hEvent</c>
 /// reports completion before beginning execution. This synchronization
 /// will be performed efficiently on the device.
 /// <para/>
 /// The stream will wait only for the completion of the most recent
 /// host call to <see cref="CudaEvent.Record()"/> on <c>hEvent</c>. Once this call has returned,
 /// any functions (including <see cref="CudaEvent.Record()"/> and <see cref="Dispose()"/> may be
 /// called on <c>hEvent</c> again, and the subsequent calls will not have any
 /// effect on this stream.
 /// <para/>
 /// If <c>hStream</c> is 0 (the NULL stream) any future work submitted in any stream
 /// will wait for <c>hEvent</c> to complete before beginning execution. This
 /// effectively creates a barrier for all future work submitted to the context.
 /// <para/>
 /// If <see cref="CudaEvent.Record()"/> has not been called on <c>hEvent</c>, this call acts as if
 /// the record has already completed, and so is a functional no-op.
 /// </summary>
 /// <returns></returns>
 public void WaitEvent(CUevent cuevent)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.Streams.cuStreamWaitEvent(_stream, cuevent, 0);
     Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamWaitEvent", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
Exemplo n.º 25
0
 /// <summary>
 /// Waits until the device has completed all operations in the stream. If the context was created
 /// with the <see cref="CUCtxFlags.BlockingSync"/> flag, the CPU thread will block until the stream is finished with all of its
 /// tasks.
 /// </summary>
 public void Synchronize()
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.Streams.cuStreamSynchronize(_stream);
     Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamSynchronize", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Creates a CUDA mipmapped array according to <c>descriptor</c>. <para/>
        /// Width, Height, and Depth are the width, height, and depth of the CUDA array (in elements); the following
        /// types of CUDA arrays can be allocated:<para/>
        /// – A 1D mipmapped array is allocated if Height and Depth extents are both zero.<para/>
        /// – A 2D mipmapped array is allocated if only Depth extent is zero.<para/>
        /// – A 3D mipmapped array is allocated if all three extents are non-zero.<para/>
        /// – A 1D layered CUDA mipmapped array is allocated if only Height is zero and the <see cref="CUDAArray3DFlags.Layered"/>
        ///   flag is set. Each layer is a 1D array. The number of layers is determined by the depth extent.<para/>
        /// – A 2D layered CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Layered"/>
        ///   flag is set. Each layer is a 2D array. The number of layers is determined by the depth extent.<para/>
        /// – A cubemap CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Cubemap"/>
        ///   flag is set. Width must be equal to Height, and Depth must be six. A
        ///   cubemap is a special type of 2D layered CUDA array, where the six layers represent the six faces of a
        ///   cube. The order of the six layers in memory is the same as that listed in CUarray_cubemap_face.<para/>
        /// – A cubemap layered CUDA mipmapped array is allocated if all three extents are non-zero, and both,
        ///   <see cref="CUDAArray3DFlags.Cubemap"/> and <see cref="CUDAArray3DFlags.Layered"/> flags are set. Width must be equal
        ///   to Height, and Depth must be a multiple of six. A cubemap layered CUDA array is a special type of
        ///   2D layered CUDA array that consists of a collection of cubemaps. The first six layers represent the first
        ///   cubemap, the next six layers form the second cubemap, and so on.<para/>
        /// Flags may be set to:<para/>
        /// – <see cref="CUDAArray3DFlags.Layered"/> to enable creation of layered CUDA mipmapped arrays. If this flag is set,
        ///   Depth specifies the number of layers, not the depth of a 3D array.<para/>
        /// – <see cref="CUDAArray3DFlags.Cubemap"/> to enable creation of mipmapped cubemaps. If this flag is set, Width
        ///   must be equal to Height, and Depth must be six. If the CUDA_ARRAY3D_LAYERED flag is also set,
        ///   then Depth must be a multiple of six.<para/>
        /// – <see cref="CUDAArray3DFlags.TextureGather"/> to indicate that the CUDA mipmapped array will be used for
        ///   texture gather. Texture gather can only be performed on 2D CUDA mipmapped arrays.
        /// </summary>
        /// <param name="descriptor">mipmapped array descriptor</param>
        /// <param name="numMipmapLevels">Number of mipmap levels. This value is clamped to the range [1, 1 + floor(log2(max(width, height, depth)))]</param>
        public CudaMipmappedArray(CUDAArray3DDescriptor descriptor, uint numMipmapLevels)
        {
            _mipmappedArray  = new CUmipmappedArray();
            _arrayDescriptor = descriptor;

            res = DriverAPINativeMethods.ArrayManagement.cuMipmappedArrayCreate(ref _mipmappedArray, ref _arrayDescriptor, numMipmapLevels);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMipmappedArrayCreate", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            _isOwner = true;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates a texture object and returns it in pTexObject. pResDesc describes the data to texture from. pTexDesc
        /// describes how the data should be sampled.
        /// </summary>
        /// <param name="resDesc">CudaResourceDesc</param>
        /// <param name="texDesc">CudaTextureDescriptor</param>
        public CudaTexObject(CudaResourceDesc resDesc, CudaTextureDescriptor texDesc)
        {
            _resDesc = resDesc;
            _texDesc = texDesc;

            _texObject = new CUtexObject();
            res        = DriverAPINativeMethods.TextureObjects.cuTexObjectCreate(ref _texObject, ref _resDesc, ref _texDesc, IntPtr.Zero);
            Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexObjectCreate", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// For IDisposable
 /// </summary>
 /// <param name="fDisposing"></param>
 protected virtual void Dispose(bool fDisposing)
 {
     if (fDisposing && !disposed)
     {
         res = DriverAPINativeMethods.GraphManagment.cuGraphExecDestroy(_graph);
         Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphExecDestroy", res));
         disposed = true;
     }
     if (!fDisposing && !disposed)
     {
         Debug.WriteLine(String.Format("ManagedCUDA not-disposed warning: {0}", this.GetType()));
     }
 }
        /// <summary>
        /// Creates a new CudaPageLockedHostMemory and allocates the memory on host. Using cuMemAllocHost
        /// </summary>
        /// <param name="size">In elements</param>
        public CudaPageLockedHostMemory(SizeT size)
        {
            _intPtr   = new IntPtr();
            _size     = size;
            _typeSize = (SizeT)Marshal.SizeOf(typeof(T));

            res = DriverAPINativeMethods.MemoryManagement.cuMemAllocHost_v2(ref _intPtr, _typeSize * size);
            Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemHostAlloc", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            _isOwner = true;
        }
Exemplo n.º 31
0
 /// <summary>
 /// Page-locks the memory range specified by <c>p</c> and <c>bytesize</c> and maps it
 /// for the device(s) as specified by <c>Flags</c>. This memory range also is added
 /// to the same tracking mechanism as ::cuMemHostAlloc to automatically accelerate
 /// calls to functions such as <see cref="DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyHtoD_v2(BasicTypes.CUdeviceptr, VectorTypes.dim3[], BasicTypes.SizeT)"/>. Since the memory can be accessed
 /// directly by the device, it can be read or written with much higher bandwidth
 /// than pageable memory that has not been registered.  Page-locking excessive
 /// amounts of memory may degrade system performance, since it reduces the amount
 /// of memory available to the system for paging. As a result, this function is
 /// best used sparingly to register staging areas for data exchange between
 /// host and device.<para/>
 /// The pointer <c>p</c> and size <c>bytesize</c> must be aligned to the host page size (4 KB).<para/>
 /// The memory page-locked by this function must be unregistered with <see cref="Unregister"/>
 /// </summary>
 /// <param name="flags"></param>
 public void Register(CUMemHostRegisterFlags flags)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.MemoryManagement.cuMemHostRegister(_intPtr, _size, flags);
     Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemHostRegister", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
     _registered = true;
 }
Exemplo n.º 32
0
 /// <summary>
 /// For IDisposable
 /// </summary>
 /// <param name="fDisposing"></param>
 protected virtual void Dispose(bool fDisposing)
 {
     if (fDisposing && !disposed)
     {
         //_array.Dispose();
         disposed = true;
         res      = DriverAPINativeMethods.SurfaceObjects.cuSurfObjectDestroy(_surfObject);
         Debug.Write("");                //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuSurfObjectDestroy", res));
     }
     if (!fDisposing && !disposed)
     {
         Debug.Write("");                //Line(String.Format("ManagedCUDA not-disposed warning: {0}", this.GetType()));
     }
 }
Exemplo n.º 33
0
 /// <summary>
 /// Unmaps the memory range whose base address is specified by <c>p</c>, and makes it pageable again.<para/>
 /// The base address must be the same one specified to <see cref="Register"/>.
 /// </summary>
 public void Unregister()
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     res = DriverAPINativeMethods.MemoryManagement.cuMemHostUnregister(_intPtr);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemHostUnregister", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
     _registered = false;
 }
Exemplo n.º 34
0
        /// <summary>
        /// Adds a callback to be called on the host after all currently enqueued
        /// items in the stream have completed.  For each
        /// cuStreamAddCallback call, the callback will be executed exactly once.
        /// The callback will block later work in the stream until it is finished.
        /// <para/>
        /// The callback may be passed <see cref="CUResult.Success"/> or an error code.  In the event
        /// of a device error, all subsequently executed callbacks will receive an
        /// appropriate <see cref="CUResult"/>.
        /// <para/>
        /// Callbacks must not make any CUDA API calls.  Attempting to use a CUDA API
        /// will result in <see cref="CUResult.ErrorNotPermitted"/>.  Callbacks must not perform any
        /// synchronization that may depend on outstanding device work or other callbacks
        /// that are not mandated to run earlier.  Callbacks without a mandated order
        /// (in independent streams) execute in undefined order and may be serialized.
        /// <para/>
        /// This API requires compute capability 1.1 or greater.  See
        /// cuDeviceGetAttribute or ::cuDeviceGetProperties to query compute
        /// capability.  Attempting to use this API with earlier compute versions will
        /// return <see cref="CUResult.ErrorNotSupported"/>.
        /// </summary>
        /// <param name="callback">The function to call once preceding stream operations are complete</param>
        /// <param name="userData">User specified data to be passed to the callback function. Use GCAlloc to pin a managed object</param>
        /// <param name="flags">Callback flags (must be CUStreamAddCallbackFlags.None)</param>
        public void AddCallback(CUstreamCallback callback, IntPtr userData, CUStreamAddCallbackFlags flags)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }

            res = DriverAPINativeMethods.Streams.cuStreamAddCallback(_stream, callback, userData, flags);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamAddCallback", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
        /// <summary>
        /// Set <c>flags</c> for mapping the graphics resource. <para/>
        /// Changes to <c>flags</c> will take effect the next time <c>resource</c> is mapped. See <see cref="CUGraphicsMapResourceFlags"/>. <para/>
        /// If <c>resource</c> is presently mapped for access by CUDA then <see cref="CUResult.ErrorAlreadyMapped"/> exception is thrown.
        /// </summary>
        /// <param name="flags"></param>
        public void SetMapFlags(CUGraphicsMapResourceFlags flags)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }

            res = DriverAPINativeMethods.GraphicsInterop.cuGraphicsResourceSetMapFlags(_cudaResource, flags);
            Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphicsResourceSetMapFlags", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
        /// <summary>
        /// Unmaps the graphics resource.<para/>
        /// Once unmapped, the resource may not be accessed by CUDA until they are mapped again.<para/>
        /// This function provides the synchronization guarantee that any CUDA work issued in <c>stream</c> before <see cref="UnMap()"/>
        /// will complete before any subsequently issued graphics work begins.<para/>
        /// If the resource is not presently mapped for access by CUDA then <see cref="CUResult.ErrorNotMapped"/> exception is thrown.
        /// </summary>
        /// <param name="stream"></param>
        public void UnMap(CUstream stream)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }

            res = DriverAPINativeMethods.GraphicsInterop.cuGraphicsUnmapResources(1, ref _cudaResource, stream);
            Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphicsUnmapResources", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            _IsMapped = false;
        }
Exemplo n.º 37
0
		/// <summary>
		/// Creates a pending JIT linker invocation.
		/// </summary>
		/// <param name="options">Collection of linker and compiler options</param>
		public CudaLinker(CudaJitOptionCollection options)
		{
			
			_state = new CUlinkState();

			if (options == null) 
				res = DriverAPINativeMethods.ModuleManagement.cuLinkCreate(0, null, null, ref _state);
			else
				res = DriverAPINativeMethods.ModuleManagement.cuLinkCreate((uint)options.Count, options.Options, options.Values, ref _state);

			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuLinkCreate", res));
			if (res != CUResult.Success)
				throw new CudaException(res);
			

		}
Exemplo n.º 38
0
        /// <summary>
        /// Creates a new 1D texture from array memory. Allocates new array.
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="texName"></param>
        /// <param name="addressMode"></param>
        /// <param name="filterMode"></param>
        /// <param name="flags"></param>
        /// <param name="format"></param>
        /// <param name="size">In elements</param>
        /// <param name="numChannels"></param>
        public CudaTextureArray1D(CudaKernel kernel, string texName, CUAddressMode addressMode, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT size, CudaArray1DNumChannels numChannels)
        {
            _texref = new CUtexref();
            res = DriverAPINativeMethods.ModuleManagement.cuModuleGetTexRef(ref _texref, kernel.CUModule, texName);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}, Texture name: {3}", DateTime.Now, "cuModuleGetTexRef", res, texName));
            if (res != CUResult.Success) throw new CudaException(res);

            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddressMode(_texref, 0, addressMode);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddressMode", res));
            if (res != CUResult.Success) throw new CudaException(res);
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFilterMode(_texref, filterMode);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFilterMode", res));
            if (res != CUResult.Success) throw new CudaException(res);
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFlags(_texref, flags);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFlags", res));
            if (res != CUResult.Success) throw new CudaException(res);
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFormat(_texref, format, (int)numChannels);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFormat", res));
            if (res != CUResult.Success) throw new CudaException(res);

            _filtermode = filterMode;
            _flags = flags;
            _addressMode = addressMode;
            _format = format;
            _size = size;
            _numChannels = (int)numChannels;
            _name = texName;
            _module = kernel.CUModule;
            _cufunction = kernel.CUFunction;

            _channelSize = CudaHelperMethods.GetChannelSize(format);
            _dataSize = size * _numChannels * _channelSize;
            _array = new CudaArray1D(format, size, numChannels);

            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetArray(_texref, _array.CUArray, CUTexRefSetArrayFlags.OverrideFormat);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetArray", res));
            if (res != CUResult.Success) throw new CudaException(res);
            //res = DriverAPINativeMethods.ParameterManagement.cuParamSetTexRef(_cufunction, CUParameterTexRef.Default, _texref);
            //Debug.WriteLine("{0:G}, {1}: {2}", DateTime.Now, "cuParamSetTexRef", res);
            //if (res != CUResult.Success) throw new CudaException(res);
        }
Exemplo n.º 39
0
		/// <summary>
		/// Bind a CudaArray3D to a surface reference.
		/// </summary>
		/// <param name="kernel"></param>
		/// <param name="surfName"></param>
		/// <param name="flags"></param>
		/// <param name="array"></param>
		public static void BindArray(CudaKernel kernel, string surfName, CUSurfRefSetFlags flags, CudaArray3D array)
		{
			CUsurfref surfref = new CUsurfref();
			CUResult res = DriverAPINativeMethods.ModuleManagement.cuModuleGetSurfRef(ref surfref, kernel.CUModule, surfName);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}, Surface name: {3}", DateTime.Now, "cuModuleGetSurfRef", res, surfName));
			if (res != CUResult.Success) throw new CudaException(res);
			
			res = DriverAPINativeMethods.SurfaceReferenceManagement.cuSurfRefSetArray(surfref, array.CUArray, flags);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuSurfRefSetArray", res));
			if (res != CUResult.Success) throw new CudaException(res);
		}
Exemplo n.º 40
0
		/// <summary>
		/// Create a new CudaArray3D and bind it to a surface reference.
		/// </summary>
		/// <param name="kernel"></param>
		/// <param name="surfName"></param>
		/// <param name="flags"></param>
		/// <param name="format"></param>
		/// <param name="width">In elements</param>
		/// <param name="height">In elements</param>
		/// <param name="depth">In elements</param>
		/// <param name="numChannels"></param>
		/// <param name="arrayFlags"></param>
		public static CudaArray3D BindArray(CudaKernel kernel, string surfName, CUSurfRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, SizeT depth, CudaArray3DNumChannels numChannels, CUDAArray3DFlags arrayFlags)
		{
			CUsurfref surfref = new CUsurfref();
			CUResult res = DriverAPINativeMethods.ModuleManagement.cuModuleGetSurfRef(ref surfref, kernel.CUModule, surfName);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}, Surface name: {3}", DateTime.Now, "cuModuleGetSurfRef", res, surfName));
			if (res != CUResult.Success) throw new CudaException(res);

			CudaArray3D array = new CudaArray3D(format, width, height, depth, numChannels, arrayFlags);

			res = DriverAPINativeMethods.SurfaceReferenceManagement.cuSurfRefSetArray(surfref, array.CUArray, flags);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuSurfRefSetArray", res));
			if (res != CUResult.Success) throw new CudaException(res);

			return array;
		}
Exemplo n.º 41
0
		private static string GetInternalNameFromCUResult(CUResult error)
		{
			IntPtr name = new IntPtr();

			DriverAPINativeMethods.ErrorHandling.cuGetErrorName(error, ref name);
			string val = Marshal.PtrToStringAnsi(name);			
			return val;
		}
Exemplo n.º 42
0
		/// <summary>
		/// For IDisposable
		/// </summary>
		/// <param name="fDisposing"></param>
		protected virtual void Dispose(bool fDisposing)
		{
			if (fDisposing && !disposed)
			{
				//_array.Dispose();
				disposed = true;
				res = DriverAPINativeMethods.SurfaceObjects.cuSurfObjectDestroy(_surfObject);
				Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuSurfObjectDestroy", res));
			}
			if (!fDisposing && !disposed)
				Debug.WriteLine(String.Format("ManagedCUDA not-disposed warning: {0}", this.GetType()));
		}
Exemplo n.º 43
0
		/// <summary>
		/// For IDisposable
		/// </summary>
		/// <param name="fDisposing"></param>
		protected virtual void Dispose(bool fDisposing)
		{
			if (fDisposing && !disposed)
			{
				if (_isOwner)
				{
					res = DriverAPINativeMethods.ArrayManagement.cuMipmappedArrayDestroy(_mipmappedArray);
					Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMipmappedArrayDestroy", res));
				}
				disposed = true;
			}
			if (!fDisposing && !disposed)
				Debug.WriteLine(String.Format("ManagedCUDA not-disposed warning: {0}", this.GetType()));
		}
Exemplo n.º 44
0
			public static extern CUResult cuGetErrorName(CUResult error, ref IntPtr pStr);
		/// <summary> 
		/// Unmaps the memory range whose base address is specified by <c>p</c>, and makes it pageable again.<para/>
		/// The base address must be the same one specified to <see cref="Register"/>.
		/// </summary>
		public void Unregister()
		{
			if (disposed) throw new ObjectDisposedException(this.ToString());
			res = DriverAPINativeMethods.MemoryManagement.cuMemHostUnregister(_intPtr);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemHostUnregister", res));
			if (res != CUResult.Success) throw new CudaException(res);
			_registered = false;
		}
Exemplo n.º 46
0
        /// <summary>
        /// Returns true if all operations in the stream have completed, or
        /// false if not.
        /// </summary>
        /// <returns></returns>
        public bool Query()
        {
            if (disposed) throw new ObjectDisposedException(this.ToString());
            res = DriverAPINativeMethods.Streams.cuStreamQuery(_stream);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamQuery", res));
            if (res != CUResult.Success && res != CUResult.ErrorNotReady) throw new CudaException(res);

            if (res == CUResult.Success) return true;
            return false; // --> ErrorNotReady
        }
Exemplo n.º 47
0
 /// <summary>
 /// Waits until the device has completed all operations in the stream. If the context was created
 /// with the <see cref="CUCtxFlags.BlockingSync"/> flag, the CPU thread will block until the stream is finished with all of its
 /// tasks.
 /// </summary>
 public void Synchronize()
 {
     if (disposed) throw new ObjectDisposedException(this.ToString());
     res = DriverAPINativeMethods.Streams.cuStreamSynchronize(_stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamSynchronize", res));
     if (res != CUResult.Success) throw new CudaException(res);
 }
Exemplo n.º 48
0
        /// <summary>
        /// For IDisposable
        /// </summary>
        /// <param name="fDisposing"></param>
        protected virtual void Dispose(bool fDisposing)
        {
            if (fDisposing && !disposed && _isOwner)
            {
                res = DriverAPINativeMethods.Streams.cuStreamDestroy_v2(_stream);
                Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamDestroy", res));
                disposed = true;
            }
			if (!fDisposing && !disposed && _isOwner)
                Debug.WriteLine(String.Format("ManagedCUDA not-disposed warning: {0}", this.GetType()));
        }
Exemplo n.º 49
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="error"></param>
		/// <param name="message"></param>
		/// <param name="exception"></param>
		public CudaException(CUResult error, string message, Exception exception)
			: base(message, exception)
		{
			this._cudaError = error;
			this._internalDescripton = GetInternalDescriptionFromCUResult(error);
			this._internalName = GetInternalNameFromCUResult(error);
		}
        /// <summary>
		/// Creates a new mipmapped texture from array memory. Allocates a new mipmapped array.
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="texName"></param>
        /// <param name="addressMode0"></param>
        /// <param name="addressMode1"></param>
        /// <param name="addressMode2"></param>
        /// <param name="filterMode"></param>
        /// <param name="flags"></param>
        /// <param name="descriptor"></param>
        /// <param name="numMipmapLevels"></param>
        /// <param name="maxAniso"></param>
        /// <param name="mipmapFilterMode"></param>
        /// <param name="mipmapLevelBias"></param>
        /// <param name="minMipmapLevelClamp"></param>
        /// <param name="maxMipmapLevelClamp"></param>
        public CudaTextureMipmappedArray(CudaKernel kernel, string texName, CUAddressMode addressMode0, CUAddressMode addressMode1, CUAddressMode addressMode2,
			CUFilterMode filterMode, CUTexRefSetFlags flags, CUDAArray3DDescriptor descriptor, uint numMipmapLevels, 
			uint maxAniso, CUFilterMode mipmapFilterMode, float mipmapLevelBias, float minMipmapLevelClamp, float maxMipmapLevelClamp)
        {
			_maxAniso = maxAniso;
			_mipmapFilterMode = mipmapFilterMode;
			_mipmapLevelBias = mipmapLevelBias;
			_minMipmapLevelClamp = minMipmapLevelClamp;
			_maxMipmapLevelClamp = maxMipmapLevelClamp;

            _texref = new CUtexref();
            res = DriverAPINativeMethods.ModuleManagement.cuModuleGetTexRef(ref _texref, kernel.CUModule, texName);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}, Texture name: {3}", DateTime.Now, "cuModuleGetTexRef", res, texName));
            if (res != CUResult.Success) throw new CudaException(res);

            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddressMode(_texref, 0, addressMode0);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddressMode", res));
            if (res != CUResult.Success) throw new CudaException(res);
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddressMode(_texref, 1, addressMode1);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddressMode", res));
            if (res != CUResult.Success) throw new CudaException(res);
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddressMode(_texref, 2, addressMode2);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddressMode", res));
            if (res != CUResult.Success) throw new CudaException(res);
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFilterMode(_texref, filterMode);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFilterMode", res));
            if (res != CUResult.Success) throw new CudaException(res);
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFlags(_texref, flags);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFlags", res));
            if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFormat(_texref, descriptor.Format, (int)descriptor.NumChannels);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFormat", res));
            if (res != CUResult.Success) throw new CudaException(res);

            _filtermode = filterMode;
            _flags = flags;
            _addressMode0 = addressMode0;
            _addressMode1 = addressMode1;
            _addressMode2 = addressMode2;
			_arrayDescriptor = descriptor;
            _name = texName;
            _module = kernel.CUModule;
            _cufunction = kernel.CUFunction;

            _array = new CudaMipmappedArray(descriptor, numMipmapLevels);

            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMipmappedArray(_texref, _array.CUMipmappedArray, CUTexRefSetArrayFlags.OverrideFormat);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMipmappedArray", res));
			if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMaxAnisotropy(_texref, maxAniso);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMaxAnisotropy", res));
			if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMipmapFilterMode(_texref, mipmapFilterMode);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMipmapFilterMode", res));
			if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMipmapLevelBias(_texref, mipmapLevelBias);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMipmapLevelBias", res));
			if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMipmapLevelClamp(_texref, minMipmapLevelClamp, maxMipmapLevelClamp);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMipmapLevelClamp", res));
			if (res != CUResult.Success) throw new CudaException(res);
        }
Exemplo n.º 51
0
		/// <summary>
		/// Creates a CUDA mipmapped array according to <c>descriptor</c>. <para/>
		/// Width, Height, and Depth are the width, height, and depth of the CUDA array (in elements); the following
		/// types of CUDA arrays can be allocated:<para/>
		/// – A 1D mipmapped array is allocated if Height and Depth extents are both zero.<para/>
		/// – A 2D mipmapped array is allocated if only Depth extent is zero.<para/>
		/// – A 3D mipmapped array is allocated if all three extents are non-zero.<para/>
		/// – A 1D layered CUDA mipmapped array is allocated if only Height is zero and the <see cref="CUDAArray3DFlags.Layered"/> 
		///   flag is set. Each layer is a 1D array. The number of layers is determined by the depth extent.
		/// – A 2D layered CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Layered"/> 
		///   flag is set. Each layer is a 2D array. The number of layers is determined by the depth extent.
		/// – A cubemap CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Cubemap"/>
		///   flag is set. Width must be equal to Height, and Depth must be six. A
		///   cubemap is a special type of 2D layered CUDA array, where the six layers represent the six faces of a
		///   cube. The order of the six layers in memory is the same as that listed in CUarray_cubemap_face.
		/// – A cubemap layered CUDA mipmapped array is allocated if all three extents are non-zero, and both,
		///   <see cref="CUDAArray3DFlags.Cubemap"/> and <see cref="CUDAArray3DFlags.Layered"/> flags are set. Width must be equal
		///   to Height, and Depth must be a multiple of six. A cubemap layered CUDA array is a special type of
		///   2D layered CUDA array that consists of a collection of cubemaps. The first six layers represent the first
		///   cubemap, the next six layers form the second cubemap, and so on.
		/// </summary>
		/// <param name="format">Array format</param>
		/// <param name="width">Array width. See general description.</param>
		/// <param name="height">Array height. See general description.</param>
		/// <param name="depth">Array depth or layer count. See general description.</param>
		/// <param name="numChannels">number of channels</param>
		/// <param name="flags">Flags may be set to:<para/>
		/// – <see cref="CUDAArray3DFlags.Layered"/> to enable creation of layered CUDA mipmapped arrays. If this flag is set,
		///   Depth specifies the number of layers, not the depth of a 3D array.<para/>
		/// – <see cref="CUDAArray3DFlags.Cubemap"/> to enable creation of mipmapped cubemaps. If this flag is set, Width
		///   must be equal to Height, and Depth must be six. If the CUDA_ARRAY3D_LAYERED flag is also set,
		///   then Depth must be a multiple of six.<para/>
		/// – <see cref="CUDAArray3DFlags.TextureGather"/> to indicate that the CUDA mipmapped array will be used for
		///   texture gather. Texture gather can only be performed on 2D CUDA mipmapped arrays.</param>
		/// <param name="numMipmapLevels">Number of mipmap levels. This value is clamped to the range [1, 1 + floor(log2(max(width, height, depth)))]</param>
		public CudaMipmappedArray(CUArrayFormat format, SizeT width, SizeT height, SizeT depth, CudaMipmappedArrayNumChannels numChannels, CUDAArray3DFlags flags, uint numMipmapLevels)
		{
			_mipmappedArray = new CUmipmappedArray();
			_arrayDescriptor = new CUDAArray3DDescriptor();
			_arrayDescriptor.Width = width;
			_arrayDescriptor.Height = height;
			_arrayDescriptor.Depth = depth;
			_arrayDescriptor.NumChannels = (uint)numChannels;
			_arrayDescriptor.Flags = flags;
			_arrayDescriptor.Format = format;


			res = DriverAPINativeMethods.ArrayManagement.cuMipmappedArrayCreate(ref _mipmappedArray, ref _arrayDescriptor, numMipmapLevels);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMipmappedArrayCreate", res));
			if (res != CUResult.Success) throw new CudaException(res);
			_isOwner = true;
		}
Exemplo n.º 52
0
		private static string GetErrorMessageFromCUResult(CUResult error)
		{
			string message = string.Empty;

			switch (error)
			{
				case CUResult.Success:
					message = "No error.";
					break;
				case CUResult.ErrorInvalidValue:
					message = "This indicates that one or more of the parameters passed to the API call is not within an acceptable range of values.";
					break;
				case CUResult.ErrorOutOfMemory:
					message = "The API call failed because it was unable to allocate enough memory to perform the requested operation.";
					break;
				case CUResult.ErrorNotInitialized:
					message = "The CUDA driver API is not yet initialized. Call cuInit(Flags) before any other driver API call.";
					break;
				case CUResult.ErrorDeinitialized:
					message = "This indicates that the CUDA driver is in the process of shutting down.";
					break;
				case CUResult.ErrorProfilerDisabled:
					message = "This indicates profiling APIs are called while application is running in visual profiler mode.";
					break;
				//case CUResult.ErrorProfilerNotInitialized:
				//    message = "This indicates profiling has not been initialized for this context. Call cuProfilerInitialize() to resolve this.";
				//    break;
				//case CUResult.ErrorProfilerAlreadyStarted:
				//    message = "This indicates profiler has already been started and probably cuProfilerStart() is incorrectly called.";
				//    break;
				//case CUResult.ErrorProfilerAlreadyStopped:
				//    message = "This indicates profiler has already been stopped and probably cuProfilerStop() is incorrectly called.";
				//    break;
				case CUResult.ErrorNoDevice:
					message = "This indicates that no CUDA-capable devices were detected by the installed CUDA driver.";
					break;
				case CUResult.ErrorInvalidDevice:
					message = "This indicates that the device ordinal supplied by the user does not correspond to a valid CUDA device.";
					break;
				case CUResult.ErrorInvalidImage:
					message = "This indicates that the device kernel image is invalid. This can also indicate an invalid CUDA module.";
					break;
				case CUResult.ErrorInvalidContext:
					message = "This most frequently indicates that there is no context bound to the current thread. This can also be returned if the context passed to an API call is not a valid handle (such as a context that has had cuCtxDestroy() invoked on it). This can also be returned if a user mixes different API versions (i.e. 3010 context with 3020 API calls). See cuCtxGetApiVersion() for more details.";
					break;
				//CUResult.ErrorContextAlreadyCurrent is marked obsolet since CUDA version 3.2
				//case CUResult.ErrorContextAlreadyCurrent:
				//    message = "This indicated that the context being supplied as a parameter to the API call was already the active context.";
				//    break;
				case CUResult.ErrorMapFailed:
					message = "This indicates that a map or register operation has failed.";
					break;
				case CUResult.ErrorUnmapFailed:
					message = "This indicates that an unmap or unregister operation has failed.";
					break;
				case CUResult.ErrorArrayIsMapped:
					message = "This indicates that the specified array is currently mapped and thus cannot be destroyed.";
					break;
				case CUResult.ErrorAlreadyMapped:
					message = "This indicates that the resource is already mapped.";
					break;
				case CUResult.ErrorNoBinaryForGPU:
					message = "This indicates that there is no kernel image available that is suitable for the device. This can occur when a user specifies code generation options for a particular CUDA source file that do not include the corresponding device configuration.";
					break;
				case CUResult.ErrorAlreadyAcquired:
					message = "This indicates that a resource has already been acquired.";
					break;
				case CUResult.ErrorNotMapped:
					message = "This indicates that a resource is not mapped.";
					break;
				case CUResult.ErrorNotMappedAsArray:
					message = "This indicates that a mapped resource is not available for access as an array.";
					break;
				case CUResult.ErrorNotMappedAsPointer:
					message = "This indicates that a mapped resource is not available for access as a pointer.";
					break;
				case CUResult.ErrorECCUncorrectable:
					message = "This indicates that an uncorrectable ECC error was detected during execution.";
					break;
				case CUResult.ErrorUnsupportedLimit:
					message = "This indicates that the CUlimit passed to the API call is not supported by the active device.";
					break;
				case CUResult.ErrorContextAlreadyInUse:
					message = "This indicates that the ::CUcontext passed to the API call can only be bound to a single CPU thread at a time but is already bound to a CPU thread.";
					break;
				case CUResult.ErrorPeerAccessUnsupported:
					message = "This indicates that peer access is not supported across the given devices.";
					break;
				case CUResult.ErrorInvalidPtx:
					message = "This indicates that a PTX JIT compilation failed.";
					break;
				case CUResult.ErrorInvalidGraphicsContext:
					message = "This indicates an error with OpenGL or DirectX context.";
					break;
				case CUResult.ErrorInvalidSource:
					message = "This indicates that the device kernel source is invalid.";
					break;
				case CUResult.ErrorFileNotFound:
					message = "This indicates that the file specified was not found.";
					break;
				case CUResult.ErrorSharedObjectSymbolNotFound:
					message = "This indicates that a link to a shared object failed to resolve.";
					break;
				case CUResult.ErrorSharedObjectInitFailed:
					message = "This indicates that initialization of a shared object failed.";
					break;
				case CUResult.ErrorOperatingSystem:
					message = "This indicates that an OS call failed.";
					break;
				case CUResult.ErrorInvalidHandle:
					message = "This indicates that a resource handle passed to the API call was not valid. Resource handles are opaque types like CUstream and CUevent.";
					break;
				case CUResult.ErrorNotFound:
					message = "This indicates that a named symbol was not found. Examples of symbols are global/constant variable names, texture names, and surface names.";
					break;
				case CUResult.ErrorNotReady:
					message = "This indicates that asynchronous operations issued previously have not completed yet. This result is not actually an error, but must be indicated differently than CUDA_SUCCESS (which indicates completion). Calls that may return this value include cuEventQuery() and cuStreamQuery().";
					break;
				case CUResult.ErrorIllegalAddress:
					message = "While executing a kernel, the device encountered a load or store instruction on an invalid memory address.\nThe context cannot be used, so it must be destroyed (and a new one should be created).\nAll existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.";
					break;
				case CUResult.ErrorLaunchOutOfResources:
					message = "This indicates that a launch did not occur because it did not have appropriate resources. This error usually indicates that the user has attempted to pass too many arguments to the device kernel, or the kernel launch specifies too many threads for the kernel's register count. Passing arguments of the wrong size (i.e. a 64-bit pointer when a 32-bit int is expected) is equivalent to passing too many arguments and can also result in this error.";
					break;
				case CUResult.ErrorLaunchTimeout:
					message = "This indicates that the device kernel took too long to execute. This can only occur if timeouts are enabled - see the device attribute CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT for more information. The context cannot be used (and must be destroyed similar to CUDA_ERROR_LAUNCH_FAILED). All existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.";
					break;
				case CUResult.ErrorLaunchIncompatibleTexturing:
					message = "This error indicates a kernel launch that uses an incompatible texturing mode.";
					break;
				case CUResult.ErrorPeerAccessAlreadyEnabled:
					message = "This error indicates that a call to ::cuCtxEnablePeerAccess() is trying to re-enable peer access to a context which has already had peer access to it enabled.";
					break;
				case CUResult.ErrorPeerAccessNotEnabled:
					message = "This error indicates that ::cuCtxDisablePeerAccess() is trying to disable peer access which has not been enabled yet via ::cuCtxEnablePeerAccess().";
					break;
				case CUResult.ErrorPrimaryContextActice:
					message = "This error indicates that the primary context for the specified device has already been initialized.";
					break;
				case CUResult.ErrorContextIsDestroyed:
					message = "This error indicates that the context current to the calling thread has been destroyed using ::cuCtxDestroy, or is a primary context which has not yet been initialized.";
					break;
				case CUResult.ErrorAssert:
					message = "A device-side assert triggered during kernel execution. The context cannot be used anymore, and must be destroyed. All existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.";
					break;
				case CUResult.ErrorTooManyPeers:
					message = "This error indicates that the hardware resources required to enable peer access have been exhausted for one or more of the devices passed to cuCtxEnablePeerAccess().";
					break;
				case CUResult.ErrorHostMemoryAlreadyRegistered:
					message = "This error indicates that the memory range passed to cuMemHostRegister() has already been registered.";
					break;
				case CUResult.ErrorHostMemoryNotRegistered:
					message = "This error indicates that the pointer passed to cuMemHostUnregister() does not correspond to any currently registered memory region.";
					break;
				case CUResult.ErrorHardwareStackError:
					message = "While executing a kernel, the device encountered a stack error.\nThis can be due to stack corruption or exceeding the stack size limit.\nThe context cannot be used, so it must be destroyed (and a new one should be created).\nAll existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.";
					break;
				case CUResult.ErrorIllegalInstruction:
					message = "While executing a kernel, the device encountered an illegal instruction.\nThe context cannot be used, so it must be destroyed (and a new one should be created).\nAll existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.";
					break;
				case CUResult.ErrorMisalignedAddress:
					message = "While executing a kernel, the device encountered a load or store instruction on a memory address which is not aligned.\nThe context cannot be used, so it must be destroyed (and a new one should be created).\nAll existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.";
					break;
				case CUResult.ErrorInvalidAddressSpace:
					message = "While executing a kernel, the device encountered an instruction which can only operate on memory locations in certain address spaces (global, shared, or local), but was supplied a memory address not belonging to an allowed address space.\nThe context cannot be used, so it must be destroyed (and a new one should be created).\nAll existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.";
					break;
				case CUResult.ErrorInvalidPC:
					message = "While executing a kernel, the device program counter wrapped its address space.\nThe context cannot be used, so it must be destroyed (and a new one should be created).\nAll existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.";
					break;
				case CUResult.ErrorLaunchFailed:
					message = "An exception occurred on the device while executing a kernel. Common causes include dereferencing an invalid device pointer and accessing out of bounds shared memory.\nThe context cannot be used, so it must be destroyed (and a new one should be created).\nAll existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA.";
					break;
				case CUResult.ErrorNotPermitted:
					message = "This error indicates that the attempted operation is not permitted.";
					break;
				case CUResult.ErrorNotSupported:
					message = "This error indicates that the attempted operation is not supported on the current system or device.";
					break;
				case CUResult.ErrorUnknown:
					message = "This indicates that an unknown internal error has occurred.";
					break;
				default:
					break;
			}
			return error.ToString() + ": " + message;
		}
Exemplo n.º 53
0
		/// <summary>
		/// Creates a new surface from array memory.
		/// </summary>
		/// <param name="kernel"></param>
		/// <param name="surfName"></param>
		/// <param name="flags"></param>
		/// <param name="array"></param>
		public CudaSurface(CudaKernel kernel, string surfName, CUSurfRefSetFlags flags, CudaArray3D array)
		{
			_surfref = new CUsurfref();
			res = DriverAPINativeMethods.ModuleManagement.cuModuleGetSurfRef(ref _surfref, kernel.CUModule, surfName);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}, Surface name: {3}", DateTime.Now, "cuModuleGetSurfRef", res, surfName));
			if (res != CUResult.Success) throw new CudaException(res);

			_flags = flags;
			_format = array.Array3DDescriptor.Format;
			_height = array.Height;
			_width = array.Width;
			_depth = array.Depth;
			_numChannels = (int)array.Array3DDescriptor.NumChannels;
			_name = surfName;
			_module = kernel.CUModule;
			_cufunction = kernel.CUFunction;
			_channelSize = CudaHelperMethods.GetChannelSize(array.Array3DDescriptor.Format);
			_dataSize = array.Height * array.Width * array.Depth * array.Array3DDescriptor.NumChannels * _channelSize;
			_array = array;

			res = DriverAPINativeMethods.SurfaceReferenceManagement.cuSurfRefSetArray(_surfref, _array.CUArray, flags);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuSurfRefSetArray", res));
			if (res != CUResult.Success) throw new CudaException(res);
		}
Exemplo n.º 54
0
        /// <summary>
        /// Make a compute stream wait on an event<para/>
        /// Makes all future work submitted to the Stream wait until <c>hEvent</c>
        /// reports completion before beginning execution. This synchronization
        /// will be performed efficiently on the device.
        /// <para/>
        /// The stream will wait only for the completion of the most recent
        /// host call to <see cref="CudaEvent.Record()"/> on <c>hEvent</c>. Once this call has returned,
        /// any functions (including <see cref="CudaEvent.Record()"/> and <see cref="Dispose()"/> may be
        /// called on <c>hEvent</c> again, and the subsequent calls will not have any
        /// effect on this stream.
        /// <para/>
        /// If <c>hStream</c> is 0 (the NULL stream) any future work submitted in any stream
        /// will wait for <c>hEvent</c> to complete before beginning execution. This
        /// effectively creates a barrier for all future work submitted to the context.
        /// <para/>
        /// If <see cref="CudaEvent.Record()"/> has not been called on <c>hEvent</c>, this call acts as if
        /// the record has already completed, and so is a functional no-op.
        /// </summary>
        /// <returns></returns>
        public void WaitEvent(CUevent cuevent)
        {
            if (disposed) throw new ObjectDisposedException(this.ToString());
            res = DriverAPINativeMethods.Streams.cuStreamWaitEvent(_stream, cuevent, 0);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamWaitEvent", res));
            if (res != CUResult.Success) throw new CudaException(res);

        }
Exemplo n.º 55
0
		/// <summary>
		/// Creates a CUDA mipmapped array according to <c>descriptor</c>. <para/>
		/// Width, Height, and Depth are the width, height, and depth of the CUDA array (in elements); the following
		/// types of CUDA arrays can be allocated:<para/>
		/// – A 1D mipmapped array is allocated if Height and Depth extents are both zero.<para/>
		/// – A 2D mipmapped array is allocated if only Depth extent is zero.<para/>
		/// – A 3D mipmapped array is allocated if all three extents are non-zero.<para/>
		/// – A 1D layered CUDA mipmapped array is allocated if only Height is zero and the <see cref="CUDAArray3DFlags.Layered"/> 
		///   flag is set. Each layer is a 1D array. The number of layers is determined by the depth extent.<para/>
		/// – A 2D layered CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Layered"/> 
		///   flag is set. Each layer is a 2D array. The number of layers is determined by the depth extent.<para/>
		/// – A cubemap CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Cubemap"/>
		///   flag is set. Width must be equal to Height, and Depth must be six. A
		///   cubemap is a special type of 2D layered CUDA array, where the six layers represent the six faces of a
		///   cube. The order of the six layers in memory is the same as that listed in CUarray_cubemap_face.<para/>
		/// – A cubemap layered CUDA mipmapped array is allocated if all three extents are non-zero, and both,
		///   <see cref="CUDAArray3DFlags.Cubemap"/> and <see cref="CUDAArray3DFlags.Layered"/> flags are set. Width must be equal
		///   to Height, and Depth must be a multiple of six. A cubemap layered CUDA array is a special type of
		///   2D layered CUDA array that consists of a collection of cubemaps. The first six layers represent the first
		///   cubemap, the next six layers form the second cubemap, and so on.<para/>
		/// Flags may be set to:<para/>
		/// – <see cref="CUDAArray3DFlags.Layered"/> to enable creation of layered CUDA mipmapped arrays. If this flag is set,
		///   Depth specifies the number of layers, not the depth of a 3D array.<para/>
		/// – <see cref="CUDAArray3DFlags.Cubemap"/> to enable creation of mipmapped cubemaps. If this flag is set, Width
		///   must be equal to Height, and Depth must be six. If the CUDA_ARRAY3D_LAYERED flag is also set,
		///   then Depth must be a multiple of six.<para/>
		/// – <see cref="CUDAArray3DFlags.TextureGather"/> to indicate that the CUDA mipmapped array will be used for
		///   texture gather. Texture gather can only be performed on 2D CUDA mipmapped arrays.
		/// </summary>
		/// <param name="descriptor">mipmapped array descriptor</param>
		/// <param name="numMipmapLevels">Number of mipmap levels. This value is clamped to the range [1, 1 + floor(log2(max(width, height, depth)))]</param>
		public CudaMipmappedArray(CUDAArray3DDescriptor descriptor, uint numMipmapLevels)
		{
			_mipmappedArray = new CUmipmappedArray();
			_arrayDescriptor = descriptor;

			res = DriverAPINativeMethods.ArrayManagement.cuMipmappedArrayCreate(ref _mipmappedArray, ref _arrayDescriptor, numMipmapLevels);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMipmappedArrayCreate", res));
            if (res != CUResult.Success) throw new CudaException(res);
            _isOwner = true;        
		}
Exemplo n.º 56
0
 public CUDAException(CUResult error)
 {
     this.error = error;
 }
Exemplo n.º 57
0
		/// <summary> 
		/// Adds a callback to be called on the host after all currently enqueued
		/// items in the stream have completed.  For each 
		/// cuStreamAddCallback call, the callback will be executed exactly once.
		/// The callback will block later work in the stream until it is finished.
		/// <para/>
		/// The callback may be passed <see cref="CUResult.Success"/> or an error code.  In the event
		/// of a device error, all subsequently executed callbacks will receive an
		/// appropriate <see cref="CUResult"/>.
		/// <para/>
		/// Callbacks must not make any CUDA API calls.  Attempting to use a CUDA API
		/// will result in <see cref="CUResult.ErrorNotPermitted"/>.  Callbacks must not perform any
		/// synchronization that may depend on outstanding device work or other callbacks
		/// that are not mandated to run earlier.  Callbacks without a mandated order
		/// (in independent streams) execute in undefined order and may be serialized.
		/// <para/>
		/// This API requires compute capability 1.1 or greater.  See
		/// cuDeviceGetAttribute or ::cuDeviceGetProperties to query compute
		/// capability.  Attempting to use this API with earlier compute versions will
		/// return <see cref="CUResult.ErrorNotSupported"/>.
		/// </summary>
		/// <param name="callback">The function to call once preceding stream operations are complete</param>
		/// <param name="userData">User specified data to be passed to the callback function. Use GCAlloc to pin a managed object</param>
		/// <param name="flags">Callback flags (must be CUStreamAddCallbackFlags.None)</param>
		public void AddCallback(CUstreamCallback callback, IntPtr userData, CUStreamAddCallbackFlags flags)
		{
			if (disposed) throw new ObjectDisposedException(this.ToString());
			
			res = DriverAPINativeMethods.Streams.cuStreamAddCallback(_stream, callback, userData, flags);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuStreamAddCallback", res));
			if (res != CUResult.Success) throw new CudaException(res);
			
		}
Exemplo n.º 58
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;
		}
Exemplo n.º 59
0
		private static string GetInternalDescriptionFromCUResult(CUResult error)
		{
			IntPtr descr = new IntPtr();

			DriverAPINativeMethods.ErrorHandling.cuGetErrorString(error, ref descr);
			string val = Marshal.PtrToStringAnsi(descr);
			return val;
		}
Exemplo n.º 60
0
 public CUDAException(CUResult error, string message, Exception e) : base(message, e)
 {
     this.error = error;
 }