-
Notifications
You must be signed in to change notification settings - Fork 1
/
hamr_hip_print_impl.h
64 lines (55 loc) · 1.57 KB
/
hamr_hip_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
57
58
59
60
61
62
63
64
#ifndef hamr_hip_print_impl_h
#define hamr_hip_print_impl_h
#include "hamr_config.h"
#include "hamr_env.h"
#if defined(HAMR_ENABLE_HIP)
#include "hamr_hip_kernels.h"
#include "hamr_hip_launch.h"
#include <hip/hip_runtime.h>
#endif
#include <iostream>
/// heterogeneous accelerator memory resource
namespace hamr
{
/** prints an array on the GPU
* @param[in] vals an array of n elements accessible in HIP
* @param[in] n_elem the length of the array
* @returns 0 if there were no errors
*/
template <typename T>
int hip_print(T *vals, size_t n_elem)
{
#if !defined(HAMR_ENABLE_HIP)
(void) vals;
(void) n_elem;
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] ERROR:"
" print_hip failed because HIP is not enabled." << std::endl;
return -1;
#else
// get launch parameters
int device_id = -1;
dim3 block_grid;
int n_blocks = 0;
dim3 thread_grid = 0;
if (hamr::partition_thread_blocks(device_id, n_elem, 8, block_grid,
n_blocks, thread_grid))
{
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] ERROR:"
" Failed to determine launch properties." << std::endl;
return -1;
}
// invoke the print kernel
hipError_t ierr = hipSuccess;
hamr::hip_kernels::print<<<block_grid, thread_grid>>>(vals, n_elem);
if ((ierr = hipGetLastError()) != hipSuccess)
{
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] ERROR:"
" Failed to launch the print kernel. "
<< hipGetErrorString(ierr) << std::endl;
return -1;
}
return 0;
#endif
}
}
#endif