9#ifndef FORTRAN_RUNTIME_CUDA_COMMON_H_
10#define FORTRAN_RUNTIME_CUDA_COMMON_H_
12#include "flang/Runtime/entry-names.h"
15static constexpr unsigned kMemTypeDevice = 0;
16static constexpr unsigned kMemTypeManaged = 1;
17static constexpr unsigned kMemTypeUnified = 2;
18static constexpr unsigned kMemTypePinned = 3;
21static constexpr unsigned kHostToDevice = 0;
22static constexpr unsigned kDeviceToHost = 1;
23static constexpr unsigned kDeviceToDevice = 2;
25#define CUDA_REPORT_IF_ERROR(expr) \
26 [](cudaError_t err) { \
27 if (err == cudaSuccess) \
29 const char *name = cudaGetErrorName(err); \
32 Fortran::runtime::Terminator terminator{__FILE__, __LINE__}; \
33 terminator.Crash("'%s' failed with '%s'", #expr, name); \
36#define CUDA_REPORT_IF_ERROR_LOC(expr, file, line) \
37 [](cudaError_t err, const char *sourceFile, int sourceLine) { \
38 if (err == cudaSuccess) \
40 const char *name = cudaGetErrorName(err); \
43 Fortran::runtime::Terminator terminator{sourceFile, sourceLine}; \
44 terminator.Crash("'%s' failed with '%s'", #expr, name); \
45 }(expr, sourceFile, sourceLine)