RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
raja_cudaerrchk.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_cudaerrchk_HPP
23 #define RAJA_cudaerrchk_HPP
24 
25 #include "RAJA/config.hpp"
26 
27 #if defined(RAJA_ENABLE_CUDA)
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 <cuda.h>
40 #include <cuda_runtime.h>
41 
42 #include "camp/defines.hpp"
43 #include "camp/helpers.hpp"
44 
45 #include "RAJA/util/macros.hpp"
46 
47 #include "cub/util_type.cuh"
48 
49 namespace camp
50 {
51 
52 namespace experimental
53 {
54 
55 template<>
56 struct StreamInsertHelper<RAJA_CUDA_DIM_T&>
57 {
58  RAJA_CUDA_DIM_T& m_val;
59 
60  std::ostream& operator()(std::ostream& str) const
61  {
62  return str << "{" << m_val.x << "," << m_val.y << "," << m_val.z << "}";
63  }
64 };
65 
67 template<>
68 struct StreamInsertHelper<RAJA_CUDA_DIM_T const&>
69 {
70  RAJA_CUDA_DIM_T const& m_val;
71 
72  std::ostream& operator()(std::ostream& str) const
73  {
74  return str << "{" << m_val.x << "," << m_val.y << "," << m_val.z << "}";
75  }
76 };
77 
78 template<typename R>
79 struct StreamInsertHelper<::cub::DoubleBuffer<R>&>
80 {
81  ::cub::DoubleBuffer<R>& m_val;
82 
83  std::ostream& operator()(std::ostream& str) const
84  {
85  return str << "{" << m_val.Current() << "," << m_val.Alternate() << "}";
86  }
87 };
88 
90 template<typename R>
91 struct StreamInsertHelper<::cub::DoubleBuffer<R> const&>
92 {
93  ::cub::DoubleBuffer<R> const& m_val;
94 
95  std::ostream& operator()(std::ostream& str) const
96  {
97  // Can't get current and alternate as they are non-const functions
98  return str << "{?,?}";
99  }
100 };
101 
102 } // namespace experimental
103 
104 } // namespace camp
105 
106 namespace RAJA
107 {
108 
118 #define cudaErrchk(ans) \
119  { \
120  ::RAJA::cudaAssert((ans), __FILE__, __LINE__); \
121  }
122 
123 [[deprecated]] inline void cudaAssert(cudaError_t code,
124  const char* file,
125  int line,
126  bool abort = true)
127 {
128  if (code != cudaSuccess)
129  {
130  if (abort)
131  {
132  std::string msg;
133  msg += "CUDAassert: ";
134  msg += cudaGetErrorString(code);
135  msg += " ";
136  msg += file;
137  msg += ":";
138  msg += std::to_string(line);
139  throw std::runtime_error(msg);
140  }
141  else
142  {
143  fprintf(stderr, "CUDAassert: %s %s %d\n", cudaGetErrorString(code), file,
144  line);
145  }
146  }
147 }
148 
149 } // namespace RAJA
150 
151 #endif // closing endif for if defined(RAJA_ENABLE_CUDA)
152 
153 #endif // closing endif for header file include guard
Header file for common RAJA internal macro definitions.
Definition: AlignedRangeIndexSetBuilders.cpp:35