public CUtexref GetModuleTexture(CUmodule mod, string textureName) { CUtexref pTexRef = new CUtexref(); this.LastError = CUDADriver.cuModuleGetTexRef(ref pTexRef, mod, textureName); return(pTexRef); }
public CUAddressMode GetTextureAddressMode(CUtexref tex, int dimension) { CUAddressMode wrap = CUAddressMode.Wrap; this.LastError = CUDADriver.cuTexRefGetAddressMode(ref wrap, tex, dimension); return(wrap); }
public CUdeviceptr GetTextureAddress(CUtexref tex) { CUdeviceptr pdptr = new CUdeviceptr(); this.LastError = CUDADriver.cuTexRefGetAddress(ref pdptr, tex); return(pdptr); }
public uint SetTextureAddress(CUtexref tex, CUdeviceptr dptr, uint bytes) { uint byteOffset = 0; this.LastError = CUDADriver.cuTexRefSetAddress(ref byteOffset, tex, dptr, bytes); return(byteOffset); }
public CUFilterMode GetTextureFilterMode(CUtexref tex) { CUFilterMode point = CUFilterMode.Point; this.LastError = CUDADriver.cuTexRefGetFilterMode(ref point, tex); return(point); }
public uint GetTextureFlags(CUtexref tex) { uint pFlags = 0; this.LastError = CUDADriver.cuTexRefGetFlags(ref pFlags, tex); return(pFlags); }
public CUtexref CreateTexture() { CUtexref pTexRef = new CUtexref(); this.LastError = CUDADriver.cuTexRefCreate(ref pTexRef); return(pTexRef); }
public CUarray GetTextureArray(CUtexref tex) { CUarray phArray = new CUarray(); this.LastError = CUDADriver.cuTexRefGetArray(ref phArray, tex); return(phArray); }
/// <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); }
public CUArrayFormat GetTextureFormat(CUtexref tex) { CUArrayFormat pFormat = (CUArrayFormat)0; int pNumChannels = 0; this.LastError = CUDADriver.cuTexRefGetFormat(ref pFormat, ref pNumChannels, tex); return(pFormat); }
public override void Init() { cuda = new CUDA(0, true); var cuCtx = cuda.CreateContext(0, CUCtxFlags.MapHost); cuda.SetCurrentContext(cuCtx); cuModule = cuda.LoadModule(Path.Combine(Environment.CurrentDirectory, cudaModuleName)); cuFunc = cuda.GetModuleFunction(cudaEvaluatorKernelName); cuFuncSign = cuda.GetModuleFunction(cudaSignKernelName); //reserved memory based on dimension of support vector //svVector = new float[TrainedModel.SupportElements[0].Count]; stream = cuda.CreateStream(); //memSvSize = (uint)(TrainedModel.SupportElements[0].Count * sizeof(float)); memSvSize = (uint)(TrainedModel.SupportElements[0].Dim * sizeof(float)); //allocates memory for buffers svVecIntPtrs[0] = cuda.AllocateHost(memSvSize); svVecIntPtrs[1] = cuda.AllocateHost(memSvSize); mainVecPtr = cuda.CopyHostToDeviceAsync(svVecIntPtrs[0], memSvSize, stream); cuSVTexRef = cuda.GetModuleTexture(cuModule, "svTexRef"); cuda.SetTextureFlags(cuSVTexRef, 0); cuda.SetTextureAddress(cuSVTexRef, mainVecPtr, memSvSize); //todo: copy labels and alphas float[] svLabels = new float[TrainedModel.SupportElements.Length]; float[] svAlphas = new float[TrainedModel.SupportElements.Length]; Parallel.For(0, TrainedModel.SupportElementsIndexes.Length, i => { int idx = TrainedModel.SupportElementsIndexes[i]; svLabels[i] = TrainedModel.Y[i]; //svLabels[i] = TrainningProblem.Labels[idx]; svAlphas[i] = TrainedModel.Alpha[idx]; }); //for (int i = 0; i < TrainedModel.SupportElementsIndexes.Length; i++) //{ // int idx = TrainedModel.SupportElementsIndexes[i]; // svLabels[i]= TrainningProblem.Labels[idx]; // svAlphas[i] = TrainedModel.Alpha[idx]; //} labelsPtr = cuda.CopyHostToDevice(svLabels); alphasPtr = cuda.CopyHostToDevice(svAlphas); IsInitialized = true; }
public void SetTextureAddress(CUtexref tex, CUDAArrayDescriptor desc, CUdeviceptr dptr, uint pitch) { if (_version >= 4010) { this.LastError = CUDADriver.cuTexRefSetAddress2D_v3(tex, desc, dptr, pitch); } else { this.LastError = CUDADriver.cuTexRefSetAddress2D(tex, desc, dptr, pitch); } }
public CudaFunctionCall AddParameter(CUtexref texture) { _cuda.SetParameter(_function, texture); return(this); }
/// <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); }
/// <summary> /// set cuda texture memory based on array /// </summary> /// <param name="texture"></param> /// <param name="texName"></param> /// <param name="data"></param> /// <param name="memPtr"></param> protected void SetTextureMemory(ref CUtexref texture, string texName, float[] data, ref CUdeviceptr memPtr) { texture = cuda.GetModuleTexture(cuModule, texName); memPtr = cuda.CopyHostToDevice(data); cuda.SetTextureAddress(texture, memPtr, (uint)(sizeof(float) * data.Length)); }
/// <summary> /// set cuda texture memory /// </summary> /// <param name="texture"></param> /// <param name="texName"></param> /// <param name="memPtr"></param> /// <param name="memSize"></param> private void SetTextureMemory(ref CUtexref texture, string texName, ref CUdeviceptr memPtr, uint memSize) { texture = cuda.GetModuleTexture(cuModule, texName); memPtr = cuda.Allocate(memSize); cuda.SetTextureAddress(texture, memPtr, memSize); }
/// <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); }
public static float[] CRSSparseMMwithDenseVector(int repetition, string moduleFunction, int blockSizeX, int blockSizeY) { CUDA cuda = new CUDA(0, true); // load module CUmodule module = cuda.LoadModule(Path.Combine(Environment.CurrentDirectory, "matrixKernels.cubin")); CUfunction cuFunc = cuda.GetModuleFunction(moduleFunction); int maxRowSize = avgElements + stdElements - 1; Console.WriteLine("------------------------------------"); Console.WriteLine("init Matrix"); Stopwatch t = Stopwatch.StartNew(); //values in CRS format float[] AVals, BVals; //indexes in Crs format int[] AIdx, BIdx; //Lenght of each row in CRS format int[] ARowLen, BRowLen; int maxIndex = 0; MakeRandCrsSparseMatrix(Rows, maxRowSize, out AVals, out AIdx, out ARowLen, out maxIndex); // DisplayCrsMatrix(AVals, AIdx, ARowLen,maxIndex); MakeRandCrsSparseMatrix(Cols, maxRowSize, out BVals, out BIdx, out BRowLen, out maxIndex); //DisplayCrsMatrix(BVals, BIdx, BRowLen, maxIndex); Console.WriteLine("Init takes {0}", t.Elapsed); t.Start(); CUdeviceptr AValsPtr = cuda.CopyHostToDevice(AVals); CUdeviceptr AIdxPtr = cuda.CopyHostToDevice(AIdx); CUdeviceptr ALenghtPtr = cuda.CopyHostToDevice(ARowLen); int outputSize = Rows * Cols; float[] output = new float[outputSize]; //allocate memory for output IntPtr outputPtr2 = cuda.HostAllocate((uint)(outputSize * sizeof(float)), CUDADriver.CU_MEMHOSTALLOC_DEVICEMAP); CUdeviceptr dOutput = cuda.GetHostDevicePointer(outputPtr2, 0); //create dense vector for each column in B matrix float[] mainVec = new float[maxIndex + 1]; uint memSize = (uint)((maxIndex + 1) * sizeof(float)); CUstream stream0 = cuda.CreateStream(); IntPtr[] mainVecIntPtrs = new IntPtr[2]; //write combined memory allocation //IntPtr mainVecIPtr = cuda.HostAllocate(memSize,CUDADriver.CU_MEMHOSTALLOC_WRITECOMBINED); //CUdeviceptr mainVecPtr=cuda.CopyHostToDeviceAsync(mainVecIPtr,memSize,stream0); // //mainVecIntPtrs[0] = cuda.HostAllocate(memSize, CUDADriver.CU_MEMHOSTALLOC_WRITECOMBINED); //mainVecIntPtrs[1] = cuda.HostAllocate(memSize, CUDADriver.CU_MEMHOSTALLOC_WRITECOMBINED); mainVecIntPtrs[0] = cuda.AllocateHost(memSize); mainVecIntPtrs[1] = cuda.AllocateHost(memSize); CUdeviceptr mainVecPtr = cuda.CopyHostToDeviceAsync(mainVecIntPtrs[0], memSize, stream0); //IntPtr mainVecIPtr = cuda.HostAllocate(memSize,CUDADriver.CU_MEMHOSTALLOC_PORTABLE); //CUdeviceptr mainVecPtr=cuda.CopyHostToDeviceAsync(mainVecIPtr,memSize,stream0); //mapped memory allocation //IntPtr mainVecIPtr = cuda.HostAllocate(memSize, CUDADriver.CU_MEMHOSTALLOC_DEVICEMAP); //CUdeviceptr mainVecPtr = cuda.CopyHostToDevice(mainVecIPtr, memSize); //get texture reference CUtexref cuTexRef = cuda.GetModuleTexture(module, "vectorTexRef"); cuda.SetTextureFlags(cuTexRef, 0); cuda.SetTextureAddress(cuTexRef, mainVecPtr, memSize); Console.WriteLine("copy to device takes {0}", t.Elapsed); #region set cuda parameters int Aelements = AVals.Length; cuda.SetFunctionBlockShape(cuFunc, blockSizeX, blockSizeY, 1); int offset = 0; cuda.SetParameter(cuFunc, offset, AValsPtr.Pointer); offset += IntPtr.Size; cuda.SetParameter(cuFunc, offset, AIdxPtr.Pointer); offset += IntPtr.Size; cuda.SetParameter(cuFunc, offset, ALenghtPtr.Pointer); offset += IntPtr.Size; cuda.SetParameter(cuFunc, offset, dOutput.Pointer); offset += IntPtr.Size; cuda.SetParameter(cuFunc, offset, (uint)Rows); offset += sizeof(int); cuda.SetParameter(cuFunc, offset, (uint)Cols); offset += sizeof(int); int colIndexParamOffset = offset; cuda.SetParameter(cuFunc, offset, (uint)0); offset += sizeof(int); cuda.SetParameterSize(cuFunc, (uint)offset); #endregion Console.WriteLine("start computation"); CUevent start = cuda.CreateEvent(); CUevent end = cuda.CreateEvent(); int gridDimX = (int)Math.Ceiling((Rows + 0.0) / (blockSizeX)); int gridDim = (Rows + blockSizeX - 1) / blockSizeX; Stopwatch timer = Stopwatch.StartNew(); cuda.RecordEvent(start); for (int rep = 0; rep < repetition; rep++) { for (int k = 0; k < Cols; k++) { Helpers.InitBuffer(BVals, BIdx, BRowLen, k, mainVecIntPtrs[k % 2]); cuda.SynchronizeStream(stream0); cuda.CopyHostToDeviceAsync(mainVecPtr, mainVecIntPtrs[k % 2], memSize, stream0); cuda.SetParameter(cuFunc, colIndexParamOffset, (uint)k); cuda.LaunchAsync(cuFunc, gridDimX, 1, stream0); //cuda.SynchronizeStream(stream0); ////clear host buffer Helpers.SetBufferIdx(BIdx, BRowLen, k - 1, mainVecIntPtrs[(k + 1) % 2], 0.0f); //Helpers.InitBuffer(BVals, BIdx, BRowLen, k, mainVecIPtr); ////make asynchronius copy and kernel lauch //cuda.CopyHostToDeviceAsync(mainVecPtr, mainVecIPtr, memSize, stream0); //cuda.SetParameter(cuFunc, colIndexParamOffset,(uint) k); //cuda.LaunchAsync(cuFunc, gridDimX, 1, stream0); //cuda.SynchronizeStream(stream0); ////clear host buffer //Helpers.SetBufferIdx(BIdx, BRowLen, k, mainVecIPtr, 0.0f); } } cuda.RecordEvent(end); cuda.SynchronizeContext(); timer.Stop(); float cudaTime = cuda.ElapsedTime(start, end); Marshal.Copy(outputPtr2, output, 0, outputSize); Console.WriteLine("Matrix products with kernel {0}", moduleFunction); Console.WriteLine(" takes {0} ms stopwatch time {1} ms", cudaTime, timer.Elapsed); int lenght = displayCount;// Math.Min(displayCount, Rows); Console.WriteLine(); for (int i = 0; i < lenght; i++) { Console.WriteLine("{0}-{1}", i, output[i]); } cuda.Free(AValsPtr); cuda.Free(AIdxPtr); cuda.Free(ALenghtPtr); cuda.Free(dOutput); cuda.DestroyEvent(start); cuda.DestroyEvent(end); cuda.DestroyStream(stream0); cuda.Free(mainVecPtr); cuda.DestroyTexture(cuTexRef); return(output); }
/// <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); }
public void DestroyTexture(CUtexref tex) { this.LastError = CUDADriver.cuTexRefDestroy(tex); }
/// <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.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.cuTexRefSetAddressMode(_texref, 2, addressMode2); 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, descriptor.Format, (int)descriptor.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; _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.Write(""); //Line(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.Write(""); //Line(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.Write(""); //Line(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.Write(""); //Line(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.Write(""); //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMipmapLevelClamp", res)); if (res != CUResult.Success) { throw new CudaException(res); } }
public void SetTextureAddressMode(CUtexref tex, int dimension, CUAddressMode addressMode) { this.LastError = CUDADriver.cuTexRefSetAddressMode(tex, dimension, addressMode); }
public void SetTextureArray(CUtexref tex, CUarray array) { this.SetTextureArray(tex, array, 1); }
public void SetTextureArray(CUtexref tex, CUarray array, uint flags) { this.LastError = CUDADriver.cuTexRefSetArray(tex, array, flags); }
public void SetTextureFilterMode(CUtexref tex, CUFilterMode filterMode) { this.LastError = CUDADriver.cuTexRefSetFilterMode(tex, filterMode); }
public void SetTextureFlags(CUtexref tex, uint flags) { this.LastError = CUDADriver.cuTexRefSetFlags(tex, flags); }
public void SetParameter(CUfunction func, CUtexref tex) { this.LastError = CUDADriver.cuParamSetTexRef(func, -1, tex); }
public void SetTextureFormat(CUtexref tex, CUArrayFormat format, int numComponents) { this.LastError = CUDADriver.cuTexRefSetFormat(tex, format, numComponents); }