/// <summary> /// Creates a surface object. <c>ResDesc</c> describes /// the data to perform surface load/stores on. <c>ResDesc.resType</c> must be /// <see cref="CUResourceType.Array"/> and <c>ResDesc.hArray</c> /// must be set to a valid CUDA array handle. /// </summary> /// <param name="array">CudaArray2D</param> public CudaSurfObject(CudaArray2D array) { _resDesc = new CudaResourceDesc(array); _surfObject = new CUsurfObject(); res = DriverAPINativeMethods.SurfaceObjects.cuSurfObjectCreate(ref _surfObject, ref _resDesc); Debug.Write(""); //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuSurfObjectCreate", res)); if (res != CUResult.Success) { throw new CudaException(res); } }
/// <summary> /// Copy array to array /// </summary> /// <param name="aDestArray"></param> public void CopyFromThisToArray(CudaArray2D aDestArray) { CUDAMemCpy2D copyParams = new CUDAMemCpy2D(); copyParams.srcArray = _cuArray; copyParams.srcMemoryType = CUMemoryType.Array; copyParams.dstArray = aDestArray.CUArray; copyParams.dstMemoryType = CUMemoryType.Array; copyParams.Height = aDestArray.ArrayDescriptor.Height; copyParams.WidthInBytes = aDestArray.ArrayDescriptor.Width * CudaHelperMethods.GetChannelSize(aDestArray.ArrayDescriptor.Format) * aDestArray.ArrayDescriptor.NumChannels; res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpy2D_v2(ref copyParams); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpy2D", res)); if (res != CUResult.Success) { throw new CudaException(res); } }
/// <summary> /// Returns a CudaArray2D 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>CudaArray2D</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> /// <param name="arrayIndex"></param> /// <param name="mipLevel"></param> /// <returns></returns> public CudaArray2D GetMappedArray2D(uint arrayIndex, uint mipLevel) { if (disposed) { throw new ObjectDisposedException(this.ToString()); } CUarray array = new CUarray(); SizeT size = 0; res = DriverAPINativeMethods.GraphicsInterop.cuGraphicsSubResourceGetMappedArray(ref array, _cudaResource, arrayIndex, mipLevel); Debug.Write(""); //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphicsSubResourceGetMappedArray", res)); if (res != CUResult.Success) { throw new CudaException(res); } CudaArray2D retVar = new CudaArray2D(array, false); return(retVar); }
/// <summary> /// Asynchron copy 2D Array to host /// </summary> /// <param name="array"></param> /// <param name="stream"></param> public void AsyncCopyFromArray2D(CudaArray2D array, CUstream stream) { AsyncCopyFromArray2D(array.CUArray, stream); }
/// <summary> /// Synchron copy 2D Array to host /// </summary> /// <param name="array"></param> public void SynchronCopyFromArray2D(CudaArray2D array) { SynchronCopyFromArray2D(array.CUArray); }
/// <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 2D texture from array memory /// </summary> /// <param name="kernel"></param> /// <param name="texName"></param> /// <param name="addressMode"></param> /// <param name="filterMode"></param> /// <param name="flags"></param> /// <param name="array"></param> public CudaTextureArray2D(CudaKernel kernel, string texName, CUAddressMode addressMode, CUFilterMode filterMode, CUTexRefSetFlags flags, CudaArray2D array) : this(kernel, texName, addressMode, addressMode, filterMode, flags, array) { }