10 #ifndef __stir_cuda_utilities_H__ 11 #define __stir_cuda_utilities_H__ 26 template <
int num_dimensions,
typename elemT>
28 array_to_device(elemT* dev_data,
const Array<num_dimensions, elemT>& stir_array)
30 if (stir_array.is_contiguous())
32 info(
"array_to_device contiguous", 100);
33 cudaMemcpy(dev_data, stir_array.get_const_full_data_ptr(), stir_array.size_all() *
sizeof(elemT), cudaMemcpyHostToDevice);
34 stir_array.release_const_full_data_ptr();
38 info(
"array_to_device non-contiguous", 100);
40 std::vector<elemT> tmp_data(stir_array.size_all());
41 std::copy(stir_array.begin_all(), stir_array.end_all(), tmp_data.begin());
42 cudaMemcpy(dev_data, tmp_data.data(), stir_array.size_all() *
sizeof(elemT), cudaMemcpyHostToDevice);
46 template <
int num_dimensions,
typename elemT>
48 array_to_host(Array<num_dimensions, elemT>& stir_array,
const elemT* dev_data)
50 if (stir_array.is_contiguous())
52 info(
"array_to_host contiguous", 100);
53 cudaMemcpy(stir_array.get_full_data_ptr(), dev_data, stir_array.size_all() *
sizeof(elemT), cudaMemcpyDeviceToHost);
54 stir_array.release_full_data_ptr();
58 info(
"array_to_host non-contiguous", 100);
60 std::vector<elemT> tmp_data(stir_array.size_all());
61 cudaMemcpy(tmp_data.data(), dev_data, stir_array.size_all() *
sizeof(elemT), cudaMemcpyDeviceToHost);
63 std::copy(tmp_data.begin(), tmp_data.end(), stir_array.begin_all());
void info(const STRING &string, const int verbosity_level=1)
Use this function for writing informational messages.
Definition: info.h:51
defines the Array class for multi-dimensional (numeric) arrays
Declaration of stir::info()