summaryrefslogtreecommitdiffstats
path: root/cuda
diff options
context:
space:
mode:
Diffstat (limited to 'cuda')
-rw-r--r--cuda/2d/astra.cu309
-rw-r--r--cuda/2d/astra.h39
-rw-r--r--cuda/2d/dims.h12
-rw-r--r--cuda/2d/fft.cu45
-rw-r--r--cuda/2d/util.cu8
-rw-r--r--cuda/3d/cone_bp.cu194
-rw-r--r--cuda/3d/dims3d.h32
-rw-r--r--cuda/3d/par3d_bp.cu104
-rw-r--r--cuda/3d/util3d.cu12
9 files changed, 407 insertions, 348 deletions
diff --git a/cuda/2d/astra.cu b/cuda/2d/astra.cu
index d7ddc26..2f72db0 100644
--- a/cuda/2d/astra.cu
+++ b/cuda/2d/astra.cu
@@ -42,7 +42,12 @@ $Id$
#include <fstream>
#include <cuda.h>
-#include "../../include/astra/Logger.h"
+#include "../../include/astra/VolumeGeometry2D.h"
+#include "../../include/astra/ParallelProjectionGeometry2D.h"
+#include "../../include/astra/FanFlatProjectionGeometry2D.h"
+#include "../../include/astra/FanFlatVecProjectionGeometry2D.h"
+
+#include "../../include/astra/Logging.h"
// For fan beam FBP weighting
#include "../3d/fdk.h"
@@ -64,6 +69,7 @@ public:
SDimensions dims;
float* angles;
float* TOffsets;
+ astraCUDA::SFanProjection* fanProjections;
float fOriginSourceDistance;
float fOriginDetectorDistance;
@@ -90,6 +96,8 @@ AstraFBP::AstraFBP()
pData = new AstraFBP_internal();
pData->angles = 0;
+ pData->fanProjections = 0;
+ pData->TOffsets = 0;
pData->D_sinoData = 0;
pData->D_volumeData = 0;
@@ -113,6 +121,9 @@ AstraFBP::~AstraFBP()
delete[] pData->TOffsets;
pData->TOffsets = 0;
+ delete[] pData->fanProjections;
+ pData->fanProjections = 0;
+
cudaFree(pData->D_sinoData);
pData->D_sinoData = 0;
@@ -169,6 +180,7 @@ bool AstraFBP::setProjectionGeometry(unsigned int iProjAngles,
bool AstraFBP::setFanGeometry(unsigned int iProjAngles,
unsigned int iProjDets,
+ const astraCUDA::SFanProjection *fanProjs,
const float* pfAngles,
float fOriginSourceDistance,
float fOriginDetectorDistance,
@@ -182,6 +194,9 @@ bool AstraFBP::setFanGeometry(unsigned int iProjAngles,
pData->fOriginSourceDistance = fOriginSourceDistance;
pData->fOriginDetectorDistance = fOriginDetectorDistance;
+ pData->fanProjections = new astraCUDA::SFanProjection[iProjAngles];
+ memcpy(pData->fanProjections, fanProjs, iProjAngles * sizeof(fanProjs[0]));
+
pData->bFanBeam = true;
pData->bShortScan = bShortScan;
@@ -310,7 +325,7 @@ bool AstraFBP::run()
// Call FDK_PreWeight to handle fan beam geometry. We treat
// this as a cone beam setup of a single slice:
- // TODO: TOffsets...
+ // TODO: TOffsets affects this preweighting...
// We create a fake cudaPitchedPtr
cudaPitchedPtr tmp;
@@ -354,29 +369,7 @@ bool AstraFBP::run()
}
if (pData->bFanBeam) {
- // TODO: TOffsets?
- // TODO: Remove this code duplication with CudaReconstructionAlgorithm
- SFanProjection* projs;
- projs = new SFanProjection[pData->dims.iProjAngles];
-
- float fSrcX0 = 0.0f;
- float fSrcY0 = -pData->fOriginSourceDistance / pData->fPixelSize;
- float fDetUX0 = pData->dims.fDetScale;
- float fDetUY0 = 0.0f;
- float fDetSX0 = pData->dims.iProjDets * fDetUX0 / -2.0f;
- float fDetSY0 = pData->fOriginDetectorDistance / pData->fPixelSize;
-
-#define ROTATE0(name,i,alpha) do { projs[i].f##name##X = f##name##X0 * cos(alpha) - f##name##Y0 * sin(alpha); projs[i].f##name##Y = f##name##X0 * sin(alpha) + f##name##Y0 * cos(alpha); } while(0)
- for (unsigned int i = 0; i < pData->dims.iProjAngles; ++i) {
- ROTATE0(Src, i, pData->angles[i]);
- ROTATE0(DetS, i, pData->angles[i]);
- ROTATE0(DetU, i, pData->angles[i]);
- }
-
-#undef ROTATE0
- ok = FanBP_FBPWeighted(pData->D_volumeData, pData->volumePitch, pData->D_sinoData, pData->sinoPitch, pData->dims, projs);
-
- delete[] projs;
+ ok = FanBP_FBPWeighted(pData->D_volumeData, pData->volumePitch, pData->D_sinoData, pData->sinoPitch, pData->dims, pData->fanProjections);
} else {
ok = BP(pData->D_volumeData, pData->volumePitch, pData->D_sinoData, pData->sinoPitch, pData->dims, pData->angles, pData->TOffsets);
@@ -546,7 +539,7 @@ bool AstraFBP::setFilter(E_FBPFILTER _eFilter, const float * _pfHostFilter /* =
int iMaxFilterIndex = iStartFilterIndex + iUsedFilterWidth;
int iFilterShiftSize = _iFilterWidth / 2;
-
+
for(int iDetectorIndex = iStartFilterIndex; iDetectorIndex < iMaxFilterIndex; iDetectorIndex++)
{
int iFFTInFilterIndex = (iDetectorIndex + iFFTRealDetCount - iFilterShiftSize) % iFFTRealDetCount;
@@ -571,7 +564,7 @@ bool AstraFBP::setFilter(E_FBPFILTER _eFilter, const float * _pfHostFilter /* =
}
default:
{
- fprintf(stderr, "AstraFBP::setFilter: Unknown filter type requested");
+ ASTRA_ERROR("AstraFBP::setFilter: Unknown filter type requested");
delete [] pHostFilter;
return false;
}
@@ -628,7 +621,7 @@ bool astraCudaFP(const float* pfVolume, float* pfSinogram,
unsigned int iProjAngles, unsigned int iProjDets,
const float *pfAngles, const float *pfOffsets,
float fDetSize, unsigned int iDetSuperSampling,
- int iGPUIndex)
+ float fOutputScale, int iGPUIndex)
{
SDimensions dims;
@@ -687,7 +680,7 @@ bool astraCudaFP(const float* pfVolume, float* pfSinogram,
}
zeroProjectionData(D_sinoData, sinoPitch, dims);
- ok = FP(D_volumeData, volumePitch, D_sinoData, sinoPitch, dims, pfAngles, pfOffsets, 1.0f);
+ ok = FP(D_volumeData, volumePitch, D_sinoData, sinoPitch, dims, pfAngles, pfOffsets, fOutputScale);
if (!ok) {
cudaFree(D_volumeData);
cudaFree(D_sinoData);
@@ -711,19 +704,18 @@ bool astraCudaFP(const float* pfVolume, float* pfSinogram,
bool astraCudaFanFP(const float* pfVolume, float* pfSinogram,
unsigned int iVolWidth, unsigned int iVolHeight,
unsigned int iProjAngles, unsigned int iProjDets,
- const float *pfAngles, float fOriginSourceDistance,
- float fOriginDetectorDistance, float fPixelSize,
- float fDetSize,
- unsigned int iDetSuperSampling,
+ const SFanProjection *pAngles,
+ unsigned int iDetSuperSampling, float fOutputScale,
int iGPUIndex)
{
SDimensions dims;
- if (iProjAngles == 0 || iProjDets == 0 || pfAngles == 0)
+ if (iProjAngles == 0 || iProjDets == 0 || pAngles == 0)
return false;
dims.iProjAngles = iProjAngles;
dims.iProjDets = iProjDets;
+ dims.fDetScale = 1.0f; // TODO?
if (iDetSuperSampling == 0)
return false;
@@ -774,27 +766,7 @@ bool astraCudaFanFP(const float* pfVolume, float* pfSinogram,
zeroProjectionData(D_sinoData, sinoPitch, dims);
- // TODO: Turn this geometry conversion into a util function
- SFanProjection* projs = new SFanProjection[dims.iProjAngles];
-
- float fSrcX0 = 0.0f;
- float fSrcY0 = -fOriginSourceDistance / fPixelSize;
- float fDetUX0 = fDetSize / fPixelSize;
- float fDetUY0 = 0.0f;
- float fDetSX0 = dims.iProjDets * fDetUX0 / -2.0f;
- float fDetSY0 = fOriginDetectorDistance / fPixelSize;
-
-#define ROTATE0(name,i,alpha) do { projs[i].f##name##X = f##name##X0 * cos(alpha) - f##name##Y0 * sin(alpha); projs[i].f##name##Y = f##name##X0 * sin(alpha) + f##name##Y0 * cos(alpha); } while(0)
- for (int i = 0; i < dims.iProjAngles; ++i) {
- ROTATE0(Src, i, pfAngles[i]);
- ROTATE0(DetS, i, pfAngles[i]);
- ROTATE0(DetU, i, pfAngles[i]);
- }
-
-#undef ROTATE0
-
- ok = FanFP(D_volumeData, volumePitch, D_sinoData, sinoPitch, dims, projs, 1.0f);
- delete[] projs;
+ ok = FanFP(D_volumeData, volumePitch, D_sinoData, sinoPitch, dims, pAngles, fOutputScale);
if (!ok) {
cudaFree(D_volumeData);
@@ -819,94 +791,205 @@ bool astraCudaFanFP(const float* pfVolume, float* pfSinogram,
}
-bool astraCudaFanFP(const float* pfVolume, float* pfSinogram,
- unsigned int iVolWidth, unsigned int iVolHeight,
- unsigned int iProjAngles, unsigned int iProjDets,
- const SFanProjection *pAngles,
- unsigned int iDetSuperSampling,
- int iGPUIndex)
+bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom,
+ const CParallelProjectionGeometry2D* pProjGeom,
+ float*& detectorOffsets, float*& projectionAngles,
+ float& detSize, float& outputScale)
{
- SDimensions dims;
+ assert(pVolGeom);
+ assert(pProjGeom);
+ assert(pProjGeom->getProjectionAngles());
- if (iProjAngles == 0 || iProjDets == 0 || pAngles == 0)
- return false;
+ const float EPS = 0.00001f;
- dims.iProjAngles = iProjAngles;
- dims.iProjDets = iProjDets;
- dims.fDetScale = 1.0f; // TODO?
+ int nth = pProjGeom->getProjectionAngleCount();
- if (iDetSuperSampling == 0)
+ // Check if pixels are square
+ if (abs(pVolGeom->getPixelLengthX() - pVolGeom->getPixelLengthY()) > EPS)
return false;
- dims.iRaysPerDet = iDetSuperSampling;
-
- if (iVolWidth <= 0 || iVolHeight <= 0)
- return false;
- dims.iVolWidth = iVolWidth;
- dims.iVolHeight = iVolHeight;
+ // Scale volume pixels to 1x1
+ detSize = pProjGeom->getDetectorWidth() / pVolGeom->getPixelLengthX();
- if (iGPUIndex != -1) {
- cudaSetDevice(iGPUIndex);
- cudaError_t err = cudaGetLastError();
+ // Copy angles
+ float *angles = new float[nth];
+ for (int i = 0; i < nth; ++i)
+ angles[i] = pProjGeom->getProjectionAngles()[i];
+ projectionAngles = angles;
- // Ignore errors caused by calling cudaSetDevice multiple times
- if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess)
- return false;
+ // Check if we need to translate
+ bool offCenter = false;
+ if (abs(pVolGeom->getWindowMinX() + pVolGeom->getWindowMaxX()) > EPS ||
+ abs(pVolGeom->getWindowMinY() + pVolGeom->getWindowMaxY()) > EPS)
+ {
+ offCenter = true;
}
- bool ok;
+ // If there are existing detector offsets, or if we need to translate,
+ // we need to return offsets
+ if (pProjGeom->getExtraDetectorOffset() || offCenter)
+ {
+ float* offset = new float[nth];
+
+ if (pProjGeom->getExtraDetectorOffset()) {
+ for (int i = 0; i < nth; ++i)
+ offset[i] = pProjGeom->getExtraDetectorOffset()[i];
+ } else {
+ for (int i = 0; i < nth; ++i)
+ offset[i] = 0.0f;
+ }
- float* D_volumeData;
- unsigned int volumePitch;
+ if (offCenter) {
+ float dx = (pVolGeom->getWindowMinX() + pVolGeom->getWindowMaxX()) / 2;
+ float dy = (pVolGeom->getWindowMinY() + pVolGeom->getWindowMaxY()) / 2;
- ok = allocateVolumeData(D_volumeData, volumePitch, dims);
- if (!ok)
- return false;
+ // CHECKME: Is d in pixels or in units?
- float* D_sinoData;
- unsigned int sinoPitch;
+ for (int i = 0; i < nth; ++i) {
+ float d = dx * cos(angles[i]) + dy * sin(angles[i]);
+ offset[i] += d;
+ }
+ }
- ok = allocateProjectionData(D_sinoData, sinoPitch, dims);
- if (!ok) {
- cudaFree(D_volumeData);
- return false;
+ // CHECKME: Order of scaling and translation
+
+ // Scale volume pixels to 1x1
+ for (int i = 0; i < nth; ++i) {
+ //offset[i] /= pVolGeom->getPixelLengthX();
+ //offset[i] *= detSize;
+ }
+
+
+ detectorOffsets = offset;
+ } else {
+ detectorOffsets = 0;
}
- ok = copyVolumeToDevice(pfVolume, dims.iVolWidth,
- dims,
- D_volumeData, volumePitch);
- if (!ok) {
- cudaFree(D_volumeData);
- cudaFree(D_sinoData);
- return false;
+ outputScale = pVolGeom->getPixelLengthX();
+ outputScale *= outputScale;
+
+ return true;
+}
+
+static void convertAstraGeometry_internal(const CVolumeGeometry2D* pVolGeom,
+ unsigned int iProjectionAngleCount,
+ astraCUDA::SFanProjection*& pProjs,
+ float& outputScale)
+{
+ // Translate
+ float dx = (pVolGeom->getWindowMinX() + pVolGeom->getWindowMaxX()) / 2;
+ float dy = (pVolGeom->getWindowMinY() + pVolGeom->getWindowMaxY()) / 2;
+
+ for (int i = 0; i < iProjectionAngleCount; ++i) {
+ pProjs[i].fSrcX -= dx;
+ pProjs[i].fSrcY -= dy;
+ pProjs[i].fDetSX -= dx;
+ pProjs[i].fDetSY -= dy;
}
- zeroProjectionData(D_sinoData, sinoPitch, dims);
+ // CHECKME: Order of scaling and translation
- ok = FanFP(D_volumeData, volumePitch, D_sinoData, sinoPitch, dims, pAngles, 1.0f);
+ // Scale
+ float factor = 1.0f / pVolGeom->getPixelLengthX();
+ for (int i = 0; i < iProjectionAngleCount; ++i) {
+ pProjs[i].fSrcX *= factor;
+ pProjs[i].fSrcY *= factor;
+ pProjs[i].fDetSX *= factor;
+ pProjs[i].fDetSY *= factor;
+ pProjs[i].fDetUX *= factor;
+ pProjs[i].fDetUY *= factor;
- if (!ok) {
- cudaFree(D_volumeData);
- cudaFree(D_sinoData);
- return false;
}
- ok = copySinogramFromDevice(pfSinogram, dims.iProjDets,
- dims,
- D_sinoData, sinoPitch);
- if (!ok) {
- cudaFree(D_volumeData);
- cudaFree(D_sinoData);
+ // CHECKME: Check factor
+ outputScale = pVolGeom->getPixelLengthX();
+// outputScale *= outputScale;
+}
+
+
+bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom,
+ const CFanFlatProjectionGeometry2D* pProjGeom,
+ astraCUDA::SFanProjection*& pProjs,
+ float& outputScale)
+{
+ assert(pVolGeom);
+ assert(pProjGeom);
+ assert(pProjGeom->getProjectionAngles());
+
+ const float EPS = 0.00001f;
+
+ int nth = pProjGeom->getProjectionAngleCount();
+
+ // Check if pixels are square
+ if (abs(pVolGeom->getPixelLengthX() - pVolGeom->getPixelLengthY()) > EPS)
return false;
+
+ // TODO: Deprecate this.
+// if (pProjGeom->getExtraDetectorOffset())
+// return false;
+
+
+ float fOriginSourceDistance = pProjGeom->getOriginSourceDistance();
+ float fOriginDetectorDistance = pProjGeom->getOriginDetectorDistance();
+ float fDetSize = pProjGeom->getDetectorWidth();
+ const float *pfAngles = pProjGeom->getProjectionAngles();
+
+ pProjs = new SFanProjection[nth];
+
+ float fSrcX0 = 0.0f;
+ float fSrcY0 = -fOriginSourceDistance;
+ float fDetUX0 = fDetSize;
+ float fDetUY0 = 0.0f;
+ float fDetSX0 = pProjGeom->getDetectorCount() * fDetUX0 / -2.0f;
+ float fDetSY0 = fOriginDetectorDistance;
+
+#define ROTATE0(name,i,alpha) do { pProjs[i].f##name##X = f##name##X0 * cos(alpha) - f##name##Y0 * sin(alpha); pProjs[i].f##name##Y = f##name##X0 * sin(alpha) + f##name##Y0 * cos(alpha); } while(0)
+ for (int i = 0; i < nth; ++i) {
+ ROTATE0(Src, i, pfAngles[i]);
+ ROTATE0(DetS, i, pfAngles[i]);
+ ROTATE0(DetU, i, pfAngles[i]);
}
- cudaFree(D_volumeData);
- cudaFree(D_sinoData);
+#undef ROTATE0
+
+ convertAstraGeometry_internal(pVolGeom, nth, pProjs, outputScale);
return true;
}
+bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom,
+ const CFanFlatVecProjectionGeometry2D* pProjGeom,
+ astraCUDA::SFanProjection*& pProjs,
+ float& outputScale)
+{
+ assert(pVolGeom);
+ assert(pProjGeom);
+ assert(pProjGeom->getProjectionVectors());
+
+ const float EPS = 0.00001f;
+
+ int nx = pVolGeom->getGridColCount();
+ int ny = pVolGeom->getGridRowCount();
+ int nth = pProjGeom->getProjectionAngleCount();
+
+ // Check if pixels are square
+ if (abs(pVolGeom->getPixelLengthX() - pVolGeom->getPixelLengthY()) > EPS)
+ return false;
+
+ pProjs = new SFanProjection[nth];
+
+ // Copy vectors
+ for (int i = 0; i < nth; ++i)
+ pProjs[i] = pProjGeom->getProjectionVectors()[i];
+
+ convertAstraGeometry_internal(pVolGeom, nth, pProjs, outputScale);
+
+ return true;
+}
+
+
+
}
diff --git a/cuda/2d/astra.h b/cuda/2d/astra.h
index 474f99a..617883b 100644
--- a/cuda/2d/astra.h
+++ b/cuda/2d/astra.h
@@ -42,6 +42,11 @@ enum Cuda2DProjectionKernel {
ker2d_default = 0
};
+class CParallelProjectionGeometry2D;
+class CFanFlatProjectionGeometry2D;
+class CFanFlatVecProjectionGeometry2D;
+class CVolumeGeometry2D;
+
class AstraFBP_internal;
class _AstraExport AstraFBP {
@@ -73,9 +78,10 @@ public:
// fDetSize indicates the size of a detector pixel compared to a
// volume pixel edge.
//
- // pfAngles will only be read from during this call.
+ // pfAngles, fanProjs will only be read from during this call.
bool setFanGeometry(unsigned int iProjAngles,
unsigned int iProjDets,
+ const astraCUDA::SFanProjection *fanProjs,
const float *pfAngles,
float fOriginSourceDistance,
float fOriginDetectorDistance,
@@ -195,24 +201,31 @@ _AstraExport bool astraCudaFP(const float* pfVolume, float* pfSinogram,
unsigned int iProjAngles, unsigned int iProjDets,
const float *pfAngles, const float *pfOffsets,
float fDetSize = 1.0f, unsigned int iDetSuperSampling = 1,
- int iGPUIndex = 0);
-
-// Do a single forward projection, fan beam
-_AstraExport bool astraCudaFanFP(const float* pfVolume, float* pfSinogram,
- unsigned int iVolWidth, unsigned int iVolHeight,
- unsigned int iProjAngles, unsigned int iProjDets,
- const float *pfAngles, float fOriginSourceDistance,
- float fOriginDetectorDistance, float fPixelSize = 1.0f,
- float fDetSize = 1.0f,
- unsigned int iDetSuperSampling = 1,
- int iGPUIndex = 0);
+ float fOutputScale = 1.0f, int iGPUIndex = 0);
_AstraExport bool astraCudaFanFP(const float* pfVolume, float* pfSinogram,
unsigned int iVolWidth, unsigned int iVolHeight,
unsigned int iProjAngles, unsigned int iProjDets,
const SFanProjection *pAngles,
unsigned int iDetSuperSampling = 1,
- int iGPUIndex = 0);
+ float fOutputScale = 1.0f, int iGPUIndex = 0);
+
+
+_AstraExport bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom,
+ const CParallelProjectionGeometry2D* pProjGeom,
+ float*& pfDetectorOffsets, float*& pfProjectionAngles,
+ float& fDetSize, float& fOutputScale);
+
+_AstraExport bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom,
+ const CFanFlatProjectionGeometry2D* pProjGeom,
+ astraCUDA::SFanProjection*& pProjs,
+ float& outputScale);
+
+_AstraExport bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom,
+ const CFanFlatVecProjectionGeometry2D* pProjGeom,
+ astraCUDA::SFanProjection*& pProjs,
+ float& outputScale);
+
}
#endif
diff --git a/cuda/2d/dims.h b/cuda/2d/dims.h
index 37bfa66..e870da5 100644
--- a/cuda/2d/dims.h
+++ b/cuda/2d/dims.h
@@ -29,18 +29,12 @@ $Id$
#ifndef _CUDA_DIMS_H
#define _CUDA_DIMS_H
-namespace astraCUDA {
+#include "astra/GeometryUtil2D.h"
-struct SFanProjection {
- // the source
- float fSrcX, fSrcY;
- // the start of the (linear) detector
- float fDetSX, fDetSY;
+namespace astraCUDA {
- // the length of a single detector pixel
- float fDetUX, fDetUY;
-};
+using astra::SFanProjection;
struct SDimensions {
diff --git a/cuda/2d/fft.cu b/cuda/2d/fft.cu
index d105e29..2bfd493 100644
--- a/cuda/2d/fft.cu
+++ b/cuda/2d/fft.cu
@@ -34,7 +34,7 @@ $Id$
#include <cuda.h>
#include <fstream>
-#include "../../include/astra/Logger.h"
+#include "../../include/astra/Logging.h"
using namespace astra;
@@ -43,25 +43,22 @@ using namespace astra;
#define CHECK_ERROR(errorMessage) do { \
cudaError_t err = cudaThreadSynchronize(); \
if( cudaSuccess != err) { \
- fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
- errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
- CLogger::writeTerminalCUDAError(__FILE__, __LINE__, cudaGetErrorString( err)); \
+ ASTRA_ERROR("Cuda error %s : %s", \
+ errorMessage,cudaGetErrorString( err)); \
exit(EXIT_FAILURE); \
} } while (0)
#define SAFE_CALL( call) do { \
cudaError err = call; \
if( cudaSuccess != err) { \
- fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \
- __FILE__, __LINE__, cudaGetErrorString( err) ); \
- CLogger::writeTerminalCUDAError(__FILE__, __LINE__, cudaGetErrorString( err)); \
+ ASTRA_ERROR("Cuda error: %s ", \
+ cudaGetErrorString( err)); \
exit(EXIT_FAILURE); \
} \
err = cudaThreadSynchronize(); \
if( cudaSuccess != err) { \
- fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \
- __FILE__, __LINE__, cudaGetErrorString( err) ); \
- CLogger::writeTerminalCUDAError(__FILE__, __LINE__, cudaGetErrorString( err)); \
+ ASTRA_ERROR("Cuda error: %s : ", \
+ cudaGetErrorString( err)); \
exit(EXIT_FAILURE); \
} } while (0)
@@ -140,7 +137,7 @@ static bool invokeCudaFFT(int _iProjectionCount, int _iDetectorCount,
result = cufftPlan1d(&plan, _iDetectorCount, CUFFT_R2C, _iProjectionCount);
if(result != CUFFT_SUCCESS)
{
- std::cerr << "Failed to plan 1d r2c fft" << std::endl;
+ ASTRA_ERROR("Failed to plan 1d r2c fft");
return false;
}
@@ -149,7 +146,7 @@ static bool invokeCudaFFT(int _iProjectionCount, int _iDetectorCount,
if(result != CUFFT_SUCCESS)
{
- std::cerr << "Failed to exec 1d r2c fft" << std::endl;
+ ASTRA_ERROR("Failed to exec 1d r2c fft");
return false;
}
@@ -166,18 +163,18 @@ static bool invokeCudaIFFT(int _iProjectionCount, int _iDetectorCount,
result = cufftPlan1d(&plan, _iDetectorCount, CUFFT_C2R, _iProjectionCount);
if(result != CUFFT_SUCCESS)
{
- std::cerr << "Failed to plan 1d c2r fft" << std::endl;
+ ASTRA_ERROR("Failed to plan 1d c2r fft");
return false;
}
// todo: why do we have to get rid of the const qualifier?
result = cufftExecC2R(plan, (cufftComplex *)_pDevSourceComplex,
- (cufftReal *)_pfDevTarget);
+ (cufftReal *)_pfDevTarget);
cufftDestroy(plan);
if(result != CUFFT_SUCCESS)
{
- std::cerr << "Failed to exec 1d c2r fft" << std::endl;
+ ASTRA_ERROR("Failed to exec 1d c2r fft");
return false;
}
@@ -257,7 +254,7 @@ bool runCudaIFFT(int _iProjectionCount, const cufftComplex* _pDevSourceComplex,
}
rescaleInverseFourier(_iProjectionCount, _iFFTRealDetectorCount,
- pfDevRealFFTTarget);
+ pfDevRealFFTTarget);
SAFE_CALL(cudaMemset(_pfRealTarget, 0, sizeof(float) * _iProjectionCount * _iTargetPitch));
@@ -460,7 +457,7 @@ void genFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount,
const float fA1 = 0.48f;
const float fA2 = 0.38f;
float fNMinusOne = (float)(_iFFTFourierDetectorCount) - 1.0f;
-
+
for(int iDetectorIndex = 1; iDetectorIndex < _iFFTFourierDetectorCount; iDetectorIndex++)
{
float fSmallN = (float)iDetectorIndex;
@@ -633,7 +630,7 @@ void genFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount,
}
default:
{
- std::cerr << "Cannot serve requested filter" << std::endl;
+ ASTRA_ERROR("Cannot serve requested filter");
}
}
@@ -746,7 +743,7 @@ void testCudaFFT()
{
for(int iDetectorIndex = 0; iDetectorIndex < iDetectorCount; iDetectorIndex++)
{
-// int
+// int
// pfHostProj[iIndex] = (float)rand() / (float)RAND_MAX;
}
@@ -767,13 +764,13 @@ void testCudaFFT()
result = cufftPlan1d(&plan, iDetectorCount, CUFFT_R2C, iProjectionCount);
if(result != CUFFT_SUCCESS)
{
- cerr << "Failed to plan 1d r2c fft" << endl;
+ ASTRA_ERROR("Failed to plan 1d r2c fft");
}
result = cufftExecR2C(plan, pfDevProj, pDevFourProj);
if(result != CUFFT_SUCCESS)
{
- cerr << "Failed to exec 1d r2c fft" << endl;
+ ASTRA_ERROR("Failed to exec 1d r2c fft");
}
cufftDestroy(plan);
@@ -787,7 +784,7 @@ void testCudaFFT()
float * pfHostFourProjImaginary = new float[iTotalElementCount];
convertComplexToRealImg(pHostFourProj, iTotalElementCount, pfHostFourProjReal, pfHostFourProjImaginary);
-
+
writeToMatlabFile("proj_four_real.mat", pfHostFourProjReal, iProjectionCount, iDetectorCount);
writeToMatlabFile("proj_four_imaginary.mat", pfHostFourProjImaginary, iProjectionCount, iDetectorCount);
@@ -797,13 +794,13 @@ void testCudaFFT()
result = cufftPlan1d(&plan, iDetectorCount, CUFFT_C2R, iProjectionCount);
if(result != CUFFT_SUCCESS)
{
- cerr << "Failed to plan 1d c2r fft" << endl;
+ ASTRA_ERROR("Failed to plan 1d c2r fft");
}
result = cufftExecC2R(plan, pDevFourProj, pfDevInFourProj);
if(result != CUFFT_SUCCESS)
{
- cerr << "Failed to exec 1d c2r fft" << endl;
+ ASTRA_ERROR("Failed to exec 1d c2r fft");
}
cufftDestroy(plan);
diff --git a/cuda/2d/util.cu b/cuda/2d/util.cu
index 81e368f..a4f8f3e 100644
--- a/cuda/2d/util.cu
+++ b/cuda/2d/util.cu
@@ -30,6 +30,8 @@ $Id$
#include <cassert>
#include "util.h"
+#include "../../include/astra/Logging.h"
+
namespace astraCUDA {
bool copyVolumeToDevice(const float* in_data, unsigned int in_pitch,
@@ -91,7 +93,7 @@ bool allocateVolume(float*& ptr, unsigned int width, unsigned int height, unsign
cudaError_t ret = cudaMallocPitch((void**)&ptr, &p, sizeof(float)*width, height);
if (ret != cudaSuccess) {
reportCudaError(ret);
- fprintf(stderr, "Failed to allocate %dx%d GPU buffer\n", width, height);
+ ASTRA_ERROR("Failed to allocate %dx%d GPU buffer", width, height);
return false;
}
@@ -259,7 +261,7 @@ bool cudaTextForceKernelsCompletion()
cudaError_t returnedCudaError = cudaThreadSynchronize();
if(returnedCudaError != cudaSuccess) {
- fprintf(stderr, "Failed to force completion of cuda kernels: %d: %s.\n", returnedCudaError, cudaGetErrorString(returnedCudaError));
+ ASTRA_ERROR("Failed to force completion of cuda kernels: %d: %s.", returnedCudaError, cudaGetErrorString(returnedCudaError));
return false;
}
@@ -269,7 +271,7 @@ bool cudaTextForceKernelsCompletion()
void reportCudaError(cudaError_t err)
{
if(err != cudaSuccess)
- fprintf(stderr, "CUDA error %d: %s.\n", err, cudaGetErrorString(err));
+ ASTRA_ERROR("CUDA error %d: %s.", err, cudaGetErrorString(err));
}
diff --git a/cuda/3d/cone_bp.cu b/cuda/3d/cone_bp.cu
index 18ee4b7..5648d6f 100644
--- a/cuda/3d/cone_bp.cu
+++ b/cuda/3d/cone_bp.cu
@@ -47,27 +47,16 @@ static texture3D gT_coneProjTexture;
namespace astraCUDA3d {
-static const unsigned int g_volBlockZ = 16;
+#define ZSIZE 6
+static const unsigned int g_volBlockZ = ZSIZE;
-static const unsigned int g_anglesPerBlock = 64;
-static const unsigned int g_volBlockX = 32;
-static const unsigned int g_volBlockY = 16;
+static const unsigned int g_anglesPerBlock = 32;
+static const unsigned int g_volBlockX = 16;
+static const unsigned int g_volBlockY = 32;
static const unsigned g_MaxAngles = 1024;
-__constant__ float gC_Cux[g_MaxAngles];
-__constant__ float gC_Cuy[g_MaxAngles];
-__constant__ float gC_Cuz[g_MaxAngles];
-__constant__ float gC_Cuc[g_MaxAngles];
-__constant__ float gC_Cvx[g_MaxAngles];
-__constant__ float gC_Cvy[g_MaxAngles];
-__constant__ float gC_Cvz[g_MaxAngles];
-__constant__ float gC_Cvc[g_MaxAngles];
-__constant__ float gC_Cdx[g_MaxAngles];
-__constant__ float gC_Cdy[g_MaxAngles];
-__constant__ float gC_Cdz[g_MaxAngles];
-__constant__ float gC_Cdc[g_MaxAngles];
-
+__constant__ float gC_C[12*g_MaxAngles];
bool bindProjDataTexture(const cudaArray* array)
{
@@ -87,7 +76,9 @@ bool bindProjDataTexture(const cudaArray* array)
}
-__global__ void dev_cone_BP(void* D_volData, unsigned int volPitch, int startAngle, int angleOffset, const SDimensions3D dims)
+//__launch_bounds__(32*16, 4)
+__global__ void dev_cone_BP(void* D_volData, unsigned int volPitch, int startAngle,
+ int angleOffset, const astraCUDA3d::SDimensions3D dims)
{
float* volData = (float*)D_volData;
@@ -99,11 +90,9 @@ __global__ void dev_cone_BP(void* D_volData, unsigned int volPitch, int startAng
// y = rel y
// blockIdx: x = x + y
- // y = z
+ // y = z
- // TO TRY: precompute part of detector intersection formulas in shared mem?
- // TO TRY: inner loop over z, gather ray values in shared mem
const int X = blockIdx.x % ((dims.iVolX+g_volBlockX-1)/g_volBlockX) * g_volBlockX + threadIdx.x;
const int Y = blockIdx.x / ((dims.iVolX+g_volBlockX-1)/g_volBlockX) * g_volBlockY + threadIdx.y;
@@ -114,51 +103,54 @@ __global__ void dev_cone_BP(void* D_volData, unsigned int volPitch, int startAng
return;
const int startZ = blockIdx.y * g_volBlockZ;
- int endZ = startZ + g_volBlockZ;
- if (endZ > dims.iVolZ)
- endZ = dims.iVolZ;
+ const float fX = X - 0.5f*dims.iVolX + 0.5f;
+ const float fY = Y - 0.5f*dims.iVolY + 0.5f;
+ const float fZ = startZ - 0.5f*dims.iVolZ + 0.5f;
- float fX = X - 0.5f*dims.iVolX + 0.5f;
- float fY = Y - 0.5f*dims.iVolY + 0.5f;
- float fZ = startZ - 0.5f*dims.iVolZ + 0.5f;
+ float Z[ZSIZE];
+ for(int i=0; i < ZSIZE; i++)
+ Z[i] = 0.0f;
- for (int Z = startZ; Z < endZ; ++Z, fZ += 1.0f)
- {
- float fVal = 0.0f;
+ {
float fAngle = startAngle + angleOffset + 0.5f;
for (int angle = startAngle; angle < endAngle; ++angle, fAngle += 1.0f)
{
+ float4 fCu = make_float4(gC_C[12*angle+0], gC_C[12*angle+1], gC_C[12*angle+2], gC_C[12*angle+3]);
+ float4 fCv = make_float4(gC_C[12*angle+4], gC_C[12*angle+5], gC_C[12*angle+6], gC_C[12*angle+7]);
+ float4 fCd = make_float4(gC_C[12*angle+8], gC_C[12*angle+9], gC_C[12*angle+10], gC_C[12*angle+11]);
+
+ float fUNum = fCu.w + fX * fCu.x + fY * fCu.y + fZ * fCu.z;
+ float fVNum = fCv.w + fX * fCv.x + fY * fCv.y + fZ * fCv.z;
+ float fDen = fCd.w + fX * fCd.x + fY * fCd.y + fZ * fCd.z;
+
+ float fU,fV, fr;
+
+ for (int idx = 0; idx < ZSIZE; idx++)
+ {
+ fr = __fdividef(1.0f, fDen);
+ fU = fUNum * fr;
+ fV = fVNum * fr;
+ float fVal = tex3D(gT_coneProjTexture, fU, fAngle, fV);
+ Z[idx] += fVal; // fr*fr*fVal;
+
+ fUNum += fCu.z;
+ fVNum += fCv.z;
+ fDen += fCd.z;
+ }
+ }
+ }
- const float fCux = gC_Cux[angle];
- const float fCuy = gC_Cuy[angle];
- const float fCuz = gC_Cuz[angle];
- const float fCuc = gC_Cuc[angle];
- const float fCvx = gC_Cvx[angle];
- const float fCvy = gC_Cvy[angle];
- const float fCvz = gC_Cvz[angle];
- const float fCvc = gC_Cvc[angle];
- const float fCdx = gC_Cdx[angle];
- const float fCdy = gC_Cdy[angle];
- const float fCdz = gC_Cdz[angle];
- const float fCdc = gC_Cdc[angle];
-
- const float fUNum = fCuc + fX * fCux + fY * fCuy + fZ * fCuz;
- const float fVNum = fCvc + fX * fCvx + fY * fCvy + fZ * fCvz;
- const float fDen = fCdc + fX * fCdx + fY * fCdy + fZ * fCdz;
-
- const float fU = fUNum / fDen;
- const float fV = fVNum / fDen;
-
- fVal += tex3D(gT_coneProjTexture, fU, fAngle, fV);
+ int endZ = ZSIZE;
+ if (endZ > dims.iVolZ - startZ)
+ endZ = dims.iVolZ - startZ;
- }
+ for(int i=0; i < endZ; i++)
+ volData[((startZ+i)*dims.iVolY+Y)*volPitch+X] += Z[i];
+} //End kernel
- volData[(Z*dims.iVolY+Y)*volPitch+X] += fVal;
- }
-}
// supersampling version
__global__ void dev_cone_BP_SS(void* D_volData, unsigned int volPitch, int startAngle, int angleOffset, const SDimensions3D dims)
@@ -206,18 +198,18 @@ __global__ void dev_cone_BP_SS(void* D_volData, unsigned int volPitch, int start
for (int angle = startAngle; angle < endAngle; ++angle, fAngle += 1.0f)
{
- const float fCux = gC_Cux[angle];
- const float fCuy = gC_Cuy[angle];
- const float fCuz = gC_Cuz[angle];
- const float fCuc = gC_Cuc[angle];
- const float fCvx = gC_Cvx[angle];
- const float fCvy = gC_Cvy[angle];
- const float fCvz = gC_Cvz[angle];
- const float fCvc = gC_Cvc[angle];
- const float fCdx = gC_Cdx[angle];
- const float fCdy = gC_Cdy[angle];
- const float fCdz = gC_Cdz[angle];
- const float fCdc = gC_Cdc[angle];
+ const float fCux = gC_C[12*angle+0];
+ const float fCuy = gC_C[12*angle+1];
+ const float fCuz = gC_C[12*angle+2];
+ const float fCuc = gC_C[12*angle+3];
+ const float fCvx = gC_C[12*angle+4];
+ const float fCvy = gC_C[12*angle+5];
+ const float fCvz = gC_C[12*angle+6];
+ const float fCvc = gC_C[12*angle+7];
+ const float fCdx = gC_C[12*angle+8];
+ const float fCdy = gC_C[12*angle+9];
+ const float fCdz = gC_C[12*angle+10];
+ const float fCdc = gC_C[12*angle+11];
float fXs = fX;
for (int iSubX = 0; iSubX < dims.iRaysPerVoxelDim; ++iSubX) {
@@ -233,7 +225,7 @@ __global__ void dev_cone_BP_SS(void* D_volData, unsigned int volPitch, int start
const float fU = fUNum / fDen;
const float fV = fVNum / fDen;
- fVal += tex3D(gT_coneProjTexture, fU, fAngle, fV);
+ fVal += tex3D(gT_coneProjTexture, fU, fV, fAngle);
fZs += fSubStep;
}
@@ -246,7 +238,6 @@ __global__ void dev_cone_BP_SS(void* D_volData, unsigned int volPitch, int start
volData[(Z*dims.iVolY+Y)*volPitch+X] += fVal / (dims.iRaysPerVoxelDim*dims.iRaysPerVoxelDim*dims.iRaysPerVoxelDim);
}
-
}
@@ -262,35 +253,37 @@ bool ConeBP_Array(cudaPitchedPtr D_volumeData,
angleCount = dims.iProjAngles - th;
// transfer angles to constant memory
- float* tmp = new float[angleCount];
+ float* tmp = new float[12*angleCount];
// NB: We increment angles at the end of the loop body.
-#define TRANSFER_TO_CONSTANT(expr,name) do { for (unsigned int i = 0; i < angleCount; ++i) tmp[i] = (expr) ; cudaMemcpyToSymbol(gC_##name, tmp, angleCount*sizeof(float), 0, cudaMemcpyHostToDevice); } while (0)
- TRANSFER_TO_CONSTANT( (angles[i].fDetSZ - angles[i].fSrcZ)*angles[i].fDetVY - (angles[i].fDetSY - angles[i].fSrcY)*angles[i].fDetVZ , Cux );
- TRANSFER_TO_CONSTANT( (angles[i].fDetSX - angles[i].fSrcX)*angles[i].fDetVZ -(angles[i].fDetSZ - angles[i].fSrcZ)*angles[i].fDetVX , Cuy );
- TRANSFER_TO_CONSTANT( (angles[i].fDetSY - angles[i].fSrcY)*angles[i].fDetVX - (angles[i].fDetSX - angles[i].fSrcX)*angles[i].fDetVY , Cuz );
- TRANSFER_TO_CONSTANT( (angles[i].fDetSY*angles[i].fDetVZ - angles[i].fDetSZ*angles[i].fDetVY)*angles[i].fSrcX - (angles[i].fDetSX*angles[i].fDetVZ - angles[i].fDetSZ*angles[i].fDetVX)*angles[i].fSrcY + (angles[i].fDetSX*angles[i].fDetVY - angles[i].fDetSY*angles[i].fDetVX)*angles[i].fSrcZ , Cuc );
+#define TRANSFER_TO_CONSTANT(expr,name) do { for (unsigned int i = 0; i < angleCount; ++i) tmp[12*i+name] = (expr) ; } while (0)
- TRANSFER_TO_CONSTANT( (angles[i].fDetSY - angles[i].fSrcY)*angles[i].fDetUZ-(angles[i].fDetSZ - angles[i].fSrcZ)*angles[i].fDetUY, Cvx );
- TRANSFER_TO_CONSTANT( (angles[i].fDetSZ - angles[i].fSrcZ)*angles[i].fDetUX - (angles[i].fDetSX - angles[i].fSrcX)*angles[i].fDetUZ , Cvy );
- TRANSFER_TO_CONSTANT((angles[i].fDetSX - angles[i].fSrcX)*angles[i].fDetUY-(angles[i].fDetSY - angles[i].fSrcY)*angles[i].fDetUX , Cvz );
- TRANSFER_TO_CONSTANT( -(angles[i].fDetSY*angles[i].fDetUZ - angles[i].fDetSZ*angles[i].fDetUY)*angles[i].fSrcX + (angles[i].fDetSX*angles[i].fDetUZ - angles[i].fDetSZ*angles[i].fDetUX)*angles[i].fSrcY - (angles[i].fDetSX*angles[i].fDetUY - angles[i].fDetSY*angles[i].fDetUX)*angles[i].fSrcZ , Cvc );
+ TRANSFER_TO_CONSTANT( (angles[i].fDetSZ - angles[i].fSrcZ)*angles[i].fDetVY - (angles[i].fDetSY - angles[i].fSrcY)*angles[i].fDetVZ , 0 );
+ TRANSFER_TO_CONSTANT( (angles[i].fDetSX - angles[i].fSrcX)*angles[i].fDetVZ -(angles[i].fDetSZ - angles[i].fSrcZ)*angles[i].fDetVX , 1 );
+ TRANSFER_TO_CONSTANT( (angles[i].fDetSY - angles[i].fSrcY)*angles[i].fDetVX - (angles[i].fDetSX - angles[i].fSrcX)*angles[i].fDetVY , 2 );
+ TRANSFER_TO_CONSTANT( (angles[i].fDetSY*angles[i].fDetVZ - angles[i].fDetSZ*angles[i].fDetVY)*angles[i].fSrcX - (angles[i].fDetSX*angles[i].fDetVZ - angles[i].fDetSZ*angles[i].fDetVX)*angles[i].fSrcY + (angles[i].fDetSX*angles[i].fDetVY - angles[i].fDetSY*angles[i].fDetVX)*angles[i].fSrcZ , 3 );
- TRANSFER_TO_CONSTANT( angles[i].fDetUY*angles[i].fDetVZ - angles[i].fDetUZ*angles[i].fDetVY , Cdx );
- TRANSFER_TO_CONSTANT( angles[i].fDetUZ*angles[i].fDetVX - angles[i].fDetUX*angles[i].fDetVZ , Cdy );
- TRANSFER_TO_CONSTANT( angles[i].fDetUX*angles[i].fDetVY - angles[i].fDetUY*angles[i].fDetVX , Cdz );
- TRANSFER_TO_CONSTANT( -angles[i].fSrcX * (angles[i].fDetUY*angles[i].fDetVZ - angles[i].fDetUZ*angles[i].fDetVY) - angles[i].fSrcY * (angles[i].fDetUZ*angles[i].fDetVX - angles[i].fDetUX*angles[i].fDetVZ) - angles[i].fSrcZ * (angles[i].fDetUX*angles[i].fDetVY - angles[i].fDetUY*angles[i].fDetVX) , Cdc );
+ TRANSFER_TO_CONSTANT( (angles[i].fDetSY - angles[i].fSrcY)*angles[i].fDetUZ-(angles[i].fDetSZ - angles[i].fSrcZ)*angles[i].fDetUY, 4 );
+ TRANSFER_TO_CONSTANT( (angles[i].fDetSZ - angles[i].fSrcZ)*angles[i].fDetUX - (angles[i].fDetSX - angles[i].fSrcX)*angles[i].fDetUZ , 5 );
+ TRANSFER_TO_CONSTANT((angles[i].fDetSX - angles[i].fSrcX)*angles[i].fDetUY-(angles[i].fDetSY - angles[i].fSrcY)*angles[i].fDetUX , 6 );
+ TRANSFER_TO_CONSTANT( -(angles[i].fDetSY*angles[i].fDetUZ - angles[i].fDetSZ*angles[i].fDetUY)*angles[i].fSrcX + (angles[i].fDetSX*angles[i].fDetUZ - angles[i].fDetSZ*angles[i].fDetUX)*angles[i].fSrcY - (angles[i].fDetSX*angles[i].fDetUY - angles[i].fDetSY*angles[i].fDetUX)*angles[i].fSrcZ , 7 );
+
+ TRANSFER_TO_CONSTANT( angles[i].fDetUY*angles[i].fDetVZ - angles[i].fDetUZ*angles[i].fDetVY , 8 );
+ TRANSFER_TO_CONSTANT( angles[i].fDetUZ*angles[i].fDetVX - angles[i].fDetUX*angles[i].fDetVZ , 9 );
+ TRANSFER_TO_CONSTANT( angles[i].fDetUX*angles[i].fDetVY - angles[i].fDetUY*angles[i].fDetVX , 10 );
+ TRANSFER_TO_CONSTANT( -angles[i].fSrcX * (angles[i].fDetUY*angles[i].fDetVZ - angles[i].fDetUZ*angles[i].fDetVY) - angles[i].fSrcY * (angles[i].fDetUZ*angles[i].fDetVX - angles[i].fDetUX*angles[i].fDetVZ) - angles[i].fSrcZ * (angles[i].fDetUX*angles[i].fDetVY - angles[i].fDetUY*angles[i].fDetVX) , 11 );
#undef TRANSFER_TO_CONSTANT
+ cudaMemcpyToSymbol(gC_C, tmp, angleCount*12*sizeof(float), 0, cudaMemcpyHostToDevice);
delete[] tmp;
dim3 dimBlock(g_volBlockX, g_volBlockY);
- dim3 dimGrid(((dims.iVolX+g_volBlockX-1)/g_volBlockX)*((dims.iVolY+g_volBlockY-1)/g_volBlockY), (dims.iVolZ+g_volBlockZ-1)/g_volBlockZ);
+ dim3 dimGrid(((dims.iVolX/1+g_volBlockX-1)/(g_volBlockX))*((dims.iVolY/1+1*g_volBlockY-1)/(1*g_volBlockY)), (dims.iVolZ+g_volBlockZ-1)/g_volBlockZ);
// timeval t;
// tic(t);
@@ -336,14 +329,15 @@ bool ConeBP(cudaPitchedPtr D_volumeData,
#ifdef STANDALONE
int main()
{
- SDimensions3D dims;
- dims.iVolX = 256;
- dims.iVolY = 256;
- dims.iVolZ = 256;
- dims.iProjAngles = 180;
+ astraCUDA3d::SDimensions3D dims;
+ dims.iVolX = 512;
+ dims.iVolY = 512;
+ dims.iVolZ = 512;
+ dims.iProjAngles = 496;
dims.iProjU = 512;
dims.iProjV = 512;
- dims.iRaysPerDet = 1;
+ dims.iRaysPerDetDim = 1;
+ dims.iRaysPerVoxelDim = 1;
cudaExtent extentV;
extentV.width = dims.iVolX*sizeof(float);
@@ -364,6 +358,7 @@ int main()
cudaMalloc3D(&projData, extentP);
cudaMemset3D(projData, 0, extentP);
+#if 0
float* slice = new float[256*256];
cudaPitchedPtr ptr;
ptr.ptr = slice;
@@ -397,10 +392,11 @@ int main()
}
#endif
}
+#endif
- SConeProjection angle[180];
- angle[0].fSrcX = -1536;
+ astraCUDA3d::SConeProjection angle[512];
+ angle[0].fSrcX = -5120;
angle[0].fSrcY = 0;
angle[0].fSrcZ = 0;
@@ -417,16 +413,18 @@ int main()
angle[0].fDetVZ = 1;
#define ROTATE0(name,i,alpha) do { angle[i].f##name##X = angle[0].f##name##X * cos(alpha) - angle[0].f##name##Y * sin(alpha); angle[i].f##name##Y = angle[0].f##name##X * sin(alpha) + angle[0].f##name##Y * cos(alpha); } while(0)
- for (int i = 1; i < 180; ++i) {
+ for (int i = 1; i < 512; ++i) {
angle[i] = angle[0];
- ROTATE0(Src, i, i*2*M_PI/180);
- ROTATE0(DetS, i, i*2*M_PI/180);
- ROTATE0(DetU, i, i*2*M_PI/180);
- ROTATE0(DetV, i, i*2*M_PI/180);
+ ROTATE0(Src, i, i*2*M_PI/512);
+ ROTATE0(DetS, i, i*2*M_PI/512);
+ ROTATE0(DetU, i, i*2*M_PI/512);
+ ROTATE0(DetV, i, i*2*M_PI/512);
}
#undef ROTATE0
+#if 0
astraCUDA3d::ConeFP(volData, projData, dims, angle, 1.0f);
+#endif
#if 0
float* bufs = new float[180*512];
@@ -452,6 +450,7 @@ int main()
saveImage(fname, 512, 512, bufp);
}
#endif
+#if 0
for (unsigned int i = 0; i < 256*256; ++i)
slice[i] = 0.0f;
for (unsigned int i = 0; i < 256; ++i) {
@@ -472,6 +471,7 @@ int main()
p.kind = cudaMemcpyHostToDevice;
cudaMemcpy3D(&p);
}
+#endif
astraCUDA3d::ConeBP(volData, projData, dims, angle);
#if 0
diff --git a/cuda/3d/dims3d.h b/cuda/3d/dims3d.h
index de2a0d0..5437a85 100644
--- a/cuda/3d/dims3d.h
+++ b/cuda/3d/dims3d.h
@@ -29,37 +29,7 @@ $Id$
#ifndef _CUDA_CONE_DIMS_H
#define _CUDA_CONE_DIMS_H
-namespace astra {
-
-struct SConeProjection {
- // the source
- double fSrcX, fSrcY, fSrcZ;
-
- // the origin ("bottom left") of the (flat-panel) detector
- double fDetSX, fDetSY, fDetSZ;
-
- // the U-edge of a detector pixel
- double fDetUX, fDetUY, fDetUZ;
-
- // the V-edge of a detector pixel
- double fDetVX, fDetVY, fDetVZ;
-};
-
-struct SPar3DProjection {
- // the ray direction
- double fRayX, fRayY, fRayZ;
-
- // the origin ("bottom left") of the (flat-panel) detector
- double fDetSX, fDetSY, fDetSZ;
-
- // the U-edge of a detector pixel
- double fDetUX, fDetUY, fDetUZ;
-
- // the V-edge of a detector pixel
- double fDetVX, fDetVY, fDetVZ;
-};
-
-}
+#include "astra/GeometryUtil3D.h"
namespace astraCUDA3d {
diff --git a/cuda/3d/par3d_bp.cu b/cuda/3d/par3d_bp.cu
index 8b9dac1..0c33280 100644
--- a/cuda/3d/par3d_bp.cu
+++ b/cuda/3d/par3d_bp.cu
@@ -47,22 +47,16 @@ static texture3D gT_par3DProjTexture;
namespace astraCUDA3d {
-static const unsigned int g_volBlockZ = 16;
+#define ZSIZE 6
+static const unsigned int g_volBlockZ = ZSIZE;
-static const unsigned int g_anglesPerBlock = 64;
-static const unsigned int g_volBlockX = 32;
-static const unsigned int g_volBlockY = 16;
+static const unsigned int g_anglesPerBlock = 32;
+static const unsigned int g_volBlockX = 16;
+static const unsigned int g_volBlockY = 32;
static const unsigned g_MaxAngles = 1024;
-__constant__ float gC_Cux[g_MaxAngles];
-__constant__ float gC_Cuy[g_MaxAngles];
-__constant__ float gC_Cuz[g_MaxAngles];
-__constant__ float gC_Cuc[g_MaxAngles];
-__constant__ float gC_Cvx[g_MaxAngles];
-__constant__ float gC_Cvy[g_MaxAngles];
-__constant__ float gC_Cvz[g_MaxAngles];
-__constant__ float gC_Cvc[g_MaxAngles];
+__constant__ float gC_C[8*g_MaxAngles];
static bool bindProjDataTexture(const cudaArray* array)
@@ -95,12 +89,9 @@ __global__ void dev_par3D_BP(void* D_volData, unsigned int volPitch, int startAn
// y = rel y
// blockIdx: x = x + y
- // y = z
+ // y = z
- // TO TRY: precompute part of detector intersection formulas in shared mem?
- // TO TRY: inner loop over z, gather ray values in shared mem
-
const int X = blockIdx.x % ((dims.iVolX+g_volBlockX-1)/g_volBlockX) * g_volBlockX + threadIdx.x;
const int Y = blockIdx.x / ((dims.iVolX+g_volBlockX-1)/g_volBlockX) * g_volBlockY + threadIdx.y;
@@ -110,42 +101,45 @@ __global__ void dev_par3D_BP(void* D_volData, unsigned int volPitch, int startAn
return;
const int startZ = blockIdx.y * g_volBlockZ;
- int endZ = startZ + g_volBlockZ;
- if (endZ > dims.iVolZ)
- endZ = dims.iVolZ;
float fX = X - 0.5f*dims.iVolX + 0.5f;
float fY = Y - 0.5f*dims.iVolY + 0.5f;
float fZ = startZ - 0.5f*dims.iVolZ + 0.5f;
- for (int Z = startZ; Z < endZ; ++Z, fZ += 1.0f)
- {
+ float Z[ZSIZE];
+ for(int i=0; i < ZSIZE; i++)
+ Z[i] = 0.0f;
- float fVal = 0.0f;
+ {
float fAngle = startAngle + angleOffset + 0.5f;
for (int angle = startAngle; angle < endAngle; ++angle, fAngle += 1.0f)
{
- const float fCux = gC_Cux[angle];
- const float fCuy = gC_Cuy[angle];
- const float fCuz = gC_Cuz[angle];
- const float fCuc = gC_Cuc[angle];
- const float fCvx = gC_Cvx[angle];
- const float fCvy = gC_Cvy[angle];
- const float fCvz = gC_Cvz[angle];
- const float fCvc = gC_Cvc[angle];
+ float4 fCu = make_float4(gC_C[8*angle+0], gC_C[8*angle+1], gC_C[8*angle+2], gC_C[8*angle+3]);
+ float4 fCv = make_float4(gC_C[8*angle+4], gC_C[8*angle+5], gC_C[8*angle+6], gC_C[8*angle+7]);
- const float fU = fCuc + fX * fCux + fY * fCuy + fZ * fCuz;
- const float fV = fCvc + fX * fCvx + fY * fCvy + fZ * fCvz;
+ float fU = fCu.w + fX * fCu.x + fY * fCu.y + fZ * fCu.z;
+ float fV = fCv.w + fX * fCv.x + fY * fCv.y + fZ * fCv.z;
- fVal += tex3D(gT_par3DProjTexture, fU, fAngle, fV);
+ for (int idx = 0; idx < ZSIZE; ++idx) {
- }
+ float fVal = tex3D(gT_par3DProjTexture, fU, fAngle, fV);
+ Z[idx] += fVal;
+
+ fU += fCu.z;
+ fV += fCv.z;
+ }
- volData[(Z*dims.iVolY+Y)*volPitch+X] += fVal;
+ }
}
+ int endZ = ZSIZE;
+ if (endZ > dims.iVolZ - startZ)
+ endZ = dims.iVolZ - startZ;
+
+ for(int i=0; i < endZ; i++)
+ volData[((startZ+i)*dims.iVolY+Y)*volPitch+X] += Z[i];
}
// supersampling version
@@ -194,14 +188,14 @@ __global__ void dev_par3D_BP_SS(void* D_volData, unsigned int volPitch, int star
for (int angle = startAngle; angle < endAngle; ++angle, fAngle += 1.0f)
{
- const float fCux = gC_Cux[angle];
- const float fCuy = gC_Cuy[angle];
- const float fCuz = gC_Cuz[angle];
- const float fCuc = gC_Cuc[angle];
- const float fCvx = gC_Cvx[angle];
- const float fCvy = gC_Cvy[angle];
- const float fCvz = gC_Cvz[angle];
- const float fCvc = gC_Cvc[angle];
+ const float fCux = gC_C[8*angle+0];
+ const float fCuy = gC_C[8*angle+1];
+ const float fCuz = gC_C[8*angle+2];
+ const float fCuc = gC_C[8*angle+3];
+ const float fCvx = gC_C[8*angle+4];
+ const float fCvy = gC_C[8*angle+5];
+ const float fCvz = gC_C[8*angle+6];
+ const float fCvc = gC_C[8*angle+7];
float fXs = fX;
for (int iSubX = 0; iSubX < dims.iRaysPerVoxelDim; ++iSubX) {
@@ -240,26 +234,30 @@ bool Par3DBP_Array(cudaPitchedPtr D_volumeData,
angleCount = dims.iProjAngles - th;
// transfer angles to constant memory
- float* tmp = new float[dims.iProjAngles];
+ float* tmp = new float[8*dims.iProjAngles];
// NB: We increment angles at the end of the loop body.
-#define TRANSFER_TO_CONSTANT(expr,name) do { for (unsigned int i = 0; i < angleCount; ++i) tmp[i] = (expr) ; cudaMemcpyToSymbol(gC_##name, tmp, angleCount*sizeof(float), 0, cudaMemcpyHostToDevice); } while (0)
+
+ // TODO: Use functions from dims3d.cu for this:
+
+#define TRANSFER_TO_CONSTANT(expr,name) do { for (unsigned int i = 0; i < angleCount; ++i) tmp[8*i + name] = (expr) ; } while (0)
#define DENOM (angles[i].fRayX*angles[i].fDetUY*angles[i].fDetVZ - angles[i].fRayX*angles[i].fDetUZ*angles[i].fDetVY - angles[i].fRayY*angles[i].fDetUX*angles[i].fDetVZ + angles[i].fRayY*angles[i].fDetUZ*angles[i].fDetVX + angles[i].fRayZ*angles[i].fDetUX*angles[i].fDetVY - angles[i].fRayZ*angles[i].fDetUY*angles[i].fDetVX)
- TRANSFER_TO_CONSTANT( ( - (angles[i].fRayY*angles[i].fDetVZ - angles[i].fRayZ*angles[i].fDetVY)) / DENOM , Cux );
- TRANSFER_TO_CONSTANT( ( (angles[i].fRayX*angles[i].fDetVZ - angles[i].fRayZ*angles[i].fDetVX)) / DENOM , Cuy );
- TRANSFER_TO_CONSTANT( (- (angles[i].fRayX*angles[i].fDetVY - angles[i].fRayY*angles[i].fDetVX) ) / DENOM , Cuz );
- TRANSFER_TO_CONSTANT( (-(angles[i].fDetSY*angles[i].fDetVZ - angles[i].fDetSZ*angles[i].fDetVY)*angles[i].fRayX + (angles[i].fRayY*angles[i].fDetVZ - angles[i].fRayZ*angles[i].fDetVY)*angles[i].fDetSX - (angles[i].fRayY*angles[i].fDetSZ - angles[i].fRayZ*angles[i].fDetSY)*angles[i].fDetVX) / DENOM , Cuc );
+ TRANSFER_TO_CONSTANT( ( - (angles[i].fRayY*angles[i].fDetVZ - angles[i].fRayZ*angles[i].fDetVY)) / DENOM , 0 );
+ TRANSFER_TO_CONSTANT( ( (angles[i].fRayX*angles[i].fDetVZ - angles[i].fRayZ*angles[i].fDetVX)) / DENOM , 1 );
+ TRANSFER_TO_CONSTANT( (- (angles[i].fRayX*angles[i].fDetVY - angles[i].fRayY*angles[i].fDetVX) ) / DENOM , 2 );
+ TRANSFER_TO_CONSTANT( (-(angles[i].fDetSY*angles[i].fDetVZ - angles[i].fDetSZ*angles[i].fDetVY)*angles[i].fRayX + (angles[i].fRayY*angles[i].fDetVZ - angles[i].fRayZ*angles[i].fDetVY)*angles[i].fDetSX - (angles[i].fRayY*angles[i].fDetSZ - angles[i].fRayZ*angles[i].fDetSY)*angles[i].fDetVX) / DENOM , 3 );
- TRANSFER_TO_CONSTANT( ((angles[i].fRayY*angles[i].fDetUZ - angles[i].fRayZ*angles[i].fDetUY) ) / DENOM , Cvx );
- TRANSFER_TO_CONSTANT( (- (angles[i].fRayX*angles[i].fDetUZ - angles[i].fRayZ*angles[i].fDetUX) ) / DENOM , Cvy );
- TRANSFER_TO_CONSTANT( ((angles[i].fRayX*angles[i].fDetUY - angles[i].fRayY*angles[i].fDetUX) ) / DENOM , Cvz );
- TRANSFER_TO_CONSTANT( ((angles[i].fDetSY*angles[i].fDetUZ - angles[i].fDetSZ*angles[i].fDetUY)*angles[i].fRayX - (angles[i].fRayY*angles[i].fDetUZ - angles[i].fRayZ*angles[i].fDetUY)*angles[i].fDetSX + (angles[i].fRayY*angles[i].fDetSZ - angles[i].fRayZ*angles[i].fDetSY)*angles[i].fDetUX ) / DENOM , Cvc );
+ TRANSFER_TO_CONSTANT( ((angles[i].fRayY*angles[i].fDetUZ - angles[i].fRayZ*angles[i].fDetUY) ) / DENOM , 4 );
+ TRANSFER_TO_CONSTANT( (- (angles[i].fRayX*angles[i].fDetUZ - angles[i].fRayZ*angles[i].fDetUX) ) / DENOM , 5 );
+ TRANSFER_TO_CONSTANT( ((angles[i].fRayX*angles[i].fDetUY - angles[i].fRayY*angles[i].fDetUX) ) / DENOM , 6 );
+ TRANSFER_TO_CONSTANT( ((angles[i].fDetSY*angles[i].fDetUZ - angles[i].fDetSZ*angles[i].fDetUY)*angles[i].fRayX - (angles[i].fRayY*angles[i].fDetUZ - angles[i].fRayZ*angles[i].fDetUY)*angles[i].fDetSX + (angles[i].fRayY*angles[i].fDetSZ - angles[i].fRayZ*angles[i].fDetSY)*angles[i].fDetUX ) / DENOM , 7 );
#undef TRANSFER_TO_CONSTANT
#undef DENOM
+ cudaMemcpyToSymbol(gC_C, tmp, angleCount*8*sizeof(float), 0, cudaMemcpyHostToDevice);
delete[] tmp;
diff --git a/cuda/3d/util3d.cu b/cuda/3d/util3d.cu
index d85a928..537ed69 100644
--- a/cuda/3d/util3d.cu
+++ b/cuda/3d/util3d.cu
@@ -31,6 +31,8 @@ $Id$
#include "util3d.h"
#include "../2d/util.h"
+#include "../../include/astra/Logging.h"
+
namespace astraCUDA3d {
@@ -46,7 +48,7 @@ cudaPitchedPtr allocateVolumeData(const SDimensions3D& dims)
cudaError err = cudaMalloc3D(&volData, extentV);
if (err != cudaSuccess) {
astraCUDA::reportCudaError(err);
- fprintf(stderr, "Failed to allocate %dx%dx%d GPU buffer\n", dims.iVolX, dims.iVolY, dims.iVolZ);
+ ASTRA_ERROR("Failed to allocate %dx%dx%d GPU buffer", dims.iVolX, dims.iVolY, dims.iVolZ);
volData.ptr = 0;
// TODO: return 0 somehow?
}
@@ -65,7 +67,7 @@ cudaPitchedPtr allocateProjectionData(const SDimensions3D& dims)
cudaError err = cudaMalloc3D(&projData, extentP);
if (err != cudaSuccess) {
astraCUDA::reportCudaError(err);
- fprintf(stderr, "Failed to allocate %dx%dx%d GPU buffer\n", dims.iProjU, dims.iProjAngles, dims.iProjV);
+ ASTRA_ERROR("Failed to allocate %dx%dx%d GPU buffer", dims.iProjU, dims.iProjAngles, dims.iProjV);
projData.ptr = 0;
// TODO: return 0 somehow?
}
@@ -303,7 +305,7 @@ cudaArray* allocateVolumeArray(const SDimensions3D& dims)
cudaError err = cudaMalloc3DArray(&cuArray, &channelDesc, extentA);
if (err != cudaSuccess) {
astraCUDA::reportCudaError(err);
- fprintf(stderr, "Failed to allocate %dx%dx%d GPU array\n", dims.iVolX, dims.iVolY, dims.iVolZ);
+ ASTRA_ERROR("Failed to allocate %dx%dx%d GPU array", dims.iVolX, dims.iVolY, dims.iVolZ);
return 0;
}
@@ -321,7 +323,7 @@ cudaArray* allocateProjectionArray(const SDimensions3D& dims)
if (err != cudaSuccess) {
astraCUDA::reportCudaError(err);
- fprintf(stderr, "Failed to allocate %dx%dx%d GPU array\n", dims.iProjU, dims.iProjAngles, dims.iProjV);
+ ASTRA_ERROR("Failed to allocate %dx%dx%d GPU array", dims.iProjU, dims.iProjAngles, dims.iProjV);
return 0;
}
@@ -397,7 +399,7 @@ bool cudaTextForceKernelsCompletion()
cudaError_t returnedCudaError = cudaThreadSynchronize();
if(returnedCudaError != cudaSuccess) {
- fprintf(stderr, "Failed to force completion of cuda kernels: %d: %s.\n", returnedCudaError, cudaGetErrorString(returnedCudaError));
+ ASTRA_ERROR("Failed to force completion of cuda kernels: %d: %s.", returnedCudaError, cudaGetErrorString(returnedCudaError));
return false;
}