Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
realm_assert.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef REALM_ASSERT_H
19#define REALM_ASSERT_H
20
21#include "realm_config.h"
22
23#ifdef NDEBUG
24// =============================================
25// Device-side (CUDA or HIP)
26// =============================================
27#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
28
29// Clang CUDA or HIP: __assert_fail is available
30#if defined(__clang__)
31#include <assert.h>
32#define REALM_ASSERT(cond) \
33 do { \
34 if(!(cond)) { \
35 __builtin_trap(); \
36 } \
37 } while(0)
38
39// NVCC CUDA: use trap
40#elif defined(__CUDACC__)
41#define REALM_ASSERT(cond) \
42 do { \
43 if(!(cond)) { \
44 __trap(); \
45 } \
46 } while(0)
47
48#else
49#error "Unknown device compilation environment"
50#endif
51
52// =============================================
53// Host-side
54// =============================================
55#else
56namespace Realm {
57 REALM_INTERNAL_API_EXTERNAL_LINKAGE void realm_assert_fail(const char *cond_text,
58 const char *file, int line);
59}
60
61#define REALM_ASSERT(cond) \
62 do { \
63 if(!(cond)) { \
64 Realm::realm_assert_fail(#cond, __FILE__, __LINE__); \
65 abort(); \
66 } \
67 } while(0)
68
69#endif
70#else
71#include <assert.h>
72#define REALM_ASSERT(cond) assert(cond)
73#endif
74
75#endif // REALM_ASSERT_H
#define REALM_INTERNAL_API_EXTERNAL_LINKAGE
Definition compiler_support.h:218
Definition activemsg.h:38