alpaka
Abstraction Library for Parallel Kernel Acceleration
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
8
#include "
alpaka/core/Sycl.hpp
"
9
10
//! ALPAKA_THROW_ACC either aborts(terminating the program and creating a core dump) or throws std::runtime_error
11
//! depending on the Acc. The std::runtime_error exception can be catched in the catch block.
12
//!
13
//! For CUDA __trap function is used which triggers std::runtime_error but can be catched during wait not exec.
14
//! For HIP abort() function is used and calls __builtin_trap()
15
//! For Sycl assert(false) is not used since it can be disabled -DNDEBUG compile option. abort() is used although it
16
//! generates a runtime error instead of aborting in GPUs: "Caught synchronous SYCL exception: Unresolved Symbol
17
//! <abort> -999 (Unknown PI error)."
18
//!
19
//! The OpenMP specification mandates that exceptions thrown by some thread must be handled by the same thread.
20
//! Therefore std::runtime_error thrown by ALPAKA_THROW_ACC aborts the the program for OpenMP backends. If needed
21
//! the SIGABRT signal can be catched by signal handler.
22
#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && defined(__CUDA_ARCH__)
23
# define ALPAKA_THROW_ACC(MSG) \
24
{ \
25
printf( \
26
"alpaka encountered a user-defined error condition while running on the CUDA back-end:\n%s"
, \
27
(MSG)); \
28
__trap(); \
29
}
30
#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) && defined(__HIP_DEVICE_COMPILE__)
31
# define ALPAKA_THROW_ACC(MSG) \
32
{ \
33
printf( \
34
"alpaka encountered a user-defined error condition while running on the HIP back-end:\n%s"
, \
35
(MSG)); \
36
abort(); \
37
}
38
#elif defined(ALPAKA_ACC_SYCL_ENABLED) && defined(__SYCL_DEVICE_ONLY__)
39
# define ALPAKA_THROW_ACC(MSG) \
40
{ \
41
printf( \
42
"alpaka encountered a user-defined error condition while running on the SYCL back-end:\n%s"
, \
43
(MSG)); \
44
abort(); \
45
}
46
#else
47
# define ALPAKA_THROW_ACC(MSG) \
48
{ \
49
printf("alpaka encountered a user-defined error condition:\n%s"
, (MSG)); \
50
throw std::runtime_error(MSG); \
51
}
52
#endif
Sycl.hpp
include
alpaka
core
RuntimeMacros.hpp
Generated on Thu Nov 21 2024 22:46:14 for alpaka by
1.9.1