From e5b70e8b53e4ecc81b1aacc3af7893faf49ddc24 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 22 Jun 2018 15:46:11 +0200 Subject: Move CUDA include files --- include/astra/cuda/2d/algo.h | 173 ++++++++++++++++++++++++++++++++++++ include/astra/cuda/2d/arith.h | 85 ++++++++++++++++++ include/astra/cuda/2d/astra.h | 127 ++++++++++++++++++++++++++ include/astra/cuda/2d/cgls.h | 90 +++++++++++++++++++ include/astra/cuda/2d/darthelper.h | 41 +++++++++ include/astra/cuda/2d/dims.h | 68 ++++++++++++++ include/astra/cuda/2d/em.h | 75 ++++++++++++++++ include/astra/cuda/2d/fan_bp.h | 52 +++++++++++ include/astra/cuda/2d/fan_fp.h | 40 +++++++++ include/astra/cuda/2d/fbp.h | 97 ++++++++++++++++++++ include/astra/cuda/2d/fbp_filters.h | 61 +++++++++++++ include/astra/cuda/2d/fft.h | 72 +++++++++++++++ include/astra/cuda/2d/par_bp.h | 47 ++++++++++ include/astra/cuda/2d/par_fp.h | 40 +++++++++ include/astra/cuda/2d/sart.h | 87 ++++++++++++++++++ include/astra/cuda/2d/sirt.h | 96 ++++++++++++++++++++ include/astra/cuda/2d/util.h | 84 +++++++++++++++++ 17 files changed, 1335 insertions(+) create mode 100644 include/astra/cuda/2d/algo.h create mode 100644 include/astra/cuda/2d/arith.h create mode 100644 include/astra/cuda/2d/astra.h create mode 100644 include/astra/cuda/2d/cgls.h create mode 100644 include/astra/cuda/2d/darthelper.h create mode 100644 include/astra/cuda/2d/dims.h create mode 100644 include/astra/cuda/2d/em.h create mode 100644 include/astra/cuda/2d/fan_bp.h create mode 100644 include/astra/cuda/2d/fan_fp.h create mode 100644 include/astra/cuda/2d/fbp.h create mode 100644 include/astra/cuda/2d/fbp_filters.h create mode 100644 include/astra/cuda/2d/fft.h create mode 100644 include/astra/cuda/2d/par_bp.h create mode 100644 include/astra/cuda/2d/par_fp.h create mode 100644 include/astra/cuda/2d/sart.h create mode 100644 include/astra/cuda/2d/sirt.h create mode 100644 include/astra/cuda/2d/util.h (limited to 'include/astra/cuda/2d') diff --git a/include/astra/cuda/2d/algo.h b/include/astra/cuda/2d/algo.h new file mode 100644 index 0000000..2ce929c --- /dev/null +++ b/include/astra/cuda/2d/algo.h @@ -0,0 +1,173 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_ALGO_H +#define _CUDA_ALGO_H + +#include "astra/Globals.h" +#include "dims.h" + +namespace astra { + +class CParallelProjectionGeometry2D; +class CParallelVecProjectionGeometry2D; +class CFanFlatProjectionGeometry2D; +class CFanFlatVecProjectionGeometry2D; +class CVolumeGeometry2D; +class CProjectionGeometry2D; + +} + +namespace astraCUDA { + +class _AstraExport ReconAlgo { +public: + ReconAlgo(); + virtual ~ReconAlgo(); + + bool setGPUIndex(int iGPUIndex); + + bool setGeometry(const astra::CVolumeGeometry2D* pVolGeom, + const astra::CProjectionGeometry2D* pProjGeom); + + bool setSuperSampling(int raysPerDet, int raysPerPixelDim); + + void signalAbort() { shouldAbort = true; } + + virtual bool enableVolumeMask(); + virtual bool enableSinogramMask(); + + // init should be called after setting all geometry + virtual bool init() = 0; + + // setVolumeMask should be called after init and before iterate, + // but only if enableVolumeMask was called before init. + // It may be called again after iterate. + bool setVolumeMask(float* D_maskData, unsigned int maskPitch); + + // setSinogramMask should be called after init and before iterate, + // but only if enableSinogramMask was called before init. + // It may be called again after iterate. + bool setSinogramMask(float* D_smaskData, unsigned int smaskPitch); + + + // setBuffers should be called after init and before iterate. + // It may be called again after iterate. + virtual bool setBuffers(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch); + + + // instead of calling setBuffers, you can also call allocateBuffers + // to let ReconAlgo manage its own GPU memory + virtual bool allocateBuffers(); + + // copy data to GPU. This must be called after allocateBuffers. + // pfSinogram, pfReconstruction, pfVolMask, pfSinoMask are the + // sinogram, reconstruction, volume mask and sinogram mask in system RAM, + // respectively. The corresponding pitch variables give the pitches + // of these buffers, measured in floats. + // The sinogram is multiplied by fSinogramScale after uploading it. + virtual bool copyDataToGPU(const float* pfSinogram, unsigned int iSinogramPitch, float fSinogramScale, + const float* pfReconstruction, unsigned int iReconstructionPitch, + const float* pfVolMask, unsigned int iVolMaskPitch, + const float* pfSinoMask, unsigned int iSinoMaskPitch); + + + + // set Min/Max constraints. They may be called at any time, and will affect + // any iterate() calls afterwards. + virtual bool setMinConstraint(float fMin); + virtual bool setMaxConstraint(float fMax); + + + // iterate should be called after init and setBuffers. + // It may be called multiple times. + virtual bool iterate(unsigned int iterations) = 0; + + // Compute the norm of the difference of the FP of the current + // reconstruction and the sinogram. (This performs one FP.) + // It can be called after iterate. + virtual float computeDiffNorm() = 0; + // TODO: computeDiffNorm shouldn't be virtual, but for it to be + // implemented in ReconAlgo, it needs a way to get a suitable + // temporary sinogram buffer. + + bool getReconstruction(float* pfReconstruction, + unsigned int iReconstructionPitch) const; + + + +protected: + void reset(); + + bool callFP(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + float outputScale); + bool callBP(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + float outputScale); + + + SDimensions dims; + SParProjection* parProjs; + SFanProjection* fanProjs; + float fOutputScale; + + volatile bool shouldAbort; + + bool freeGPUMemory; + + // Input/output + float* D_sinoData; + unsigned int sinoPitch; + + float* D_volumeData; + unsigned int volumePitch; + + // Masks + bool useVolumeMask; + bool useSinogramMask; + + float* D_maskData; + unsigned int maskPitch; + float* D_smaskData; + unsigned int smaskPitch; + + // Min/max + bool useMinConstraint; + bool useMaxConstraint; + float fMinConstraint; + float fMaxConstraint; + + +}; + + +} + +#endif + diff --git a/include/astra/cuda/2d/arith.h b/include/astra/cuda/2d/arith.h new file mode 100644 index 0000000..e18bb1b --- /dev/null +++ b/include/astra/cuda/2d/arith.h @@ -0,0 +1,85 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_ARITH_H +#define _CUDA_ARITH_H + +#include + +namespace astraCUDA { + + +struct opAddScaled; +struct opScaleAndAdd; +struct opAddMulScaled; +struct opAddMul; +struct opAdd; +struct opAdd2; +struct opMul; +struct opDiv; +struct opMul2; +struct opDividedBy; +struct opInvert; +struct opSet; +struct opClampMin; +struct opClampMax; +struct opClampMinMask; +struct opClampMaxMask; +struct opSegmentAndMask; +struct opSetMaskedValues; + +struct opMulMask; + + +template void processVolCopy(float* out, const SDimensions& dims); +template void processVolCopy(float* out, float param, const SDimensions& dims); +template void processVolCopy(float* out1, float* out2, float param1, float param2, const SDimensions& dims); +template void processVolCopy(float* out, const float* in, const SDimensions& dims); +template void processVolCopy(float* out, const float* in, float param, const SDimensions& dims); +template void processVolCopy(float* out, const float* in1, const float* in2, const SDimensions& dims); +template void processVolCopy(float* out, const float* in1, const float* in2, float param, const SDimensions& dims); + +template void processVol(float* out, unsigned int pitch, const SDimensions& dims); +template void processVol(float* out, float fParam, unsigned int pitch, const SDimensions& dims); +template void processVol(float* out1, float* out2, float fParam1, float fParam2, unsigned int pitch, const SDimensions& dims); +template void processVol(float* out, const float* in, unsigned int pitch, const SDimensions& dims); +template void processVol(float* out, const float* in, float fParam, unsigned int pitch, const SDimensions& dims); +template void processVol(float* out, const float* in1, const float* in2, float fParam, unsigned int pitch, const SDimensions& dims); +template void processVol(float* out, const float* in1, const float* in2, unsigned int pitch, const SDimensions& dims); + +template void processSino(float* out, unsigned int pitch, const SDimensions& dims); +template void processSino(float* out, float fParam, unsigned int pitch, const SDimensions& dims); +template void processSino(float* out1, float* out2, float fParam1, float fParam2, unsigned int pitch, const SDimensions& dims); +template void processSino(float* out, const float* in, unsigned int pitch, const SDimensions& dims); +template void processSino(float* out, const float* in, float fParam, unsigned int pitch, const SDimensions& dims); +template void processSino(float* out, const float* in1, const float* in2, float fParam, unsigned int pitch, const SDimensions& dims); +template void processSino(float* out, const float* in1, const float* in2, unsigned int pitch, const SDimensions& dims); + + +} + +#endif diff --git a/include/astra/cuda/2d/astra.h b/include/astra/cuda/2d/astra.h new file mode 100644 index 0000000..6f0e2f0 --- /dev/null +++ b/include/astra/cuda/2d/astra.h @@ -0,0 +1,127 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_ASTRA_H +#define _CUDA_ASTRA_H + +#include "fbp_filters.h" +#include "dims.h" +#include "algo.h" + +using astraCUDA::SFanProjection; + +namespace astra { + +enum Cuda2DProjectionKernel { + ker2d_default = 0 +}; + +class CParallelProjectionGeometry2D; +class CParallelVecProjectionGeometry2D; +class CFanFlatProjectionGeometry2D; +class CFanFlatVecProjectionGeometry2D; +class CVolumeGeometry2D; +class CProjectionGeometry2D; + + +class _AstraExport BPalgo : public astraCUDA::ReconAlgo { +public: + BPalgo(); + ~BPalgo(); + + virtual bool init(); + + virtual bool iterate(unsigned int iterations); + + virtual float computeDiffNorm(); +}; + + + + +// TODO: Clean up this interface to FP + +// Do a single forward projection +_AstraExport bool astraCudaFP(const float* pfVolume, float* pfSinogram, + unsigned int iVolWidth, unsigned int iVolHeight, + unsigned int iProjAngles, unsigned int iProjDets, + const SParProjection *pAngles, + unsigned int iDetSuperSampling = 1, + 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, + float fOutputScale = 1.0f, int iGPUIndex = 0); + + +_AstraExport bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom, + const CParallelProjectionGeometry2D* pProjGeom, + astraCUDA::SParProjection*& pProjs, + float& fOutputScale); + +_AstraExport bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom, + const CParallelVecProjectionGeometry2D* pProjGeom, + astraCUDA::SParProjection*& pProjs, + 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); + +_AstraExport bool convertAstraGeometry_dims(const CVolumeGeometry2D* pVolGeom, + const CProjectionGeometry2D* pProjGeom, + astraCUDA::SDimensions& dims); + +_AstraExport bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom, + const CProjectionGeometry2D* pProjGeom, + astraCUDA::SParProjection*& pParProjs, + astraCUDA::SFanProjection*& pFanProjs, + float& outputScale); +} + +namespace astraCUDA { + +// Return string with CUDA device number, name and memory size. +// Use device == -1 to get info for the current device. +_AstraExport std::string getCudaDeviceString(int device); + +_AstraExport bool setGPUIndex(int index); + +_AstraExport size_t availableGPUMemory(); + +} +#endif diff --git a/include/astra/cuda/2d/cgls.h b/include/astra/cuda/2d/cgls.h new file mode 100644 index 0000000..375a425 --- /dev/null +++ b/include/astra/cuda/2d/cgls.h @@ -0,0 +1,90 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_CGLS_H +#define _CUDA_CGLS_H + +#include "algo.h" + +namespace astraCUDA { + +class _AstraExport CGLS : public ReconAlgo { +public: + CGLS(); + virtual ~CGLS(); + + // disable some features + virtual bool enableSinogramMask() { return false; } + virtual bool setMinConstraint(float) { return false; } + virtual bool setMaxConstraint(float) { return false; } + + virtual bool init(); + + virtual bool setBuffers(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch); + + virtual bool copyDataToGPU(const float* pfSinogram, unsigned int iSinogramPitch, float fSinogramScale, + const float* pfReconstruction, unsigned int iReconstructionPitch, + const float* pfVolMask, unsigned int iVolMaskPitch, + const float* pfSinoMask, unsigned int iSinoMaskPitch); + + + virtual bool iterate(unsigned int iterations); + + virtual float computeDiffNorm(); + +protected: + void reset(); + + bool sliceInitialized; + + // Buffers + float* D_r; + unsigned int rPitch; + + float* D_w; + unsigned int wPitch; + + float* D_z; + unsigned int zPitch; + + float* D_p; + unsigned int pPitch; + + + float gamma; +}; + + +_AstraExport bool doCGLS(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + const SDimensions& dims, const float* angles, + const float* TOffsets, unsigned int iterations); + +} + +#endif diff --git a/include/astra/cuda/2d/darthelper.h b/include/astra/cuda/2d/darthelper.h new file mode 100644 index 0000000..3c2f83c --- /dev/null +++ b/include/astra/cuda/2d/darthelper.h @@ -0,0 +1,41 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_ARITH2_H +#define _CUDA_ARITH2_H + +#include "astra/Globals.h" + +namespace astraCUDA { + + void roiSelect(float* out, float radius, unsigned int width, unsigned int height); + void dartMask(float* out, const float* in, unsigned int conn, unsigned int radius, unsigned int threshold, unsigned int width, unsigned int height); + void dartSmoothing(float* out, const float* in, float b, unsigned int radius, unsigned int width, unsigned int height); + +} + +#endif diff --git a/include/astra/cuda/2d/dims.h b/include/astra/cuda/2d/dims.h new file mode 100644 index 0000000..0bdefa9 --- /dev/null +++ b/include/astra/cuda/2d/dims.h @@ -0,0 +1,68 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_DIMS_H +#define _CUDA_DIMS_H + +#include "astra/GeometryUtil2D.h" + + +namespace astraCUDA { + +using astra::SParProjection; +using astra::SFanProjection; + + + +struct SDimensions { + // Width, height of reconstruction volume + unsigned int iVolWidth; + unsigned int iVolHeight; + + // Number of projection angles + unsigned int iProjAngles; + + // Number of detector pixels + unsigned int iProjDets; + + // in FP, number of rays to trace per detector pixel. + // This should usually be set to 1. + // If fDetScale > 1, this should be set to an integer of roughly + // the same size as fDetScale. + unsigned int iRaysPerDet; + + // in BP, square root of number of rays to trace per volume pixel + // This should usually be set to 1. + // If fDetScale < 1, this should be set to an integer of roughly + // the same size as 1 / fDetScale. + unsigned int iRaysPerPixelDim; +}; + +} + +#endif + diff --git a/include/astra/cuda/2d/em.h b/include/astra/cuda/2d/em.h new file mode 100644 index 0000000..3ffe01b --- /dev/null +++ b/include/astra/cuda/2d/em.h @@ -0,0 +1,75 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_EM_H +#define _CUDA_EM_H + +#include "algo.h" + +namespace astraCUDA { + +class _AstraExport EM : public ReconAlgo { +public: + EM(); + virtual ~EM(); + + // disable some features + virtual bool enableSinogramMask() { return false; } + virtual bool enableVolumeMask() { return false; } + virtual bool setMinConstraint(float) { return false; } + virtual bool setMaxConstraint(float) { return false; } + + virtual bool init(); + + virtual bool iterate(unsigned int iterations); + + virtual float computeDiffNorm(); + +protected: + void reset(); + bool precomputeWeights(); + + // Temporary buffers + float* D_projData; + unsigned int projPitch; + + float* D_tmpData; + unsigned int tmpPitch; + + // Geometry-specific precomputed data + float* D_pixelWeight; + unsigned int pixelPitch; +}; + +_AstraExport bool doEM(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + const SDimensions& dims, const float* angles, + const float* TOffsets, unsigned int iterations); + +} + +#endif diff --git a/include/astra/cuda/2d/fan_bp.h b/include/astra/cuda/2d/fan_bp.h new file mode 100644 index 0000000..22349b0 --- /dev/null +++ b/include/astra/cuda/2d/fan_bp.h @@ -0,0 +1,52 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_FAN_BP_H +#define _CUDA_FAN_BP_H + +namespace astraCUDA { + +_AstraExport bool FanBP(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + const SDimensions& dims, const SFanProjection* angles, + float fOutputScale); + +_AstraExport bool FanBP_SART(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + unsigned int angle, + const SDimensions& dims, const SFanProjection* angles, + float fOutputScale); + +_AstraExport bool FanBP_FBPWeighted(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + const SDimensions& dims, const SFanProjection* angles, + float fOutputScale); + + +} + +#endif diff --git a/include/astra/cuda/2d/fan_fp.h b/include/astra/cuda/2d/fan_fp.h new file mode 100644 index 0000000..3e8f1e4 --- /dev/null +++ b/include/astra/cuda/2d/fan_fp.h @@ -0,0 +1,40 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_FAN_FP_H +#define _CUDA_FAN_FP_H + +namespace astraCUDA { + +_AstraExport bool FanFP(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + const SDimensions& dims, const SFanProjection* angles, + float outputScale); + +} + +#endif diff --git a/include/astra/cuda/2d/fbp.h b/include/astra/cuda/2d/fbp.h new file mode 100644 index 0000000..8666646 --- /dev/null +++ b/include/astra/cuda/2d/fbp.h @@ -0,0 +1,97 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#include "algo.h" +#include "fbp_filters.h" + +namespace astraCUDA { + +class _AstraExport FBP : public ReconAlgo { +public: + FBP(); + ~FBP(); + + virtual bool useSinogramMask() { return false; } + virtual bool useVolumeMask() { return false; } + + // Returns the required size of a filter in the fourier domain + // when multiplying it with the fft of the projection data. + // Its value is equal to the smallest power of two larger than + // or equal to twice the number of detectors in the spatial domain. + // + // _iDetectorCount is the number of detectors in the spatial domain. + static int calcFourierFilterSize(int _iDetectorCount); + + // Sets the filter type. Some filter types require the user to supply an + // array containing the filter. + // The number of elements in a filter in the fourier domain should be equal + // to the value returned by calcFourierFilterSize(). + // The following types require a filter: + // + // - FILTER_PROJECTION: + // The filter size should be equal to the output of + // calcFourierFilterSize(). The filtered sinogram is + // multiplied with the supplied filter. + // + // - FILTER_SINOGRAM: + // Same as FILTER_PROJECTION, but now the filter should contain a row for + // every projection direction. + // + // - FILTER_RPROJECTION: + // The filter should now contain one kernel (= ifft of filter), with the + // peak in the center. The filter width + // can be any value. If odd, the peak is assumed to be in the center, if + // even, it is assumed to be at floor(filter-width/2). + // + // - FILTER_RSINOGRAM + // Same as FILTER_RPROJECTION, but now the supplied filter should contain a + // row for every projection direction. + // + // A large number of other filters (FILTER_RAMLAK, FILTER_SHEPPLOGAN, + // FILTER_COSINE, FILTER_HAMMING, and FILTER_HANN) + // have a D variable, which gives the cutoff point in the frequency domain. + // Setting this value to 1.0 will include the whole filter + bool setFilter(astra::E_FBPFILTER _eFilter, + const float * _pfHostFilter = NULL, + int _iFilterWidth = 0, float _fD = 1.0f, float _fFilterParameter = -1.0f); + + bool setShortScan(bool ss) { m_bShortScan = ss; return true; } + + virtual bool init(); + + virtual bool iterate(unsigned int iterations); + + virtual float computeDiffNorm() { return 0.0f; } // TODO + +protected: + void reset(); + + void* D_filter; // cufftComplex* + bool m_bShortScan; +}; + +} diff --git a/include/astra/cuda/2d/fbp_filters.h b/include/astra/cuda/2d/fbp_filters.h new file mode 100644 index 0000000..7c1121a --- /dev/null +++ b/include/astra/cuda/2d/fbp_filters.h @@ -0,0 +1,61 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef FBP_FILTERS_H +#define FBP_FILTERS_H + +namespace astra { + +enum E_FBPFILTER +{ + FILTER_NONE, //< no filter (regular BP) + FILTER_RAMLAK, //< default FBP filter + FILTER_SHEPPLOGAN, //< Shepp-Logan + FILTER_COSINE, //< Cosine + FILTER_HAMMING, //< Hamming filter + FILTER_HANN, //< Hann filter + FILTER_TUKEY, //< Tukey filter + FILTER_LANCZOS, //< Lanczos filter + FILTER_TRIANGULAR, //< Triangular filter + FILTER_GAUSSIAN, //< Gaussian filter + FILTER_BARTLETTHANN, //< Bartlett-Hann filter + FILTER_BLACKMAN, //< Blackman filter + FILTER_NUTTALL, //< Nuttall filter, continuous first derivative + FILTER_BLACKMANHARRIS, //< Blackman-Harris filter + FILTER_BLACKMANNUTTALL, //< Blackman-Nuttall filter + FILTER_FLATTOP, //< Flat top filter + FILTER_KAISER, //< Kaiser filter + FILTER_PARZEN, //< Parzen filter + FILTER_PROJECTION, //< all projection directions share one filter + FILTER_SINOGRAM, //< every projection direction has its own filter + FILTER_RPROJECTION, //< projection filter in real space (as opposed to fourier space) + FILTER_RSINOGRAM, //< sinogram filter in real space +}; + +} + +#endif /* FBP_FILTERS_H */ diff --git a/include/astra/cuda/2d/fft.h b/include/astra/cuda/2d/fft.h new file mode 100644 index 0000000..d36cae2 --- /dev/null +++ b/include/astra/cuda/2d/fft.h @@ -0,0 +1,72 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef FFT_H +#define FFT_H + +#include +#include + +#include "fbp_filters.h" + +namespace astraCUDA { + +bool allocateComplexOnDevice(int _iProjectionCount, + int _iDetectorCount, + cufftComplex ** _ppDevComplex); + +bool freeComplexOnDevice(cufftComplex * _pDevComplex); + +bool uploadComplexArrayToDevice(int _iProjectionCount, int _iDetectorCount, + cufftComplex * _pHostComplexSource, + cufftComplex * _pDevComplexTarget); + +bool runCudaFFT(int _iProjectionCount, const float * _pfDevRealSource, + int _iSourcePitch, int _iProjDets, + int _iFFTRealDetectorCount, int _iFFTFourierDetectorCount, + cufftComplex * _pDevTargetComplex); + +bool runCudaIFFT(int _iProjectionCount, const cufftComplex* _pDevSourceComplex, + float * _pfRealTarget, + int _iTargetPitch, int _iProjDets, + int _iFFTRealDetectorCount, int _iFFTFourierDetectorCount); + +void applyFilter(int _iProjectionCount, int _iFreqBinCount, + cufftComplex * _pSinogram, cufftComplex * _pFilter); + +int calcFFTFourierSize(int _iFFTRealSize); + +void genFilter(astra::E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, + cufftComplex * _pFilter, int _iFFTRealDetectorCount, + int _iFFTFourierDetectorCount, float _fParameter = -1.0f); + +void genIdenFilter(int _iProjectionCount, cufftComplex * _pFilter, + int _iFFTRealDetectorCount, int _iFFTFourierDetectorCount); + +} + +#endif /* FFT_H */ diff --git a/include/astra/cuda/2d/par_bp.h b/include/astra/cuda/2d/par_bp.h new file mode 100644 index 0000000..c8dfab8 --- /dev/null +++ b/include/astra/cuda/2d/par_bp.h @@ -0,0 +1,47 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_PAR_BP_H +#define _CUDA_PAR_BP_H + +#include "dims.h" + +namespace astraCUDA { + +_AstraExport bool BP(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + const SDimensions& dims, const SParProjection* angles, + float fOutputScale); + +_AstraExport bool BP_SART(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + unsigned int angle, const SDimensions& dims, + const SParProjection* angles, float fOutputScale); + +} + +#endif diff --git a/include/astra/cuda/2d/par_fp.h b/include/astra/cuda/2d/par_fp.h new file mode 100644 index 0000000..62277a1 --- /dev/null +++ b/include/astra/cuda/2d/par_fp.h @@ -0,0 +1,40 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_PAR_FP_H +#define _CUDA_PAR_FP_H + +namespace astraCUDA { + +_AstraExport bool FP(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + const SDimensions& dims, const SParProjection* angles, + float fOutputScale); + +} + +#endif diff --git a/include/astra/cuda/2d/sart.h b/include/astra/cuda/2d/sart.h new file mode 100644 index 0000000..6c0e547 --- /dev/null +++ b/include/astra/cuda/2d/sart.h @@ -0,0 +1,87 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_SART_H +#define _CUDA_SART_H + +#include "algo.h" + +namespace astraCUDA { + +class _AstraExport SART : public ReconAlgo { +public: + SART(); + ~SART(); + + // disable some features + virtual bool enableSinogramMask() { return false; } + + virtual bool init(); + + virtual bool setProjectionOrder(int* projectionOrder, int projectionCount); + + virtual bool iterate(unsigned int iterations); + + virtual float computeDiffNorm(); + + void setRelaxation(float r) { fRelaxation = r; } + +protected: + void reset(); + bool precomputeWeights(); + + bool callFP_SART(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + unsigned int angle, float outputScale); + bool callBP_SART(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + unsigned int angle, float outputScale); + + + // projection angle variables + bool customOrder; + int* projectionOrder; + int projectionCount; + int iteration; + + // Temporary buffers + float* D_projData; + unsigned int projPitch; + + float* D_tmpData; // Only used when there's a volume mask + unsigned int tmpPitch; + + // Geometry-specific precomputed data + float* D_lineWeight; + unsigned int linePitch; + + float fRelaxation; +}; + +} + +#endif diff --git a/include/astra/cuda/2d/sirt.h b/include/astra/cuda/2d/sirt.h new file mode 100644 index 0000000..434a07c --- /dev/null +++ b/include/astra/cuda/2d/sirt.h @@ -0,0 +1,96 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_SIRT_H +#define _CUDA_SIRT_H + +#include "algo.h" + +namespace astraCUDA { + +class _AstraExport SIRT : public ReconAlgo { +public: + SIRT(); + ~SIRT(); + + virtual bool init(); + + // Do optional long-object compensation. See the comments in sirt.cu. + // Call this after init(). It can not be used in combination with masks. + bool doSlabCorrections(); + + // Set min/max masks to existing GPU memory buffers + bool setMinMaxMasks(float* D_minMaskData, float* D_maxMaskData, + unsigned int pitch); + + // Set min/max masks from RAM buffers + bool uploadMinMaxMasks(const float* minMaskData, const float* maxMaskData, + unsigned int pitch); + + void setRelaxation(float r) { fRelaxation = r; } + + virtual bool iterate(unsigned int iterations); + + virtual float computeDiffNorm(); + +protected: + void reset(); + bool precomputeWeights(); + + // Temporary buffers + float* D_projData; + unsigned int projPitch; + + float* D_tmpData; + unsigned int tmpPitch; + + // Geometry-specific precomputed data + float* D_lineWeight; + unsigned int linePitch; + + float* D_pixelWeight; + unsigned int pixelPitch; + + // Masks + bool freeMinMaxMasks; + float* D_minMaskData; + unsigned int minMaskPitch; + float* D_maxMaskData; + unsigned int maxMaskPitch; + + float fRelaxation; +}; + +bool doSIRT(float* D_volumeData, unsigned int volumePitch, + float* D_projData, unsigned int projPitch, + float* D_maskData, unsigned int maskPitch, + const SDimensions& dims, const float* angles, + const float* TOffsets, unsigned int iterations); + +} + +#endif diff --git a/include/astra/cuda/2d/util.h b/include/astra/cuda/2d/util.h new file mode 100644 index 0000000..70e7c86 --- /dev/null +++ b/include/astra/cuda/2d/util.h @@ -0,0 +1,84 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +Website: http://www.astra-toolbox.com/ + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +*/ + +#ifndef _CUDA_UTIL_H +#define _CUDA_UTIL_H + +#include +#include +#include + +#include "astra/Globals.h" + +#include "dims.h" + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define ASTRA_CUDA_ASSERT(err) do { if (err != cudaSuccess) { astraCUDA::reportCudaError(err); assert(err == cudaSuccess); } } while(0) + + +namespace astraCUDA { + +bool copyVolumeToDevice(const float* in_data, unsigned int in_pitch, + const SDimensions& dims, + float* outD_data, unsigned int out_pitch); +bool copyVolumeFromDevice(float* out_data, unsigned int out_pitch, + const SDimensions& dims, + float* inD_data, unsigned int in_pitch); +bool copySinogramFromDevice(float* out_data, unsigned int out_pitch, + const SDimensions& dims, + float* inD_data, unsigned int in_pitch); +bool copySinogramToDevice(const float* in_data, unsigned int in_pitch, + const SDimensions& dims, + float* outD_data, unsigned int out_pitch); + +bool allocateVolume(float*& D_ptr, unsigned int width, unsigned int height, unsigned int& pitch); +void zeroVolume(float* D_data, unsigned int pitch, unsigned int width, unsigned int height); + +bool allocateVolumeData(float*& D_ptr, unsigned int& pitch, const SDimensions& dims); +bool allocateProjectionData(float*& D_ptr, unsigned int& pitch, const SDimensions& dims); +void zeroVolumeData(float* D_ptr, unsigned int pitch, const SDimensions& dims); +void zeroProjectionData(float* D_ptr, unsigned int pitch, const SDimensions& dims); + +void duplicateVolumeData(float* D_dst, float* D_src, unsigned int pitch, const SDimensions& dims); +void duplicateProjectionData(float* D_dst, float* D_src, unsigned int pitch, const SDimensions& dims); + + + +bool cudaTextForceKernelsCompletion(); +void reportCudaError(cudaError_t err); + + + +float dotProduct2D(float* D_data, unsigned int pitch, + unsigned int width, unsigned int height); + +} + +#endif -- cgit v1.2.3