From 3aa424220e6c64099b64ab15e6489d296431f542 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 22 Nov 2021 14:01:47 +0100 Subject: Replace texref by texobj in cone_bp --- cuda/3d/cone_bp.cu | 76 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 34 deletions(-) (limited to 'cuda/3d/cone_bp.cu') diff --git a/cuda/3d/cone_bp.cu b/cuda/3d/cone_bp.cu index e265304..3092467 100644 --- a/cuda/3d/cone_bp.cu +++ b/cuda/3d/cone_bp.cu @@ -35,10 +35,6 @@ along with the ASTRA Toolbox. If not, see . #include -typedef texture texture3D; - -static texture3D gT_coneProjTexture; - namespace astraCUDA3d { static const unsigned int g_volBlockZ = 6; @@ -57,28 +53,35 @@ struct DevConeParams { __constant__ DevConeParams gC_C[g_MaxAngles]; -bool bindProjDataTexture(const cudaArray* array) +bool bindProjDataTexture(cudaArray* array, cudaTextureObject_t& texObj) { - cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(); - - gT_coneProjTexture.addressMode[0] = cudaAddressModeBorder; - gT_coneProjTexture.addressMode[1] = cudaAddressModeBorder; - gT_coneProjTexture.addressMode[2] = cudaAddressModeBorder; - gT_coneProjTexture.filterMode = cudaFilterModeLinear; - gT_coneProjTexture.normalized = false; - - cudaBindTextureToArray(gT_coneProjTexture, array, channelDesc); - - // TODO: error value? - - return true; + cudaChannelFormatDesc channelDesc = + cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat); + + cudaResourceDesc resDesc; + memset(&resDesc, 0, sizeof(resDesc)); + resDesc.resType = cudaResourceTypeArray; + resDesc.res.array.array = array; + + cudaTextureDesc texDesc; + memset(&texDesc, 0, sizeof(texDesc)); + texDesc.addressMode[0] = cudaAddressModeBorder; + texDesc.addressMode[1] = cudaAddressModeBorder; + texDesc.addressMode[2] = cudaAddressModeBorder; + texDesc.filterMode = cudaFilterModeLinear; + texDesc.readMode = cudaReadModeElementType; + texDesc.normalizedCoords = 0; + + return checkCuda(cudaCreateTextureObject(&texObj, &resDesc, &texDesc, NULL), "cone_bp texture"); } //__launch_bounds__(32*16, 4) template -__global__ void dev_cone_BP(void* D_volData, unsigned int volPitch, int startAngle, - int angleOffset, const astraCUDA3d::SDimensions3D dims, +__global__ void dev_cone_BP(void* D_volData, unsigned int volPitch, + cudaTextureObject_t tex, + int startAngle, int angleOffset, + const astraCUDA3d::SDimensions3D dims, float fOutputScale) { float* volData = (float*)D_volData; @@ -133,7 +136,7 @@ __global__ void dev_cone_BP(void* D_volData, unsigned int volPitch, int startAng fr = __fdividef(1.0f, fDen); fU = fUNum * fr; fV = fVNum * fr; - float fVal = tex3D(gT_coneProjTexture, fU, fAngle, fV); + float fVal = tex3D(tex, fU, fAngle, fV); Z[idx] += fr*fr*fVal; fUNum += fCu.z; @@ -154,7 +157,7 @@ __global__ void dev_cone_BP(void* D_volData, unsigned int volPitch, int startAng // supersampling version -__global__ void dev_cone_BP_SS(void* D_volData, unsigned int volPitch, int startAngle, int angleOffset, const SDimensions3D dims, int iRaysPerVoxelDim, float fOutputScale) +__global__ void dev_cone_BP_SS(void* D_volData, unsigned int volPitch, cudaTextureObject_t tex, int startAngle, int angleOffset, const SDimensions3D dims, int iRaysPerVoxelDim, float fOutputScale) { float* volData = (float*)D_volData; @@ -220,7 +223,7 @@ __global__ void dev_cone_BP_SS(void* D_volData, unsigned int volPitch, int start const float fU = fUNum * fr; const float fV = fVNum * fr; - fVal += tex3D(gT_coneProjTexture, fU, fAngle, fV) * fr * fr; + fVal += tex3D(tex, fU, fAngle, fV) * fr * fr; fZs += fSubStep; } @@ -313,7 +316,8 @@ bool ConeBP_Array(cudaPitchedPtr D_volumeData, const SDimensions3D& dims, const SConeProjection* angles, const SProjectorParams3D& params) { - bindProjDataTexture(D_projArray); + cudaTextureObject_t D_texObj; + bindProjDataTexture(D_projArray, D_texObj); float fOutputScale; if (params.bFDKWeighting) { @@ -323,14 +327,16 @@ bool ConeBP_Array(cudaPitchedPtr D_volumeData, fOutputScale = params.fOutputScale * (params.fVolScaleX * params.fVolScaleY * params.fVolScaleZ); } + bool ok = true; + for (unsigned int th = 0; th < dims.iProjAngles; th += g_MaxAngles) { unsigned int angleCount = g_MaxAngles; if (th + angleCount > dims.iProjAngles) angleCount = dims.iProjAngles - th; - bool ok = transferConstants(angles, angleCount, params); + ok = transferConstants(angles, angleCount, params); if (!ok) - return false; + break; dim3 dimBlock(g_volBlockX, g_volBlockY); @@ -343,31 +349,33 @@ bool ConeBP_Array(cudaPitchedPtr D_volumeData, // printf("Calling BP: %d, %dx%d, %dx%d to %p\n", i, dimBlock.x, dimBlock.y, dimGrid.x, dimGrid.y, (void*)D_volumeData.ptr); if (params.bFDKWeighting) { if (dims.iVolZ == 1) { - dev_cone_BP<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), i, th, dims, fOutputScale); + dev_cone_BP<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), D_texObj, i, th, dims, fOutputScale); } else { - dev_cone_BP<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), i, th, dims, fOutputScale); + dev_cone_BP<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), D_texObj, i, th, dims, fOutputScale); } } else if (params.iRaysPerVoxelDim == 1) { if (dims.iVolZ == 1) { - dev_cone_BP<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), i, th, dims, fOutputScale); + dev_cone_BP<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), D_texObj, i, th, dims, fOutputScale); } else { - dev_cone_BP<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), i, th, dims, fOutputScale); + dev_cone_BP<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), D_texObj, i, th, dims, fOutputScale); } } else - dev_cone_BP_SS<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), i, th, dims, params.iRaysPerVoxelDim, fOutputScale); + dev_cone_BP_SS<<>>(D_volumeData.ptr, D_volumeData.pitch/sizeof(float), D_texObj, i, th, dims, params.iRaysPerVoxelDim, fOutputScale); } // TODO: Consider not synchronizing here, if possible. - if (!checkCuda(cudaThreadSynchronize(), "cone_bp")) - return false; + ok = checkCuda(cudaThreadSynchronize(), "cone_bp"); + if (!ok) + break; angles = angles + angleCount; // printf("%f\n", toc(t)); } + cudaDestroyTextureObject(D_texObj); - return true; + return ok; } bool ConeBP(cudaPitchedPtr D_volumeData, -- cgit v1.2.3 From d4645875801d29402b1e3f2a42a5d9902a37a718 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 22 Nov 2021 14:14:55 +0100 Subject: De-duplicate 3D texture object creation --- cuda/3d/cone_bp.cu | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'cuda/3d/cone_bp.cu') diff --git a/cuda/3d/cone_bp.cu b/cuda/3d/cone_bp.cu index 3092467..41d781c 100644 --- a/cuda/3d/cone_bp.cu +++ b/cuda/3d/cone_bp.cu @@ -53,29 +53,6 @@ struct DevConeParams { __constant__ DevConeParams gC_C[g_MaxAngles]; -bool bindProjDataTexture(cudaArray* array, cudaTextureObject_t& texObj) -{ - cudaChannelFormatDesc channelDesc = - cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat); - - cudaResourceDesc resDesc; - memset(&resDesc, 0, sizeof(resDesc)); - resDesc.resType = cudaResourceTypeArray; - resDesc.res.array.array = array; - - cudaTextureDesc texDesc; - memset(&texDesc, 0, sizeof(texDesc)); - texDesc.addressMode[0] = cudaAddressModeBorder; - texDesc.addressMode[1] = cudaAddressModeBorder; - texDesc.addressMode[2] = cudaAddressModeBorder; - texDesc.filterMode = cudaFilterModeLinear; - texDesc.readMode = cudaReadModeElementType; - texDesc.normalizedCoords = 0; - - return checkCuda(cudaCreateTextureObject(&texObj, &resDesc, &texDesc, NULL), "cone_bp texture"); -} - - //__launch_bounds__(32*16, 4) template __global__ void dev_cone_BP(void* D_volData, unsigned int volPitch, @@ -317,7 +294,8 @@ bool ConeBP_Array(cudaPitchedPtr D_volumeData, const SProjectorParams3D& params) { cudaTextureObject_t D_texObj; - bindProjDataTexture(D_projArray, D_texObj); + if (!createTextureObject3D(D_projArray, D_texObj)) + return false; float fOutputScale; if (params.bFDKWeighting) { -- cgit v1.2.3