summaryrefslogtreecommitdiffstats
path: root/cuda/2d/fan_bp.cu
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2021-11-22 14:43:07 +0100
committerWillem Jan Palenstijn <wjp@usecode.org>2021-11-26 12:09:09 +0100
commitbe2da43a560a7241c56e727fb481f1389e9f7fdf (patch)
tree318df874ff0efb63d01749006f09318289d0844b /cuda/2d/fan_bp.cu
parentc11ee1cffd53bdf4530eb4381bf484cd1a1ce9cb (diff)
downloadastra-be2da43a560a7241c56e727fb481f1389e9f7fdf.tar.gz
astra-be2da43a560a7241c56e727fb481f1389e9f7fdf.tar.bz2
astra-be2da43a560a7241c56e727fb481f1389e9f7fdf.tar.xz
astra-be2da43a560a7241c56e727fb481f1389e9f7fdf.zip
De-duplicate 2D texture object creation
Diffstat (limited to 'cuda/2d/fan_bp.cu')
-rw-r--r--cuda/2d/fan_bp.cu51
1 files changed, 16 insertions, 35 deletions
diff --git a/cuda/2d/fan_bp.cu b/cuda/2d/fan_bp.cu
index ea2d23b..bcda464 100644
--- a/cuda/2d/fan_bp.cu
+++ b/cuda/2d/fan_bp.cu
@@ -57,34 +57,6 @@ struct DevFanParams {
__constant__ DevFanParams gC_C[g_MaxAngles];
-
-static bool bindProjDataTexture(float* data, cudaTextureObject_t& texObj, unsigned int pitch, unsigned int width, unsigned int height, cudaTextureAddressMode mode = cudaAddressModeBorder)
-{
- cudaChannelFormatDesc channelDesc =
- cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
-
- cudaResourceDesc resDesc;
- memset(&resDesc, 0, sizeof(resDesc));
- resDesc.resType = cudaResourceTypePitch2D;
- resDesc.res.pitch2D.devPtr = (void*)data;
- resDesc.res.pitch2D.desc = channelDesc;
- resDesc.res.pitch2D.width = width;
- resDesc.res.pitch2D.height = height;
- resDesc.res.pitch2D.pitchInBytes = sizeof(float)*pitch;
-
- cudaTextureDesc texDesc;
- memset(&texDesc, 0, sizeof(texDesc));
- texDesc.addressMode[0] = mode;
- texDesc.addressMode[1] = mode;
- texDesc.filterMode = cudaFilterModeLinear;
- texDesc.readMode = cudaReadModeElementType;
- texDesc.normalizedCoords = 0;
-
- texObj = 0;
-
- return checkCuda(cudaCreateTextureObject(&texObj, &resDesc, &texDesc, NULL), "fan_bp texture");
-}
-
template<bool FBPWEIGHT>
__global__ void devFanBP(float* D_volData, unsigned int volPitch, cudaTextureObject_t tex, unsigned int startAngle, const SDimensions dims, float fOutputScale)
{
@@ -315,11 +287,14 @@ bool FanBP_internal(float* D_volumeData, unsigned int volumePitch,
assert(dims.iProjAngles <= g_MaxAngles);
cudaTextureObject_t D_texObj;
- bindProjDataTexture(D_projData, D_texObj, projPitch, dims.iProjDets, dims.iProjAngles);
+ if (!createTextureObjectPitch2D(D_projData, D_texObj, projPitch, dims.iProjDets, dims.iProjAngles))
+ return false;
bool ok = transferConstants(angles, dims.iProjAngles, false);
- if (!ok)
+ if (!ok) {
+ cudaDestroyTextureObject(D_texObj);
return false;
+ }
dim3 dimBlock(g_blockSlices, g_blockSliceSize);
dim3 dimGrid((dims.iVolWidth+g_blockSlices-1)/g_blockSlices,
@@ -352,11 +327,14 @@ bool FanBP_FBPWeighted_internal(float* D_volumeData, unsigned int volumePitch,
assert(dims.iProjAngles <= g_MaxAngles);
cudaTextureObject_t D_texObj;
- bindProjDataTexture(D_projData, D_texObj, projPitch, dims.iProjDets, dims.iProjAngles);
+ if (!createTextureObjectPitch2D(D_projData, D_texObj, projPitch, dims.iProjDets, dims.iProjAngles))
+ return false;
bool ok = transferConstants(angles, dims.iProjAngles, true);
- if (!ok)
+ if (!ok) {
+ cudaDestroyTextureObject(D_texObj);
return false;
+ }
dim3 dimBlock(g_blockSlices, g_blockSliceSize);
dim3 dimGrid((dims.iVolWidth+g_blockSlices-1)/g_blockSlices,
@@ -387,11 +365,14 @@ bool FanBP_SART(float* D_volumeData, unsigned int volumePitch,
{
// only one angle
cudaTextureObject_t D_texObj;
- bindProjDataTexture(D_projData, D_texObj, projPitch, dims.iProjDets, 1, cudaAddressModeClamp);
+ if (!createTextureObjectPitch2D(D_projData, D_texObj, projPitch, dims.iProjDets, 1, cudaAddressModeClamp))
+ return false;
bool ok = transferConstants(angles + angle, 1, false);
- if (!ok)
+ if (!ok) {
+ cudaDestroyTextureObject(D_texObj);
return false;
+ }
dim3 dimBlock(g_blockSlices, g_blockSliceSize);
dim3 dimGrid((dims.iVolWidth+g_blockSlices-1)/g_blockSlices,
@@ -399,7 +380,7 @@ bool FanBP_SART(float* D_volumeData, unsigned int volumePitch,
devFanBP_SART<<<dimGrid, dimBlock>>>(D_volumeData, volumePitch, D_texObj, dims, fOutputScale);
- bool ok = checkCuda(cudaThreadSynchronize(), "FanBP_SART");
+ ok = checkCuda(cudaThreadSynchronize(), "FanBP_SART");
cudaDestroyTextureObject(D_texObj);