RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
raja_hiperrchk.hpp
Go to the documentation of this file.
1 
13 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
14 // Copyright (c) Lawrence Livermore National Security, LLC and other
15 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
16 // files for dates and other details. No copyright assignment is required
17 // to contribute to RAJA.
18 //
19 // SPDX-License-Identifier: (BSD-3-Clause)
20 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
21 
22 #ifndef RAJA_hiperrchk_HPP
23 #define RAJA_hiperrchk_HPP
24 
25 #include "RAJA/config.hpp"
26 
27 #if defined(RAJA_ENABLE_HIP)
28 
29 #include <iostream>
30 #include <utility>
31 #include <algorithm>
32 #include <tuple>
33 #include <array>
34 #include <string_view>
35 #include <string>
36 #include <sstream>
37 #include <stdexcept>
38 
39 #include <hip/hip_runtime.h>
40 
41 #include "camp/defines.hpp"
42 #include "camp/helpers.hpp"
43 
44 #include "RAJA/util/macros.hpp"
45 
46 #if defined(__HIPCC__)
47 // Tell rocprim to provide its HIP API
48 #define ROCPRIM_HIP_API 1
49 #include "rocprim/types.hpp"
50 #endif
51 
52 namespace camp
53 {
54 
55 namespace experimental
56 {
57 
58 template<>
59 struct StreamInsertHelper<RAJA_HIP_DIM_T&>
60 {
61  RAJA_HIP_DIM_T& m_val;
62 
63  std::ostream& operator()(std::ostream& str) const
64  {
65  return str << "{" << m_val.x << "," << m_val.y << "," << m_val.z << "}";
66  }
67 };
68 
70 template<>
71 struct StreamInsertHelper<RAJA_HIP_DIM_T const&>
72 {
73  RAJA_HIP_DIM_T const& m_val;
74 
75  std::ostream& operator()(std::ostream& str) const
76  {
77  return str << "{" << m_val.x << "," << m_val.y << "," << m_val.z << "}";
78  }
79 };
80 
81 #if defined(__HIPCC__)
82 template<typename R>
83 struct StreamInsertHelper<::rocprim::double_buffer<R>&>
84 {
85  ::rocprim::double_buffer<R>& m_val;
86 
87  std::ostream& operator()(std::ostream& str) const
88  {
89  return str << "{" << m_val.current() << "," << m_val.alternate() << "}";
90  }
91 };
92 
94 template<typename R>
95 struct StreamInsertHelper<::rocprim::double_buffer<R> const&>
96 {
97  ::rocprim::double_buffer<R> const& m_val;
98 
99  std::ostream& operator()(std::ostream& str) const
100  {
101  return str << "{" << m_val.current() << "," << m_val.alternate() << "}";
102  }
103 };
104 #endif
105 
106 } // namespace experimental
107 
108 } // namespace camp
109 
110 namespace RAJA
111 {
112 
122 #define hipErrchk(ans) \
123  { \
124  ::RAJA::hipAssert((ans), __FILE__, __LINE__); \
125  }
126 
127 [[deprecated]] inline void hipAssert(hipError_t code,
128  const char* file,
129  int line,
130  bool abort = true)
131 {
132  if (code != hipSuccess)
133  {
134  if (abort)
135  {
136  std::string msg;
137  msg += "HIPassert: ";
138  msg += hipGetErrorString(code);
139  msg += " ";
140  msg += file;
141  msg += ":";
142  msg += std::to_string(line);
143  throw std::runtime_error(msg);
144  }
145  else
146  {
147  fprintf(stderr, "HIPassert: %s %s %d\n", hipGetErrorString(code), file,
148  line);
149  }
150  }
151 }
152 
153 } // namespace RAJA
154 
155 #endif // closing endif for if defined(RAJA_ENABLE_HIP)
156 
157 #endif // closing endif for header file include guard
Header file for common RAJA internal macro definitions.
Definition: AlignedRangeIndexSetBuilders.cpp:35