/// <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> /// 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> /// 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 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 CUDA array. /// </summary> /// <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="flags"></param> public CudaArray3D(CUArrayFormat format, SizeT width, SizeT height, SizeT depth, CudaArray3DNumChannels numChannels, CUDAArray3DFlags flags) { _array3DDescriptor = new CUDAArray3DDescriptor(); _array3DDescriptor.Format = format; _array3DDescriptor.Height = height; _array3DDescriptor.Width = width; _array3DDescriptor.Depth = depth; _array3DDescriptor.Flags = flags; _array3DDescriptor.NumChannels = (uint)numChannels; _cuArray = new CUarray(); res = DriverAPINativeMethods.ArrayManagement.cuArray3DCreate_v2(ref _cuArray, ref _array3DDescriptor); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuArray3DCreate", res)); if (res != CUResult.Success) { throw new CudaException(res); } _isOwner = true; }
/// <summary> /// Creates a new 3D texture from array memory. Allocates a new 3D 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="format"></param> /// <param name="width">In elements</param> /// <param name="height">In elements</param> /// <param name="depth">In elements</param> /// <param name="numChannels">1,2 or 4</param> public CudaTextureArray3D(CudaKernel kernel, string texName, CUAddressMode addressMode0, CUAddressMode addressMode1, CUAddressMode addressMode2, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, SizeT depth, CudaArray3DNumChannels 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.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, 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; _addressMode2 = addressMode2; _format = format; _height = height; _width = width; _depth = depth; _numChannels = (int)numChannels; _name = texName; _module = kernel.CUModule; _cufunction = kernel.CUFunction; _channelSize = CudaHelperMethods.GetChannelSize(format); _dataSize = height * width * depth * _numChannels * _channelSize; _array = new CudaArray3D(format, width, height, depth, numChannels, CUDAArray3DFlags.None); 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 3D texture from array memory. Allocates a new 3D array. /// </summary> /// <param name="kernel"></param> /// <param name="texName"></param> /// <param name="addressModeForAllDimensions"></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> /// <param name="depth">In elements</param> /// <param name="numChannels">1,2 or 4</param> public CudaTextureArray3D(CudaKernel kernel, string texName, CUAddressMode addressModeForAllDimensions, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, SizeT depth, CudaArray3DNumChannels numChannels) : this(kernel, texName, addressModeForAllDimensions, addressModeForAllDimensions, addressModeForAllDimensions, filterMode, flags, format, width, height, depth, numChannels) { }
/// <summary> /// Creates a new 3D texture from array memory. Allocates a new 3D 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="format"></param> /// <param name="width">In elements</param> /// <param name="height">In elements</param> /// <param name="depth">In elements</param> /// <param name="numChannels">1,2 or 4</param> public CudaTextureArray3D(CudaKernel kernel, string texName, CUAddressMode addressMode0, CUAddressMode addressMode1, CUAddressMode addressMode2, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, SizeT depth, CudaArray3DNumChannels 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.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, 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; _addressMode2 = addressMode2; _format = format; _height = height; _width = width; _depth = depth; _numChannels = (int)numChannels; _name = texName; _module = kernel.CUModule; _cufunction = kernel.CUFunction; _channelSize = CudaHelperMethods.GetChannelSize(format); _dataSize = height * width * depth * _numChannels * _channelSize; _array = new CudaArray3D(format, width, height, depth, numChannels, CUDAArray3DFlags.None); 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 3D texture from array memory. Allocates a new 3D array. /// </summary> /// <param name="kernel"></param> /// <param name="texName"></param> /// <param name="addressModeForAllDimensions"></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> /// <param name="depth">In elements</param> /// <param name="numChannels">1,2 or 4</param> public CudaTextureArray3D(CudaKernel kernel, string texName, CUAddressMode addressModeForAllDimensions, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, SizeT depth, CudaArray3DNumChannels numChannels) : this(kernel, texName, addressModeForAllDimensions, addressModeForAllDimensions, addressModeForAllDimensions, filterMode, flags, format, width, height, depth, numChannels) { }