19 #ifndef OPM_CUISTL_SAFE_CONVERSION_HPP 20 #define OPM_CUISTL_SAFE_CONVERSION_HPP 22 #include <opm/common/ErrorMacros.hpp> 26 #include <type_traits> 27 #include <cuda_runtime.h> 29 #if CUDA_VERSION >= 12100 30 #include <fmt/format.h> 59 std::is_signed_v<int>,
60 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
62 !std::is_signed_v<std::size_t>,
63 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
66 sizeof(
int) <=
sizeof(std::size_t),
67 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
70 if (s > std::size_t(std::numeric_limits<int>::max())) {
71 #if CUDA_VERSION >= 12100 72 OPM_THROW(std::invalid_argument,
73 fmt::format(fmt::runtime(
"Trying to convert {} to int, but it is out of range. Maximum possible int: {}. "),
75 std::numeric_limits<int>::max()));
77 std::stringstream str;
78 str <<
"Trying to convert " << s <<
" to int, but it is out of range. Maximum possible int: " 79 << std::numeric_limits<int>::max() <<
" .";
80 OPM_THROW(std::invalid_argument, str.str());
96 __host__ __device__
inline std::size_t
100 std::is_signed_v<int>,
101 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
103 !std::is_signed_v<std::size_t>,
104 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
107 sizeof(
int) <=
sizeof(std::size_t),
108 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
110 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) 114 #if CUDA_VERSION >= 12100 115 OPM_THROW(std::invalid_argument, fmt::format(fmt::runtime(
"Trying to convert the negative number {} to size_t."), i));
117 std::stringstream str;
118 str <<
"Trying to convert the negative number " << i <<
" to size_t.";
119 OPM_THROW(std::invalid_argument, str.str());
124 return std::size_t(i);
int to_int(std::size_t s)
to_int converts a (on most relevant platforms) 64 bits unsigned size_t to a signed 32 bits signed int...
Definition: safe_conversion.hpp:56
__host__ __device__ std::size_t to_size_t(int i)
to_size_t converts a (on most relevant platforms) a 32 bit signed int to a 64 bits unsigned int ...
Definition: safe_conversion.hpp:97
Contains wrappers to make the CuBLAS library behave as a modern C++ library with function overlading...
Definition: autotuner.hpp:29