summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2021-11-22 14:28:33 +0100
committerWillem Jan Palenstijn <wjp@usecode.org>2021-11-26 12:09:09 +0100
commit887f3c919c02bbbfc3c757478742f6961a30963a (patch)
treebede9d0ea6b22ff2caf2936ba4f9b7d1365bec19
parentd4645875801d29402b1e3f2a42a5d9902a37a718 (diff)
downloadastra-887f3c919c02bbbfc3c757478742f6961a30963a.tar.gz
astra-887f3c919c02bbbfc3c757478742f6961a30963a.tar.bz2
astra-887f3c919c02bbbfc3c757478742f6961a30963a.tar.xz
astra-887f3c919c02bbbfc3c757478742f6961a30963a.zip
Replace texref by texobj in fan_bp
-rw-r--r--cuda/2d/fan_bp.cu76
1 files changed, 49 insertions, 27 deletions
diff --git a/cuda/2d/fan_bp.cu b/cuda/2d/fan_bp.cu
index 2068d03..ea2d23b 100644
--- a/cuda/2d/fan_bp.cu
+++ b/cuda/2d/fan_bp.cu
@@ -58,24 +58,35 @@ struct DevFanParams {
__constant__ DevFanParams gC_C[g_MaxAngles];
-static bool bindProjDataTexture(float* data, unsigned int pitch, unsigned int width, unsigned int height, cudaTextureAddressMode mode = cudaAddressModeBorder)
+static bool bindProjDataTexture(float* data, cudaTextureObject_t& texObj, unsigned int pitch, unsigned int width, unsigned int height, cudaTextureAddressMode mode = cudaAddressModeBorder)
{
- cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<float>();
-
- gT_FanProjTexture.addressMode[0] = mode;
- gT_FanProjTexture.addressMode[1] = mode;
- gT_FanProjTexture.filterMode = cudaFilterModeLinear;
- gT_FanProjTexture.normalized = false;
-
- cudaBindTexture2D(0, gT_FanProjTexture, (const void*)data, channelDesc, width, height, sizeof(float)*pitch);
-
- // TODO: error value?
-
- return true;
+ 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, unsigned int startAngle, const SDimensions dims, float fOutputScale)
+__global__ void devFanBP(float* D_volData, unsigned int volPitch, cudaTextureObject_t tex, unsigned int startAngle, const SDimensions dims, float fOutputScale)
{
const int relX = threadIdx.x;
const int relY = threadIdx.y;
@@ -115,7 +126,7 @@ __global__ void devFanBP(float* D_volData, unsigned int volPitch, unsigned int s
const float fr = __fdividef(1.0f, fDen);
const float fT = fNum * fr;
- fVal += tex2D(gT_FanProjTexture, fT, fA) * (FBPWEIGHT ? fr * fr : fr);
+ fVal += tex2D<float>(tex, fT, fA) * (FBPWEIGHT ? fr * fr : fr);
fA += 1.0f;
}
@@ -123,7 +134,7 @@ __global__ void devFanBP(float* D_volData, unsigned int volPitch, unsigned int s
}
// supersampling version
-__global__ void devFanBP_SS(float* D_volData, unsigned int volPitch, unsigned int startAngle, const SDimensions dims, float fOutputScale)
+__global__ void devFanBP_SS(float* D_volData, unsigned int volPitch, cudaTextureObject_t tex, unsigned int startAngle, const SDimensions dims, float fOutputScale)
{
const int relX = threadIdx.x;
const int relY = threadIdx.y;
@@ -169,7 +180,7 @@ __global__ void devFanBP_SS(float* D_volData, unsigned int volPitch, unsigned in
const float fr = __fdividef(1.0f, fDen);
const float fT = fNum * fr;
- fVal += tex2D(gT_FanProjTexture, fT, fA) * fr;
+ fVal += tex2D<float>(tex, fT, fA) * fr;
fY -= fSubStep;
}
fX += fSubStep;
@@ -184,7 +195,7 @@ __global__ void devFanBP_SS(float* D_volData, unsigned int volPitch, unsigned in
// BP specifically for SART.
// It includes (free) weighting with voxel weight.
// It assumes the proj texture is set up _without_ padding, unlike regular BP.
-__global__ void devFanBP_SART(float* D_volData, unsigned int volPitch, const SDimensions dims, float fOutputScale)
+__global__ void devFanBP_SART(float* D_volData, unsigned int volPitch, cudaTextureObject_t tex, const SDimensions dims, float fOutputScale)
{
const int relX = threadIdx.x;
const int relY = threadIdx.y;
@@ -213,7 +224,7 @@ __global__ void devFanBP_SART(float* D_volData, unsigned int volPitch, const SDi
const float fr = __fdividef(1.0f, fDen);
const float fT = fNum * fr;
// NB: The scale constant in devBP is cancelled out by the SART weighting
- const float fVal = tex2D(gT_FanProjTexture, fT, 0.5f);
+ const float fVal = tex2D<float>(tex, fT, 0.5f);
volData[Y*volPitch+X] += fVal * fOutputScale;
}
@@ -303,7 +314,8 @@ bool FanBP_internal(float* D_volumeData, unsigned int volumePitch,
{
assert(dims.iProjAngles <= g_MaxAngles);
- bindProjDataTexture(D_projData, projPitch, dims.iProjDets, dims.iProjAngles);
+ cudaTextureObject_t D_texObj;
+ bindProjDataTexture(D_projData, D_texObj, projPitch, dims.iProjDets, dims.iProjAngles);
bool ok = transferConstants(angles, dims.iProjAngles, false);
if (!ok)
@@ -318,15 +330,17 @@ bool FanBP_internal(float* D_volumeData, unsigned int volumePitch,
for (unsigned int i = 0; i < dims.iProjAngles; i += g_anglesPerBlock) {
if (dims.iRaysPerPixelDim > 1)
- devFanBP_SS<<<dimGrid, dimBlock, 0, stream>>>(D_volumeData, volumePitch, i, dims, fOutputScale);
+ devFanBP_SS<<<dimGrid, dimBlock, 0, stream>>>(D_volumeData, volumePitch, D_texObj, i, dims, fOutputScale);
else
- devFanBP<false><<<dimGrid, dimBlock, 0, stream>>>(D_volumeData, volumePitch, i, dims, fOutputScale);
+ devFanBP<false><<<dimGrid, dimBlock, 0, stream>>>(D_volumeData, volumePitch, D_texObj, i, dims, fOutputScale);
}
ok = checkCuda(cudaStreamSynchronize(stream), "FanBP");
cudaStreamDestroy(stream);
+ cudaDestroyTextureObject(D_texObj);
+
return ok;
}
@@ -337,7 +351,8 @@ bool FanBP_FBPWeighted_internal(float* D_volumeData, unsigned int volumePitch,
{
assert(dims.iProjAngles <= g_MaxAngles);
- bindProjDataTexture(D_projData, projPitch, dims.iProjDets, dims.iProjAngles);
+ cudaTextureObject_t D_texObj;
+ bindProjDataTexture(D_projData, D_texObj, projPitch, dims.iProjDets, dims.iProjAngles);
bool ok = transferConstants(angles, dims.iProjAngles, true);
if (!ok)
@@ -351,13 +366,15 @@ bool FanBP_FBPWeighted_internal(float* D_volumeData, unsigned int volumePitch,
cudaStreamCreate(&stream);
for (unsigned int i = 0; i < dims.iProjAngles; i += g_anglesPerBlock) {
- devFanBP<true><<<dimGrid, dimBlock, 0, stream>>>(D_volumeData, volumePitch, i, dims, fOutputScale);
+ devFanBP<true><<<dimGrid, dimBlock, 0, stream>>>(D_volumeData, volumePitch, D_texObj, i, dims, fOutputScale);
}
ok = checkCuda(cudaStreamSynchronize(stream), "FanBP_FBPWeighted");
cudaStreamDestroy(stream);
+ cudaDestroyTextureObject(D_texObj);
+
return ok;
}
@@ -369,7 +386,8 @@ bool FanBP_SART(float* D_volumeData, unsigned int volumePitch,
float fOutputScale)
{
// only one angle
- bindProjDataTexture(D_projData, projPitch, dims.iProjDets, 1, cudaAddressModeClamp);
+ cudaTextureObject_t D_texObj;
+ bindProjDataTexture(D_projData, D_texObj, projPitch, dims.iProjDets, 1, cudaAddressModeClamp);
bool ok = transferConstants(angles + angle, 1, false);
if (!ok)
@@ -379,9 +397,13 @@ bool FanBP_SART(float* D_volumeData, unsigned int volumePitch,
dim3 dimGrid((dims.iVolWidth+g_blockSlices-1)/g_blockSlices,
(dims.iVolHeight+g_blockSliceSize-1)/g_blockSliceSize);
- devFanBP_SART<<<dimGrid, dimBlock>>>(D_volumeData, volumePitch, dims, fOutputScale);
+ devFanBP_SART<<<dimGrid, dimBlock>>>(D_volumeData, volumePitch, D_texObj, dims, fOutputScale);
+
+ bool ok = checkCuda(cudaThreadSynchronize(), "FanBP_SART");
- return checkCuda(cudaThreadSynchronize(), "FanBP_SART");
+ cudaDestroyTextureObject(D_texObj);
+
+ return ok;
}
bool FanBP(float* D_volumeData, unsigned int volumePitch,