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/descriptor-consts.h"
13#include "flang/Runtime/entry-names.h"
14
16static constexpr unsigned kMemTypeDevice = 0;
17static constexpr unsigned kMemTypeManaged = 1;
18static constexpr unsigned kMemTypeUnified = 2;
19static constexpr unsigned kMemTypePinned = 3;
20
22static constexpr unsigned kHostToDevice = 0;
23static constexpr unsigned kDeviceToHost = 1;
24static constexpr unsigned kDeviceToDevice = 2;
25
26#define CUDA_REPORT_IF_ERROR(expr) \
27 [](cudaError_t err) { \
28 if (err == cudaSuccess) \
29 return; \
30 const char *name = cudaGetErrorName(err); \
31 if (!name) \
32 name = "<unknown>"; \
33 Fortran::runtime::Terminator terminator{__FILE__, __LINE__}; \
34 terminator.Crash("'%s' failed with '%s'", #expr, name); \
35 }(expr)
36
37#endif // FORTRAN_RUNTIME_CUDA_COMMON_H_