alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
RuntimeMacros.hpp
Go to the documentation of this file.
1/* Copyright 2022 Andrea Bocci, Mehmet Yusufoglu, René Widera, Aurora Perego
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7// Implementation details
9
10#include <stdexcept>
11
12//! ALPAKA_THROW_ACC either aborts(terminating the program and creating a core dump) or throws std::runtime_error
13//! depending on the Acc. The std::runtime_error exception can be caught in the catch block.
14//!
15//! For CUDA __trap function is used which triggers std::runtime_error but can be caught during wait not exec.
16//! For HIP abort() function is used and calls __builtin_trap()
17//! For SYCL assert(false) is not used since it can be disabled with the -DNDEBUG compile option. abort() is used
18//! although it generates a runtime error instead of aborting in GPUs:
19//! "Caught synchronous SYCL exception: Unresolved Symbol <abort> -999 (Unknown PI error)."
20//!
21//! The OpenMP specification mandates that exceptions thrown by some thread must be handled by the same thread.
22//! Therefore std::runtime_error thrown by ALPAKA_THROW_ACC aborts the the program for OpenMP backends. If needed
23//! the SIGABRT signal can be caught by signal handler.
24#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && defined(__CUDA_ARCH__)
25# define ALPAKA_THROW_ACC(MSG) \
26 { \
27 printf( \
28 "alpaka encountered a user-defined error condition while running on the CUDA back-end:\n%s", \
29 (MSG)); \
30 __trap(); \
31 }
32#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) && defined(__HIP_DEVICE_COMPILE__)
33# define ALPAKA_THROW_ACC(MSG) \
34 { \
35 printf( \
36 "alpaka encountered a user-defined error condition while running on the HIP back-end:\n%s", \
37 (MSG)); \
38 abort(); \
39 }
40#elif defined(ALPAKA_ACC_SYCL_ENABLED) && defined(__SYCL_DEVICE_ONLY__)
41# define ALPAKA_THROW_ACC(MSG) \
42 { \
43 printf( \
44 "alpaka encountered a user-defined error condition while running on the SYCL back-end:\n%s", \
45 (MSG)); \
46 abort(); \
47 }
48#elif defined(ALPAKA_ACC_GPU_CUDA_ONLY_MODE) || defined(ALPAKA_ACC_GPU_HIP_ONLY_MODE)
49// In CUDA-only or HIP-only mode, ALPAKA_FN_ACC functions are __device__ functions, and do not support having a throw
50// visible even during host compilation
51# define ALPAKA_THROW_ACC(MSG) \
52 { \
53 }
54#else
55# define ALPAKA_THROW_ACC(MSG) \
56 { \
57 printf("alpaka encountered a user-defined error condition:\n%s", (MSG)); \
58 throw std::runtime_error(MSG); \
59 }
60#endif