opm-simulators
Toggle main menu visibility
Loading...
Searching...
No Matches
gpu_safe_call.hpp
1
/*
2
Copyright 2022-2023 SINTEF AS
3
4
This file is part of the Open Porous Media project (OPM).
5
6
OPM is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
OPM is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
#ifndef OPM_GPU_SAFE_CALL_HPP
20
#define OPM_GPU_SAFE_CALL_HPP
21
#include <cuda_runtime.h>
22
#include <fmt/core.h>
23
#include <opm/common/ErrorMacros.hpp>
24
#include <opm/common/OpmLog/OpmLog.hpp>
25
#include <string_view>
26
27
namespace
Opm::gpuistl::detail
28
{
44
inline
std::string
45
getCudaErrorMessage
(cudaError_t error,
46
const
std::string_view& expression,
47
const
std::string_view& filename,
48
const
std::string_view& functionName,
49
size_t
lineNumber)
50
{
51
return
fmt::format(
"GPU expression did not execute correctly. Expression was: \n"
52
" {}\n"
53
"GPU error was {}\n"
54
"in function {}, in {}, at line {}\n"
,
55
expression,
56
cudaGetErrorString(error),
57
functionName,
58
filename,
59
lineNumber);
60
}
61
81
inline
void
82
cudaSafeCall
(cudaError_t error,
83
const
std::string_view& expression,
84
const
std::string_view& filename,
85
const
std::string_view& functionName,
86
size_t
lineNumber)
87
{
88
if
(error != cudaSuccess) {
89
OPM_THROW(std::runtime_error,
getCudaErrorMessage
(error, expression, filename, functionName, lineNumber));
90
}
91
}
92
120
inline
void
121
cudaWarnIfError
(cudaError_t error,
122
const
std::string_view& expression,
123
const
std::string_view& filename,
124
const
std::string_view& functionName,
125
size_t
lineNumber)
126
{
127
if
(error != cudaSuccess) {
128
OpmLog::warning(
getCudaErrorMessage
(error, expression, filename, functionName, lineNumber));
129
}
130
}
131
}
// namespace Opm::gpuistl::detail
132
150
#define OPM_GPU_SAFE_CALL(expression) \
151
::Opm::gpuistl::detail::cudaSafeCall(expression, #expression, __FILE__, __func__, __LINE__)
152
153
171
#define OPM_GPU_WARN_IF_ERROR(expression) \
172
::Opm::gpuistl::detail::cudaWarnIfError(expression, #expression, __FILE__, __func__, __LINE__)
173
174
#endif
Opm::gpuistl::detail
Contains wrappers to make the CuBLAS library behave as a modern C++ library with function overlading.
Definition
autotuner.hpp:30
Opm::gpuistl::detail::getCudaErrorMessage
std::string getCudaErrorMessage(cudaError_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
getCudaErrorMessage generates the error message to display for a given error.
Definition
gpu_safe_call.hpp:45
Opm::gpuistl::detail::cudaSafeCall
void cudaSafeCall(cudaError_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
cudaSafeCall checks the return type of the GPU expression (function call) and throws an exception if ...
Definition
gpu_safe_call.hpp:82
Opm::gpuistl::detail::cudaWarnIfError
void cudaWarnIfError(cudaError_t error, const std::string_view &expression, const std::string_view &filename, const std::string_view &functionName, size_t lineNumber)
cudaWarnIfError checks the return type of the GPU expression (function call) and issues a warning if ...
Definition
gpu_safe_call.hpp:121
opm
simulators
linalg
gpuistl
detail
gpu_safe_call.hpp
Generated by
1.17.0