-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhamr_openmp_print_impl.h
56 lines (48 loc) · 1.26 KB
/
hamr_openmp_print_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef hamr_openmp_print_h
#define hamr_openmp_print_h
#include "hamr_config.h"
#include "hamr_env.h"
#if defined(HAMR_ENABLE_OPENMP)
#include "hamr_openmp_copy.h"
#include "hamr_malloc_allocator.h"
#endif
#include <iostream>
/// heterogeneous accelerator memory resource
namespace hamr
{
// ---------------------------------------------------------------------------
template <typename T>
int openmp_print(T *vals, size_t n_elem)
{
#if !defined(HAMR_ENABLE_OPENMP)
(void) vals;
(void) n_elem;
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] ERROR:"
" print_openmp failed because OpenMP is not enabled." << std::endl;
return -1;
#else
// allocate a temporary on the host
auto sptmp = hamr::malloc_allocator<T>::allocate(n_elem);
T *ptmp = sptmp.get();
// move to the host
if (hamr::copy_to_host_from_openmp(ptmp, vals, n_elem))
{
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] ERROR:"
" failed to move data to the host" << std::endl;
return -1;
}
// print
if (n_elem)
{
std::cerr << ptmp[0];
for (size_t i = 1; i < n_elem; ++i)
{
std::cerr << ", " << ptmp[i];
}
}
std::cerr << std::endl;
return 0;
#endif
}
}
#endif