/// <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); } _isOwner = false; }
/// <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); }
/// <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; }
/// <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); }
/// <summary> /// Creates a CUDA mipmapped array from an existing mipmap array handle. /// </summary> /// <param name="handle">handle to wrap</param> /// <param name="format">Array format of the wrapped array. Cannot be gathered through CUDA API.</param> /// <param name="numChannels">Number of channels of wrapped array.</param> public CudaMipmappedArray(CUmipmappedArray handle, CUArrayFormat format, CudaMipmappedArrayNumChannels numChannels) { _mipmappedArray = handle; _arrayDescriptor = new CUDAArray3DDescriptor(); _arrayDescriptor.Format = format; _arrayDescriptor.NumChannels = (uint)numChannels; _isOwner = false; }
public CUArrayFormat GetTextureFormat(CUtexref tex) { CUArrayFormat pFormat = (CUArrayFormat)0; int pNumChannels = 0; this.LastError = CUDADriver.cuTexRefGetFormat(ref pFormat, ref pNumChannels, tex); return(pFormat); }
public CUarray CreateArray(CUArrayFormat format, uint channels, uint width, uint height) { CUDAArrayDescriptor desc = new CUDAArrayDescriptor { Format = format, Width = width, Height = height, NumChannels = channels }; return(this.CreateArray(desc)); }
public CUarray CreateArray(CUArrayFormat format, uint numChannels, uint width, uint height, uint depth) { CUDAArray3DDescriptor desc = new CUDAArray3DDescriptor { Width = width, Height = height, Depth = depth, Format = format, Flags = 0, NumChannels = numChannels }; return(this.CreateArray(desc)); }
/// <summary> /// Creates a new 2D texture from array memory. Allocates a new 2D array. /// </summary> /// <param name="kernel"></param> /// <param name="texName"></param> /// <param name="addressMode0"></param> /// <param name="addressMode1"></param> /// <param name="filterMode"></param> /// <param name="flags"></param> /// <param name="format"></param> /// <param name="height">In elements</param> /// <param name="width">In elements</param> /// <param name="numChannels">1,2 or 4</param> public CudaTextureArray2D(CudaKernel kernel, string texName, CUAddressMode addressMode0, CUAddressMode addressMode1, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, CudaArray2DNumChannels 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, 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.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; _addressMode0 = addressMode0; _addressMode1 = addressMode1; _format = format; _height = height; _width = width; _numChannels = (int)numChannels; _name = texName; _module = kernel.CUModule; _cufunction = kernel.CUFunction; _channelSize = CudaHelperMethods.GetChannelSize(format); _dataSize = height * width * _numChannels * _channelSize; _array = new CudaArray2D(format, width, height, 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(kernel.CUFunction, CUParameterTexRef.Default, _texref); //Debug.WriteLine("{0:G}, {1}: {2}", DateTime.Now, "cuParamSetTexRef", res); //if (res != CUResult.Success) throw new CudaException(res); }
/// <summary> /// Creates a new CUDA array. /// </summary> /// <param name="format"></param> /// <param name="width">In elements</param> /// <param name="height">In elements</param> /// <param name="numChannels"></param> public CudaArray2D(CUArrayFormat format, SizeT width, SizeT height, CudaArray2DNumChannels numChannels) { _arrayDescriptor = new CUDAArrayDescriptor(); _arrayDescriptor.Format = format; _arrayDescriptor.Height = height; _arrayDescriptor.Width = width; _arrayDescriptor.NumChannels = (uint)numChannels; _cuArray = new CUarray(); res = DriverAPINativeMethods.ArrayManagement.cuArrayCreate_v2(ref _cuArray, ref _arrayDescriptor); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuArrayCreate", res)); if (res != CUResult.Success) { throw new CudaException(res); } _isOwner = true; }
/// <summary> /// Returns the channel size of an CUDA array in bytes. /// </summary> /// <param name="format">Channel format</param> /// <returns>Size in bytes</returns> public static uint GetChannelSize(CUArrayFormat format) { uint result = 0; switch (format) { case CUArrayFormat.Float: result = sizeof(float); break; case CUArrayFormat.Half: result = sizeof(short); break; case CUArrayFormat.UnsignedInt8: result = sizeof(byte); break; case CUArrayFormat.UnsignedInt16: result = sizeof(ushort); break; case CUArrayFormat.UnsignedInt32: result = sizeof(uint); break; case CUArrayFormat.SignedInt8: result = sizeof(sbyte); break; case CUArrayFormat.SignedInt16: result = sizeof(short); break; case CUArrayFormat.SignedInt32: result = sizeof(int); break; default: throw new CudaException(CUResult.ErrorInvalidValue, "Unknown CUArrayFormat format", null); } return(result); }
/// <summary> /// Returns a CudaMipmappedArray through which the subresource of the mapped graphics resource resource which /// corresponds to array index <c>arrayIndex</c> and mipmap level <c>mipLevel</c> may be accessed. The pointer value in <c>CudaMipmappedArray</c> /// may change every time that <c>resource</c> is mapped.<para/> /// If the resource is not a texture then it cannot be accessed via an array and <see cref="CUResult.ErrorNotMappedAsArray"/> /// exception is thrwon. If <c>arrayIndex</c> is not a valid array index for the resource then <see cref="CUResult.ErrorInvalidValue"/> /// exception is thrwon. If <c>mipLevel</c> is not a valid mipmap level for the resource then <see cref="CUResult.ErrorInvalidValue"/> /// exception is thrwon. If the resource is not mapped then <see cref="CUResult.ErrorNotMapped"/> exception is thrwon. /// </summary> /// <returns></returns> public CudaMipmappedArray GetMappedMipmappedArray(CUArrayFormat format, CudaMipmappedArrayNumChannels numChannels) { if (disposed) { throw new ObjectDisposedException(this.ToString()); } CUmipmappedArray array = new CUmipmappedArray(); res = DriverAPINativeMethods.GraphicsInterop.cuGraphicsResourceGetMappedMipmappedArray(ref array, _cudaResource); Debug.Write(""); //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphicsResourceGetMappedMipmappedArray", res)); if (res != CUResult.Success) { throw new CudaException(res); } CudaMipmappedArray retVar = new CudaMipmappedArray(array, format, numChannels); return(retVar); }
/// <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; }
/// <summary> /// Returns the channel size of an CUDA array in bytes. /// </summary> /// <param name="format">Channel format</param> /// <returns>Size in bytes</returns> public static uint GetChannelSize(CUArrayFormat format) { uint result = 0; switch (format) { case CUArrayFormat.Float: result = sizeof(float); break; case CUArrayFormat.Half: result = sizeof(short); break; case CUArrayFormat.UnsignedInt8: result = sizeof(byte); break; case CUArrayFormat.UnsignedInt16: result = sizeof(ushort); break; case CUArrayFormat.UnsignedInt32: result = sizeof(uint); break; case CUArrayFormat.SignedInt8: result = sizeof(sbyte); break; case CUArrayFormat.SignedInt16: result = sizeof(short); break; case CUArrayFormat.SignedInt32: result = sizeof(int); break; default: throw new CudaException(CUResult.ErrorInvalidValue, "Unknown CUArrayFormat format", null); } return result; }
/// <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; }
/// <summary> /// Creates a new 2D texture from linear memory. /// </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="deviceVar"></param> public CudaTextureLinearPitched2D(CudaKernel kernel, string texName, CUAddressMode addressMode, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, CudaPitchedDeviceVariable <T> deviceVar) : this(kernel, texName, addressMode, addressMode, filterMode, flags, format, deviceVar) { }
/// <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); }
/// <summary> /// Creates a new 2D texture from linear memory. Allocates a new device variable /// </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="width">In elements</param> /// <param name="height">In elements</param> public CudaTextureLinearPitched2D(CudaKernel kernel, string texName, CUAddressMode addressMode, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height) : this(kernel, texName, addressMode, addressMode, filterMode, flags, format, width, height) { }
/// <summary> /// Creates a new 2D texture from linear memory. Allocates a new device variable /// </summary> /// <param name="kernel"></param> /// <param name="texName"></param> /// <param name="addressMode0"></param> /// <param name="addressMode1"></param> /// <param name="filterMode"></param> /// <param name="flags"></param> /// <param name="format"></param> /// <param name="width">In elements</param> /// <param name="height">In elements</param> public CudaTextureLinearPitched2D(CudaKernel kernel, string texName, CUAddressMode addressMode0, CUAddressMode addressMode1, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height) { _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.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); } _numChannels = CudaHelperMethods.GetNumChannels(typeof(T)); res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFormat(_texref, format, _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; _format = format; _height = height; _width = width; _name = texName; _module = kernel.CUModule; _cufunction = kernel.CUFunction; _channelSize = CudaHelperMethods.GetChannelSize(format); _dataSize = height * width * (uint)_numChannels * _channelSize; _devVar = new CudaPitchedDeviceVariable <T>(width, height); CUDAArrayDescriptor arrayDescr = new CUDAArrayDescriptor(); arrayDescr.Format = format; arrayDescr.Height = height; arrayDescr.NumChannels = (uint)_numChannels; arrayDescr.Width = width; res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddress2D_v2(_texref, ref arrayDescr, _devVar.DevicePointer, _devVar.Pitch); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddress2D", res)); if (res != CUResult.Success) { throw new CudaException(res); } //res = DriverAPINativeMethods.ParameterManagement.cuParamSetTexRef(kernel.CUFunction, CUParameterTexRef.Default, _texref); //Debug.WriteLine("{0:G}, {1}: {2}", DateTime.Now, "cuParamSetTexRef", res); //if (res != CUResult.Success) throw new CudaException(res); }
/// <summary> /// Creates a new 2D texture from array memory. Allocates a new 2D 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="height">In elements</param> /// <param name="width">In elements</param> /// <param name="numChannels">1,2 or 4</param> public CudaTextureArray2D(CudaKernel kernel, string texName, CUAddressMode addressMode, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, CudaArray2DNumChannels numChannels) : this(kernel, texName, addressMode, addressMode, filterMode, flags, format, width, height, numChannels) { }
public CUarray CreateArray(CUArrayFormat format, uint width, uint height) { return(this.CreateArray(format, 1, width, height)); }
public static extern CUResult cuTexRefSetFormat( CUtexref hTexRef, CUArrayFormat fmt, int NumPackedComponents );
/// <summary> /// Creates a new 1D texture from linear memory. Allocates a new device variable /// </summary> /// <param name="kernel"></param> /// <param name="texName"></param> /// <param name="addressMode0"></param> /// <param name="flags"></param> /// <param name="format"></param> /// <param name="size">In elements</param> public CudaTextureLinear1D(CudaKernel kernel, string texName, CUTexRefSetFlags flags, CUAddressMode addressMode0, CUArrayFormat format, SizeT size) { _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.cuTexRefSetFilterMode(_texref, CUFilterMode.Point); //Textures from linear memory can only by point filtered 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); } _numChannels = CudaHelperMethods.GetNumChannels(typeof(T)); res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFormat(_texref, format, _numChannels); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFormat", res)); if (res != CUResult.Success) { throw new CudaException(res); } _filtermode = CUFilterMode.Point; _flags = flags; _addressMode0 = addressMode0; _format = format; _size = size; _name = texName; _module = kernel.CUModule; _cufunction = kernel.CUFunction; _channelSize = CudaHelperMethods.GetChannelSize(format); _dataSize = _size * (SizeT)_numChannels * _channelSize;//; _devVar = new CudaDeviceVariable <T>(_size); SizeT NULL = 0; res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddress_v2(ref NULL, _texref, _devVar.DevicePointer, _dataSize); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddress", res)); if (res != CUResult.Success) { throw new CudaException(res); } //res = DriverAPINativeMethods.ParameterManagement.cuParamSetTexRef(kernel.CUFunction, CUParameterTexRef.Default, _texref); //Debug.WriteLine("{0:G}, {1}: {2}", DateTime.Now, "cuParamSetTexRef", res); //if (res != CUResult.Success) throw new CudaException(res); }
/// <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); }
/// <summary> /// Creates a new 2D texture from array memory /// </summary> /// <param name="kernel"></param> /// <param name="texName"></param> /// <param name="addressMode0"></param> /// <param name="addressMode1"></param> /// <param name="filterMode"></param> /// <param name="flags"></param> /// <param name="array"></param> public CudaTextureArray2D(CudaKernel kernel, string texName, CUAddressMode addressMode0, CUAddressMode addressMode1, CUFilterMode filterMode, CUTexRefSetFlags flags, CudaArray2D array) { _texref = new CUtexref(); res = DriverAPINativeMethods.ModuleManagement.cuModuleGetTexRef(ref _texref, kernel.CUModule, texName); Debug.Write("");//Line(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.Write("");//Line(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.Write("");//Line(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.Write("");//Line(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.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFlags", res)); if (res != CUResult.Success) { throw new CudaException(res); } res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFormat(_texref, array.ArrayDescriptor.Format, (int)array.ArrayDescriptor.NumChannels); Debug.Write("");//Line(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; _format = array.ArrayDescriptor.Format; _height = array.Height; _width = array.Width; _numChannels = (int)array.ArrayDescriptor.NumChannels; _name = texName; _module = kernel.CUModule; _cufunction = kernel.CUFunction; _channelSize = CudaHelperMethods.GetChannelSize(array.ArrayDescriptor.Format); _dataSize = array.Height * array.Width * array.ArrayDescriptor.NumChannels * _channelSize; _array = array; res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetArray(_texref, _array.CUArray, CUTexRefSetArrayFlags.OverrideFormat); Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetArray", res)); if (res != CUResult.Success) { throw new CudaException(res); } //res = DriverAPINativeMethods.ParameterManagement.cuParamSetTexRef(kernel.CUFunction, CUParameterTexRef.Default, _texref); //Debug.Write("");//Line("{0:G}, {1}: {2}", DateTime.Now, "cuParamSetTexRef", res); //if (res != CUResult.Success) throw new CudaException(res); }
public static extern CUResult cuTexRefGetFormat( ref CUArrayFormat pFormat, ref int pNumChannels, CUtexref hTexRef );
/// <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; }
public void SetTextureFormat(CUtexref tex, CUArrayFormat format, int numComponents) { this.LastError = CUDADriver.cuTexRefSetFormat(tex, format, numComponents); }