Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
Macro.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2026 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10// https://gcc.gnu.org/wiki/Visibility updated to use C++11 attribute syntax
11// In Open3D, we set symbol visibility based on folder / cmake target through
12// cmake. e.g. all symbols in kernel folders are hidden. These macros allow fine
13// grained control over symbol visibility.
14#if defined(_WIN32) || defined(__CYGWIN__)
15#define OPEN3D_DLL_IMPORT __declspec(dllimport)
16#define OPEN3D_DLL_EXPORT __declspec(dllexport)
17#define OPEN3D_DLL_LOCAL
18#else
19#define OPEN3D_DLL_IMPORT [[gnu::visibility("default")]]
20#define OPEN3D_DLL_EXPORT [[gnu::visibility("default")]]
21#define OPEN3D_DLL_LOCAL [[gnu::visibility("hidden")]]
22#endif
23
24#ifdef OPEN3D_STATIC
25#define OPEN3D_API
26#define OPEN3D_LOCAL
27#else
28#define OPEN3D_LOCAL OPEN3D_DLL_LOCAL
29#if defined(OPEN3D_ENABLE_DLL_EXPORTS)
30#define OPEN3D_API OPEN3D_DLL_EXPORT
31#else
32#define OPEN3D_API OPEN3D_DLL_IMPORT
33#endif
34#endif
35
36// Compiler-specific function macro.
37// Ref: https://stackoverflow.com/a/4384825
38#ifdef _WIN32
39#define OPEN3D_FUNCTION __FUNCSIG__
40#else
41#define OPEN3D_FUNCTION __PRETTY_FUNCTION__
42#endif
43
44// Assertion for host, CUDA device, and SYCL device code.
45// Usage:
46// OPEN3D_ASSERT(condition);
47// OPEN3D_ASSERT(condition, "Error message");
48//
49// CUDA and SYCL device: OPEN3D_ASSERT prints the message and traps
50// unconditionally (independent of NDEBUG), so it fires in both Debug and
51// Release.
52// For host-only code, utility::LogError() may also be used directly.
53#define OPEN3D_ASSERT_EXPAND(...) __VA_ARGS__
54#define OPEN3D_ASSERT_GET_MACRO(_1, _2, NAME, ...) NAME
55#define OPEN3D_ASSERT_CHOOSER(...) \
56 OPEN3D_ASSERT_EXPAND(OPEN3D_ASSERT_GET_MACRO( \
57 __VA_ARGS__, OPEN3D_ASSERT_MSG, OPEN3D_ASSERT_1, ))
58#define OPEN3D_ASSERT(...) \
59 OPEN3D_ASSERT_EXPAND(OPEN3D_ASSERT_CHOOSER(__VA_ARGS__)(__VA_ARGS__))
60#define OPEN3D_ASSERT_1(condition) \
61 OPEN3D_ASSERT_MSG(condition, "Assertion failed: " #condition)
62
63#if defined(__CUDA_ARCH__)
64
66
67#define OPEN3D_ASSERT_MSG(condition, message) \
68 do { \
69 if (!(condition)) { \
70 ::open3d::detail::Open3DCudaAssertReportAndTrap(message); \
71 } \
72 } while (0)
73
74#elif defined(__SYCL_DEVICE_ONLY__)
75
76#include <sycl/ext/oneapi/experimental/builtins.hpp>
77#include <sycl/sycl.hpp>
78
79namespace open3d {
80namespace detail {
81
82inline void Open3DSyclAssertReportAndTrap(const char *message) {
83 sycl::ext::oneapi::experimental::printf(
84 "Open3D SYCL device assertion failed: %s\n", message);
85 __builtin_trap();
86}
87
88} // namespace detail
89} // namespace open3d
90
91#define OPEN3D_ASSERT_MSG(condition, message) \
92 do { \
93 if (!(condition)) { \
94 ::open3d::detail::Open3DSyclAssertReportAndTrap(message); \
95 } \
96 } while (0)
97
98#else
99
100#define OPEN3D_ASSERT_MSG(condition, message) \
101 do { \
102 if (!(condition)) { \
103 ::open3d::utility::Logger::LogError_( \
104 __FILE__, __LINE__, \
105 static_cast<const char *>(OPEN3D_FUNCTION), "{}", \
106 message); \
107 } \
108 } while (0)
109
110#endif
Common CUDA utilities.
Definition PinholeCameraIntrinsic.cpp:16