void memory_t<CUDA>::free(){ if(!isTexture){ cuMemFree(*((CUdeviceptr*) handle)); if(!isAWrapper) delete (CUdeviceptr*) handle; } else{ CUarray &array = ((CUDATextureData_t*) handle)->array; CUsurfObject &surface = ((CUDATextureData_t*) handle)->surface; cuArrayDestroy(array); cuSurfObjectDestroy(surface); if(!isAWrapper){ delete (CUDATextureData_t*) handle; delete (CUaddress_mode*) textureInfo.arg; } } size = 0; }
bool ResourceCUDA::updateResourceFromCUDA(CUstream streamID) { CUresult res; res = cuGraphicsMapResources( 1, &m_cudaResource, streamID ); if(res) { LOGE("Error>> CUDA failed map some target resources\n"); return false; } // // Walk through output resources and perform the copies // CUarray cuArray; //# define DBGDUMMYCOPY # ifdef DBGDUMMYCOPY // interop has issues... let's compare with a copy to a basic cuda array int www = m_xByteSz/4; CUDA_ARRAY_DESCRIPTOR descr = { www,//unsigned int Width; m_creationData.sz[1],//unsigned int Height; CU_AD_FORMAT_UNSIGNED_INT8,//CUarray_format Format; 4//unsigned int NumChannels; }; res = cuArrayCreate(&cuArray, &descr); # else res = cuGraphicsSubResourceGetMappedArray( &cuArray, m_cudaResource, 0/*arrayIndex*/, 0/*mipLevel*/); # endif if(res) { res = cuGraphicsUnmapResources( 1, &m_cudaResource, streamID ); return false; } CUDA_MEMCPY2D copyInfo = { 0, ///< Source X in bytes 0, ///< Source Y CU_MEMORYTYPE_DEVICE,//< Source memory type (host, device, array) NULL, ///< Source host pointer m_dptr, ///< Source device pointer NULL, ///< Source array reference m_pitch, ///< Source pitch (ignored when src is array) 0, ///< Destination X in bytes 0, ///< Destination Y CU_MEMORYTYPE_ARRAY,///< Destination memory type (host, device, array) NULL, ///< Destination host pointer NULL, ///< Destination device pointer cuArray, ///< Destination array reference 0, ///< Destination pitch (ignored when dst is array) m_xByteSz, ///< Width of 2D memory copy in bytes m_creationData.sz[1] ///< Height of 2D memory copy }; //LOGI("cuMemcpy2D(): CU_MEMORYTYPE_DEVICE source=%x pitch=%d CU_MEMORYTYPE_ARRAY=%x widthBytes=%d height=%d\n",m_dptr, m_pitch, cuArray, m_xByteSz, m_creationData.sz[1]); res = cuMemcpy2D( ©Info ); if(res) { LOGE("Error>> CUDA failed to copy linear memory to texture (array memory)\n"); res = cuGraphicsUnmapResources( 1, &m_cudaResource, streamID ); return false; } # ifdef DBGDUMMYCOPY res = cuArrayDestroy(cuArray); # endif res = cuGraphicsUnmapResources( 1, &m_cudaResource, streamID ); if(res) { LOGE("Error>> CUDA failed unmap the resource for output result of the kernel\n"); return false; } return true; }
CuTexture::~CuTexture() { if(_texture) cuArrayDestroy(_texture); }