3131#include " stir/IO/stir_ecat_common.h"
3232#include " stir/error.h"
3333#include " stir/format.h"
34+ #include " stir/cuda_utilities.h"
3435// Non-STIR includes
3536#include < fstream>
3637#include < math.h>
3738#include " driver_types.h"
3839// SPECTGPU includes
39- #include " def.h"
40- #include " auxmath.h"
41- #include " prjb.h"
42- #include " prjf.h"
43- #include " recon.h"
44- #include " lmproc.h"
45- #include " scanner_0.h"
46- #include " rnd.h"
47- #include " norm.h"
4840
4941START_NAMESPACE_STIR
5042
5143SPECTGPUHelper::~SPECTGPUHelper ()
5244{}
5345
54- // static void
55- // delete_axialLUT(axialLUT* axlut_ptr)
56- // {
57- // if (!axlut_ptr)
58- // return;
59- // delete[] axlut_ptr->li2rno;
60- // delete[] axlut_ptr->li2sn;
61- // delete[] axlut_ptr->li2nos;
62- // delete[] axlut_ptr->sn1_rno;
63- // delete[] axlut_ptr->sn1_sn11;
64- // delete[] axlut_ptr->sn1_ssrb;
65- // delete[] axlut_ptr->sn1_sn11no;
66- // }
67-
68- static shared_ptr<Cnst>
69- get_cnst (const Scanner& scanner, const bool cuda_verbose, const char cuda_device)
70- {
71- shared_ptr<Cnst> cnt_sptr = MAKE_SHARED<Cnst>();
7246
73- cnt_sptr->DEVID = cuda_device; // device (GPU) ID. allows choosing the device on which to perform calculations
74- cnt_sptr->VERBOSE = cuda_verbose;
47+ // static shared_ptr<Cnst>
48+ // get_cnst(const Scanner& scanner, const bool cuda_verbose, const char cuda_device)
49+ // {
50+ // shared_ptr<Cnst> cnt_sptr = MAKE_SHARED<Cnst>();
51+
52+ // cnt_sptr->DEVID = cuda_device; // device (GPU) ID. allows choosing the device on which to perform calculations
53+ // cnt_sptr->VERBOSE = cuda_verbose;
7554
76- cnt_sptr->A = NSANGLES; // sino angles
77- cnt_sptr->W = NSBINS; // sino bins for any angular index
78- cnt_sptr->aw = AW; // sino bins (active only)
55+ // cnt_sptr->A = NSANGLES; // sino angles
56+ // cnt_sptr->W = NSBINS; // sino bins for any angular index
57+ // cnt_sptr->aw = AW; // sino bins (active only)
7958
80- cnt_sptr->NCRS = nCRS; // number of crystals
81- cnt_sptr->NRNG = NRINGS; // number of axial positions
82- cnt_sptr->D = -1 ; // number of linear indexes along Michelogram diagonals /*unknown*/
83- cnt_sptr->Bt = -1 ; // number of buckets transaxially /*unknown*/
59+ // cnt_sptr->NCRS = nCRS; // number of crystals
60+ // cnt_sptr->NRNG = NRINGS; // number of axial positions
61+ // cnt_sptr->D = -1; // number of linear indexes along Michelogram diagonals /*unknown*/
62+ // cnt_sptr->Bt = -1; // number of buckets transaxially /*unknown*/
8463
85- cnt_sptr->B = NBUCKTS; // number of buckets (total)
86- cnt_sptr->Cbt = 32552 ; // number of crystals in bucket transaxially /*unknown*/
87- cnt_sptr->Cba = 3 ; // number of crystals in bucket axially /*unknown*/
64+ // cnt_sptr->B = NBUCKTS; // number of buckets (total)
65+ // cnt_sptr->Cbt = 32552; // number of crystals in bucket transaxially /*unknown*/
66+ // cnt_sptr->Cba = 3; // number of crystals in bucket axially /*unknown*/
8867
89- cnt_sptr->NSN1 = NSINOS; // number of sinos
90- cnt_sptr->NSN64 = NRINGS * NRINGS; // with no MRD limit
91- cnt_sptr->NSEG0 = SEG0;
68+ // cnt_sptr->NSN1 = NSINOS; // number of sinos
69+ // cnt_sptr->NSN64 = NRINGS * NRINGS; // with no MRD limit
70+ // cnt_sptr->NSEG0 = SEG0;
9271
93- cnt_sptr->RNG_STRT = 0 ;
94- cnt_sptr->RNG_END = NRINGS;
72+ // cnt_sptr->RNG_STRT = 0;
73+ // cnt_sptr->RNG_END = NRINGS;
9574
96- cnt_sptr->ALPHA = aLPHA; // angle subtended by a crystal
97- float R = 32 .8f ; // ring radius
98- cnt_sptr->RE = R + 0 .67f ; // effective ring radius accounting for the depth of interaction
99- cnt_sptr->AXR = SZ_RING; // axial crystal dim
75+ // cnt_sptr->ALPHA = aLPHA; // angle subtended by a crystal
76+ // float R = 32.8f; // ring radius
77+ // cnt_sptr->RE = R + 0.67f; // effective ring radius accounting for the depth of interaction
78+ // cnt_sptr->AXR = SZ_RING; // axial crystal dim
10079
101- float CLGHT = 29979245800 .f ; // speed of light [cm/s]
102- return cnt_sptr;
103- }
80+ // float CLGHT = 29979245800.f; // speed of light [cm/s]
81+ // return cnt_sptr;
82+ // }
10483
105- static inline unsigned
106- to_1d_idx (const unsigned nrow, const unsigned ncol, const unsigned row, const unsigned col)
107- {
108- return col + ncol * row;
109- }
11084
111- template <class dataType >
112- dataType*
113- create_heap_array (const unsigned numel, const dataType val = dataType(0 ))
114- {
115- dataType* array = new dataType[numel];
116- std::fill (array, array + numel, val);
117- return array;
118- }
11985
12086void
12187SPECTGPUHelper::set_up ()
@@ -124,14 +90,14 @@ SPECTGPUHelper::set_up()
12490 throw std::runtime_error (" SPECTGPUHelper::set_up() "
12591 " emission or transmission mode (att) not set." );
12692
127- // Get consts
128- _cnt_sptr = get_cnst (_scanner_type, _verbose, _devid);
93+ // // Get consts
94+ // _cnt_sptr = get_cnst(_scanner_type, _verbose, _devid);
12995
13096
131- // isub
132- _isub = std::vector<int >(unsigned (AW));
133- for (unsigned i = 0 ; i < unsigned (AW); i++)
134- _isub[i] = int (i);
97+ // // isub
98+ // _isub = std::vector<int>(unsigned(AW));
99+ // for (unsigned i = 0; i < unsigned(AW); i++)
100+ // _isub[i] = int(i);
135101
136102 _already_set_up = true ;
137103}
@@ -196,53 +162,6 @@ SPECTGPUHelper::convert_SPECTGPU_proj_3d_to_1d_idx(const unsigned ang, const uns
196162}
197163
198164void
199- SPECTGPUHelper::permute (std::vector<float >& output_array,
200- const std::vector<float >& orig_array,
201- const unsigned output_dims[3 ],
202- const unsigned permute_order[3 ]) const
203- {
204- #ifndef NDEBUG
205- // Check that in the permute order, each number is between 0 and 2 (can't be <0 because it's unsigned)
206- for (unsigned i = 0 ; i < 3 ; ++i)
207- if (permute_order[i] > 2 )
208- throw std::runtime_error (" Permute order values should be between 0 and 2." );
209- // Check that each number is unique
210- for (unsigned i = 0 ; i < 3 ; ++i)
211- for (unsigned j = i + 1 ; j < 3 ; ++j)
212- if (permute_order[i] == permute_order[j])
213- throw std::runtime_error (" Permute order values should be unique." );
214- // Check that size of output_dims==arr.size()
215- assert (orig_array.size () == output_dims[0 ] * output_dims[1 ] * output_dims[2 ]);
216- // Check that output array is same size as input array
217- assert (orig_array.size () == output_array.size ());
218- #endif
219-
220- // Calculate old dimensions
221- unsigned old_dims[3 ];
222- for (unsigned i = 0 ; i < 3 ; ++i)
223- old_dims[permute_order[i]] = output_dims[i];
224-
225- // Loop over all elements
226- for (unsigned old_1d_idx = 0 ; old_1d_idx < orig_array.size (); ++old_1d_idx)
227- {
228-
229- // From the 1d index, generate the old 3d index
230- unsigned old_3d_idx[3 ]
231- = { old_1d_idx / (old_dims[2 ] * old_dims[1 ]), (old_1d_idx / old_dims[2 ]) % old_dims[1 ], old_1d_idx % old_dims[2 ] };
232-
233- // Get the corresponding new 3d index
234- unsigned new_3d_idx[3 ];
235- for (unsigned i = 0 ; i < 3 ; ++i)
236- new_3d_idx[i] = old_3d_idx[permute_order[i]];
237-
238- // Get the new 1d index from the new 3d index
239- const unsigned new_1d_idx
240- = new_3d_idx[0 ] * output_dims[2 ] * output_dims[1 ] + new_3d_idx[1 ] * output_dims[2 ] + new_3d_idx[2 ];
241-
242- // Fill the data
243- output_array[new_1d_idx] = orig_array[old_1d_idx];
244- }
245- }
246165
247166void
248167SPECTGPUHelper::back_project (std::vector<float >& image, const std::vector<float >& sino_no_gaps) const
@@ -262,11 +181,13 @@ SPECTGPUHelper::back_project(std::vector<float>& image, const std::vector<float>
262181}
263182
264183void
265- SPECTGPUHelper::forward_project (std::vector< float >& sino, const std::vector< float >& image) const
184+ SPECTGPUHelper::forward_project (Array< 3 , elemT >& sino, const Array< 3 , elemT >& image) const
266185{
267186 check_set_up ();
268187 assert (!sino.empty ());
269-
188+ // prjdatainmemory
189+ cudaMalloc (&this ->cuda_image , stir_image_sptr->size_all () * sizeof (elemT));
190+ array_to_device (this ->cuda_image , *stir_image_sptr);
270191 // Permute the data (as this is done on the SPECTGPU python side before forward projection
271192 // unsigned output_dims[3] = { 320, 320, 127 };
272193 // unsigned permute_order[3] = { 1, 2, 0 };
0 commit comments