/// <summary> /// Binds a linear address range to the texture reference. <para/> /// Any previous address or CUDA array state associated with the texture reference is superseded by this function. <para/> /// Any memory previously bound to the texture reference is unbound.<para/> /// Size my differ to the previous bound variable, but type must be the same. /// </summary> /// <param name="deviceVar">New device variable to bind this texture reference to.</param> public void Reset(CudaPitchedDeviceVariable <T> deviceVar) { if (disposed) { throw new ObjectDisposedException(this.ToString()); } _height = deviceVar.Height; _width = deviceVar.Width; _dataSize = deviceVar.TotalSizeInBytes; _devVar = deviceVar; 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); } }
/// <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 CudaArray2D(CUarray cuArray, bool isOwner) { _cuArray = cuArray; _arrayDescriptor = new CUDAArrayDescriptor(); res = DriverAPINativeMethods.ArrayManagement.cuArrayGetDescriptor_v2(ref _arrayDescriptor, _cuArray); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuArrayGetDescriptor", res)); if (res != CUResult.Success) { throw new CudaException(res); } _isOwner = isOwner; }
/// <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> /// 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); }