libparallelproj_cuda

  1/**
  2 * @file parallelproj_cuda.h
  3 */
  4
  5#ifndef __PARALLELPROJ_CUDA_H__
  6#define __PARALLELPROJ_CUDA_H__
  7
  8#ifdef __cplusplus
  9extern "C"
 10{
 11#endif
 12
 13    /** @brief 3D non-tof joseph back projector CUDA wrapper
 14     *
 15     *  @param h_xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
 16     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
 17     *                  Units are the ones of voxsize.
 18     *  @param h_xend   array of shape [3*nlors] with the coordinates of the end   points of the LORs.
 19     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
 20     *                  Units are the ones of voxsize.
 21     *  @param d_img    Pointer to device arrays of shape [n0*n1*n2] containing the 3D image to
 22     *                  used to store the back projections.
 23     *                  The pixel [i,j,k] is stored at [n1*n2*i + n2*j + k].
 24     *                  The backprojector adds existing values.
 25     *  @param h_img_origin  array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
 26     *  @param h_voxsize     array [vs0, vs1, vs2] of the voxel sizes
 27     *  @param h_p           array of length nlors containg the values to be back projected
 28     *  @param nlors          number of projections (length of p array)
 29     *  @param h_img_dim      array with dimensions of image [n0,n1,n2]
 30     *  @param threadsperblock number of threads per block
 31     */
 32    void joseph3d_back_cuda(const float *h_xstart,
 33                            const float *h_xend,
 34                            float **d_img,
 35                            const float *h_img_origin,
 36                            const float *h_voxsize,
 37                            const float *h_p,
 38                            long long nlors,
 39                            const int *h_img_dim,
 40                            int threadsperblock);
 41
 42    /** @brief 3D listmode tof joseph back projector CUDA wrapper
 43     *
 44     *  @param h_xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
 45     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
 46     *                  Units are the ones of voxsize.
 47     *  @param h_xend   array of shape [3*nlors] with the coordinates of the end   points of the LORs.
 48     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
 49     *                  Units are the ones of voxsize.
 50     *  @param d_img    Pointer to device arrays of shape [n0*n1*n2] containing the 3D image to
 51     *                  used to store the back projections.
 52     *                  The pixel [i,j,k] is stored at [n1*n2*i + n2*j + k].
 53     *                  The backprojector adds existing values.
 54     *  @param h_img_origin  array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
 55     *  @param h_voxsize     array [vs0, vs1, vs2] of the voxel sizes
 56     *  @param h_p           array of length nlors containg the values to be back projected
 57     *  @param nlors         number of projections (length of p array)
 58     *  @param h_img_dim     array with dimensions of image [n0,n1,n2]
 59     *  @param tofbin_width     width of the TOF bins in spatial units (units of xstart and xend)
 60     *  @param h_sigma_tof      array of length 1 or nlors (depending on lor_dependent_sigma_tof)
 61     *                          with the TOF resolution (sigma) for each LOR in
 62     *                          spatial units (units of xstart and xend)
 63     *  @param h_tofcenter_offset array of length 1 or nlors (depending on lor_dependent_tofcenter_offset)
 64     *                            with the offset of the central TOF bin from the
 65     *                            midpoint of each LOR in spatial units (units of xstart and xend).
 66     *                            A positive value means a shift towards the end point of the LOR.
 67     *  @param n_sigmas        number of sigmas to consider for calculation of TOF kernel
 68     *  @param h_tof_bin       array containing the TOF bin of each event
 69     *  @param lor_dependent_sigma_tof unsigned char 0 or 1
 70     *                                 1 means that the TOF sigmas are LOR dependent
 71     *                                 any other value means that the first value in the sigma_tof
 72     *                                 array is used for all LORs
 73     *  @param lor_dependent_tofcenter_offset unsigned char 0 or 1
 74     *                                        1 means that the TOF center offsets are LOR dependent
 75     *                                        any other value means that the first value in the
 76     *                                        tofcenter_offset array is used for all LORs
 77     *  @param threadsperblock number of threads per block
 78     */
 79    void joseph3d_back_tof_lm_cuda(const float *h_xstart,
 80                                   const float *h_xend,
 81                                   float **d_img,
 82                                   const float *h_img_origin,
 83                                   const float *h_voxsize,
 84                                   const float *h_p,
 85                                   long long nlors,
 86                                   const int *h_img_dim,
 87                                   float tofbin_width,
 88                                   const float *h_sigma_tof,
 89                                   const float *h_tofcenter_offset,
 90                                   float n_sigmas,
 91                                   const short *h_tof_bin,
 92                                   unsigned char lor_dependent_sigma_tof,
 93                                   unsigned char lor_dependent_tofcenter_offset,
 94                                   int threadsperblock);
 95
 96    /** @brief 3D sinogram tof joseph back projector CUDA wrapper
 97     *
 98     *  @param h_xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
 99     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
100     *                  Units are the ones of voxsize.
101     *  @param h_xend   array of shape [3*nlors] with the coordinates of the end   points of the LORs.
102     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
103     *                  Units are the ones of voxsize.
104     *  @param d_img    Pointer to device arrays of shape [n0*n1*n2] containing the 3D image to
105     *                  used to store the back projections.
106     *                  The pixel [i,j,k] is stored at [n1*n2*i + n2*j + k].
107     *                  The backprojector adds existing values.
108     *  @param h_img_origin  array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
109     *  @param h_voxsize     array [vs0, vs1, vs2] of the voxel sizes
110     *  @param h_p           array of length nlors*n_tofbins with the values to be back projected
111     *                       the order of the array is
112     *                       [LOR0-TOFBIN-0, LOR0-TOFBIN-1, ... LOR0_TOFBIN-(n-1),
113     *                        LOR1-TOFBIN-0, LOR1-TOFBIN-1, ... LOR1_TOFBIN-(n-1),
114     *                        ...
115     *                        LOR(N-1)-TOFBIN-0, LOR(N-1)-TOFBIN-1, ... LOR(N-1)_TOFBIN-(n-1)]
116     *  @param nlors          number of gemeometrical projections
117     *  @param h_img_dim      array with dimensions of image [n0,n1,n2]
118     *  @param tofbin_width     width of the TOF bins in spatial units (units of xstart and xend)
119     *  @param h_sigma_tof      array of length 1 or nlors (depending on lor_dependent_sigma_tof)
120     *                          with the TOF resolution (sigma) for each LOR in
121     *                          spatial units (units of xstart and xend)
122     *  @param h_tofcenter_offset array of length 1 or nlors (depending on lor_dependent_tofcenter_offset)
123     *                            with the offset of the central TOF bin from the
124     *                            midpoint of each LOR in spatial units (units of xstart and xend).
125     *                            A positive value means a shift towards the end point of the LOR.
126     *  @param n_sigmas           number of sigmas to consider for calculation of TOF kernel
127     *  @param n_tofbins          number of TOF bins
128     *  @param lor_dependent_sigma_tof unsigned char 0 or 1
129     *                                 1 means that the TOF sigmas are LOR dependent
130     *                                 any other value means that the first value in the sigma_tof
131     *                                 array is used for all LORs
132     *  @param lor_dependent_tofcenter_offset unsigned char 0 or 1
133     *                                        1 means that the TOF center offsets are LOR dependent
134     *                                        any other value means that the first value in the
135     *                                        tofcenter_offset array is used for all LORs
136     *  @param threadsperblock number of threads per block
137     */
138    void joseph3d_back_tof_sino_cuda(const float *h_xstart,
139                                     const float *h_xend,
140                                     float **d_img,
141                                     const float *h_img_origin,
142                                     const float *h_voxsize,
143                                     const float *h_p,
144                                     long long nlors,
145                                     const int *h_img_dim,
146                                     float tofbin_width,
147                                     const float *h_sigma_tof,
148                                     const float *h_tofcenter_offset,
149                                     float n_sigmas,
150                                     short n_tofbins,
151                                     unsigned char lor_dependent_sigma_tof,
152                                     unsigned char lor_dependent_tofcenter_offset,
153                                     int threadsperblock);
154
155    /** @brief 3D non-tof joseph forward projector CUDA wrapper
156     *
157     *  @param h_xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
158     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
159     *                  Units are the ones of voxsize.
160     *  @param h_xend   array of shape [3*nlors] with the coordinates of the end   points of the LORs.
161     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
162     *                  Units are the ones of voxsize.
163     *  @param d_img    Pointer to device arrays of shape [n0*n1*n2] containing the 3D image to
164     *                  be projected.
165     *                  The pixel [i,j,k] ist stored at [n1*n2*i + n2*j + k].
166     *  @param h_img_origin  array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
167     *  @param h_voxsize     array [vs0, vs1, vs2] of the voxel sizes
168     *  @param h_p           array of length nlors (output) used to store the projections
169     *  @param nlors           number of projections (length of p array)
170     *  @param h_img_dim       array with dimensions of image [n0,n1,n2]
171     *  @param threadsperblock number of threads per block
172     */
173    void joseph3d_fwd_cuda(const float *h_xstart,
174                           const float *h_xend,
175                           float **d_img,
176                           const float *h_img_origin,
177                           const float *h_voxsize,
178                           float *h_p,
179                           long long nlors,
180                           const int *h_img_dim,
181                           int threadsperblock);
182
183    /** @brief 3D listmode tof joseph forward projector CUDA wrapper
184     *
185     *  @param h_xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
186     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
187     *                  Units are the ones of voxsize.
188     *  @param h_xend   array of shape [3*nlors] with the coordinates of the end   points of the LORs.
189     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
190     *                  Units are the ones of voxsize.
191     *  @param d_img    Pointer to device arrays of shape [n0*n1*n2] containing the 3D image to
192     *                  used to store the back projections.
193     *                  The pixel [i,j,k] is stored at [n1*n2*i + n2*j + k].
194     *  @param h_img_origin  array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
195     *  @param h_voxsize     array [vs0, vs1, vs2] of the voxel sizes
196     *  @param h_p           array of length nlors (output) used to store the projections
197     *  @param nlors         number of projections (length of p array)
198     *  @param h_img_dim     array with dimensions of image [n0,n1,n2]
199     *  @param tofbin_width  width of the TOF bins in spatial units (units of xstart and xend)
200     *  @param h_sigma_tof   array of length 1 or nlors (depending on lor_dependent_sigma_tof)
201     *                       with the TOF resolution (sigma) for each LOR in
202     *                       spatial units (units of xstart and xend)
203     *  @param h_tofcenter_offset array of length 1 or nlors (depending on lor_dependent_tofcenter_offset)
204     *                            with the offset of the central TOF bin from the
205     *                            midpoint of each LOR in spatial units (units of xstart and xend).
206     *                            A positive value means a shift towards the end point of the LOR.
207     *  @param n_sigmas           number of sigmas to consider for calculation of TOF kernel
208     *  @param h_tof_bin          array of length nlors with the tofbin of every event
209     *  @param lor_dependent_sigma_tof unsigned char 0 or 1
210     *                                 1 means that the TOF sigmas are LOR dependent
211     *                                 any other value means that the first value in the sigma_tof
212     *                                 array is used for all LORs
213     *  @param lor_dependent_tofcenter_offset unsigned char 0 or 1
214     *                                        1 means that the TOF center offsets are LOR dependent
215     *                                        any other value means that the first value in the
216     *                                        tofcenter_offset array is used for all LORs
217     *  @param threadsperblock    number of threads per block
218     */
219    void joseph3d_fwd_tof_lm_cuda(const float *h_xstart,
220                                  const float *h_xend,
221                                  float **d_img,
222                                  const float *h_img_origin,
223                                  const float *h_voxsize,
224                                  float *h_p,
225                                  long long nlors,
226                                  const int *h_img_dim,
227                                  float tofbin_width,
228                                  const float *h_sigma_tof,
229                                  const float *h_tofcenter_offset,
230                                  float n_sigmas,
231                                  const short *h_tof_bin,
232                                  unsigned char lor_dependent_sigma_tof,
233                                  unsigned char lor_dependent_tofcenter_offset,
234                                  int threadsperblock);
235
236    /** @brief 3D sinogram tof joseph forward projector CUDA wrapper
237     *
238     *  @param h_xstart array of shape [3*nlors] with the coordinates of the start points of the LORs.
239     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
240     *                  Units are the ones of voxsize.
241     *  @param h_xend   array of shape [3*nlors] with the coordinates of the end   points of the LORs.
242     *                  The start coordinates of the n-th LOR are at xstart[n*3 + i] with i = 0,1,2.
243     *                  Units are the ones of voxsize.
244     *  @param d_img    Pointer to device arrays of shape [n0*n1*n2] containing the 3D image to
245     *                  used to store the back projections.
246     *                  The pixel [i,j,k] is stored at [n1*n2*i + n2*j + k].
247     *  @param h_img_origin  array [x0_0,x0_1,x0_2] of coordinates of the center of the [0,0,0] voxel
248     *  @param h_voxsize     array [vs0, vs1, vs2] of the voxel sizes
249     *  @param h_p           array of length nlors*n_tofbins (output) used to store the projections
250     *                       the order of the array is
251     *                       [LOR0-TOFBIN-0, LOR0-TOFBIN-1, ... LOR0_TOFBIN-(n-1),
252     *                        LOR1-TOFBIN-0, LOR1-TOFBIN-1, ... LOR1_TOFBIN-(n-1),
253     *                        ...
254     *                        LOR(N-1)-TOFBIN-0, LOR(N-1)-TOFBIN-1, ... LOR(N-1)_TOFBIN-(n-1)]
255     *  @param nlors         number of geometrical LORs
256     *  @param h_img_dim     array with dimensions of image [n0,n1,n2]
257     *  @param tofbin_width  width of the TOF bins in spatial units (units of xstart and xend)
258     *  @param h_sigma_tof   array of length 1 or nlors (depending on lor_dependent_sigma_tof)
259     *                       with the TOF resolution (sigma) for each LOR in
260     *                       spatial units (units of xstart and xend)
261     *  @param h_tofcenter_offset array of length 1 or nlors (depending on lor_dependent_tofcenter_offset)
262     *                            with the offset of the central TOF bin from the
263     *                            midpoint of each LOR in spatial units (units of xstart and xend).
264     *                            A positive value means a shift towards the end point of the LOR.
265     *  @param n_sigmas           number of sigmas to consider for calculation of TOF kernel
266     *  @param n_tofbins          number of TOF bins
267     *  @param lor_dependent_sigma_tof unsigned char 0 or 1
268     *                                 1 means that the TOF sigmas are LOR dependent
269     *                                 any other value means that the first value in the sigma_tof
270     *                                 array is used for all LORs
271     *  @param lor_dependent_tofcenter_offset unsigned char 0 or 1
272     *                                        1 means that the TOF center offsets are LOR dependent
273     *                                        any other value means that the first value in the
274     *                                        tofcenter_offset array is used for all LORs
275     *  @param threadsperblock    number of threads per block
276     */
277    void joseph3d_fwd_tof_sino_cuda(const float *h_xstart,
278                                    const float *h_xend,
279                                    float **d_img,
280                                    const float *h_img_origin,
281                                    const float *h_voxsize,
282                                    float *h_p,
283                                    long long nlors,
284                                    const int *h_img_dim,
285                                    float tofbin_width,
286                                    const float *h_sigma_tof,
287                                    const float *h_tofcenter_offset,
288                                    float n_sigmas,
289                                    short n_tofbins,
290                                    unsigned char lor_dependent_sigma_tof,
291                                    unsigned char lor_dependent_tofcenter_offset,
292                                    int threadsperblock);
293
294    /** @brief copy a float array to all visible cuda devices
295     *
296     *  The number of visible cuda devices is determined automatically via the CUDA API
297     *
298     *  @param    h_array   array of shape [n] on the host
299     *  @param    n         number of array elements
300     *  @return   a pointer to all devices arrays
301     */
302    float **copy_float_array_to_all_devices(const float *h_array, long long n);
303
304    /** @brief free device array on all visible cuda devices
305     *
306     *  The number of visible cuda devices is determined automatically via the CUDA API
307     *
308     *  @param d_array a pointer to all devices arrays
309     */
310    void free_float_array_on_all_devices(float **d_array);
311
312    /** @brief sum multiple versions of an array on different devices on first device
313     *
314     *  The number of visible cuda devices is determined automatically via the CUDA API
315     *  This becomes usefule when multiple devices backproject into separate images.
316     *
317     *  @param d_array a pointer to all devices arrays
318     *  @param    n         number of array elements
319     */
320    void sum_float_arrays_on_first_device(float **d_array, long long n);
321
322    /** @brief copy a (summed) float array from first device back to host
323     *
324     *  The number of visible cuda devices is determined automatically via the CUDA API
325     *
326     *  @param  d_array   a pointer to all devices arrays of shape [n]
327     *  @param  n         number of array elements
328     *  @param  i_dev     device number
329     *  @param  h_array   array of shape [n] on the host used for output
330     */
331    void get_float_array_from_device(float **d_array, long long n, int i_dev, float *h_array);
332
333    /** @brief get the number of visible cuda devices
334     */
335    int get_cuda_device_count();
336
337#ifdef __cplusplus
338} /* extern "C" */
339#endif
340
341#endif