diff options
Diffstat (limited to 'cuda/2d')
-rw-r--r-- | cuda/2d/astra.cu | 309 | ||||
-rw-r--r-- | cuda/2d/astra.h | 39 | ||||
-rw-r--r-- | cuda/2d/dims.h | 12 | ||||
-rw-r--r-- | cuda/2d/fft.cu | 45 | ||||
-rw-r--r-- | cuda/2d/util.cu | 8 |
5 files changed, 251 insertions, 162 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)); } |