FLANG
common.h
1//===-- include/flang/Runtime/CUDA/common.h ------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef FORTRAN_RUNTIME_CUDA_COMMON_H_
10#define FORTRAN_RUNTIME_CUDA_COMMON_H_
11
12#include "flang/Runtime/entry-names.h"
13
15static constexpr unsigned kMemTypeDevice = 0;
16static constexpr unsigned kMemTypeManaged = 1;
17static constexpr unsigned kMemTypeUnified = 2;
18static constexpr unsigned kMemTypePinned = 3;
19
21static constexpr unsigned kHostToDevice = 0;
22static constexpr unsigned kDeviceToHost = 1;
23static constexpr unsigned kDeviceToDevice = 2;
24
25#define CUDA_REPORT_IF_ERROR(expr) \
26 [](cudaError_t err) { \
27 if (err == cudaSuccess) \
28 return; \
29 const char *name = cudaGetErrorName(err); \
30 if (!name) \
31 name = "<unknown>"; \
32 Fortran::runtime::Terminator terminator{__FILE__, __LINE__}; \
33 terminator.Crash("'%s' failed with '%s'", #expr, name); \
34 }(expr)
35
36#define CUDA_REPORT_IF_ERROR_LOC(expr, file, line) \
37 [](cudaError_t err, const char *sourceFile, int sourceLine) { \
38 if (err == cudaSuccess) \
39 return; \
40 const char *name = cudaGetErrorName(err); \
41 if (!name) \
42 name = "<unknown>"; \
43 Fortran::runtime::Terminator terminator{sourceFile, sourceLine}; \
44 terminator.Crash("'%s' failed with '%s'", #expr, name); \
45 }(expr, sourceFile, sourceLine)
46
47#endif // FORTRAN_RUNTIME_CUDA_COMMON_H_