コード例 #1
0
ファイル: CudaSurface.cs プロジェクト: lvaleriu/managedCuda
		/// <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);
		}
コード例 #2
0
ファイル: CudaSurface.cs プロジェクト: lvaleriu/managedCuda
		/// <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;
		}
コード例 #3
0
ファイル: CudaSurface.cs プロジェクト: zhongkaifu/managedCuda
        /// <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);
            }
            _isOwner = true;
        }
コード例 #4
0
ファイル: CudaSurface.cs プロジェクト: zhongkaifu/managedCuda
        /// <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);
        }
コード例 #5
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;
        }
コード例 #6
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;
		}