SuperDex Physics C++ API
Loading...
Searching...
No Matches
mochi_config.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**************************************************************************************************
18 This header declares macros which enable/disable Mochi features.
19 These macros are always defined to 1 or 0 so you can use #if instead of #ifdef.
20 These macros are externally customizable (e.g. via BUCK of Visual Studio configuration).
21 If they have not already been defined by the user, then we will define the defaults here.
22*/
23
24// no #pragma once for pure C inclusion
25#ifndef MOCHI_CONFIG_H
26#define MOCHI_CONFIG_H
27
29
30#include <cstddef>
31
32/**************************************************************************************************
33 Debugging
34 - MOCHI_DEBUG Enables additional debug checks (slower).
35 - MOCHI_OPTIMIZED Defined to 1 if this is a build in which optimizations are
36 enabled. Else defined to 0. Usually equivalent to !MOCHI_DEBUG.
37 - MOCHI_WARN_IF_NOT_OPTIMIZED Causes the compiler to print a warning message if
38 !MOCHI_OPTIMIZED.
39 - MOCHI_ASSERT_ENABLED Enables MOCHI_ASSERT macros. Else they compile out.
40 - MOCHI_ASSERT_VERBOSE_ENABLED Enables MOCHI_ASSERT_VERBOSE macros. Else they compile out.
41 - MOCHI_LOG_ENABLED Enables the MOCHI_LOG family of macros. Else they compile out.
42 - MOCHI_PROFILE_ENABLE Enables the MOCHI_PROFILE family of macros. Else they compile
43 out.
44*/
45
46#ifndef MOCHI_DEBUG
47#ifdef NDEBUG
48#define MOCHI_DEBUG 0
49#else
50#define MOCHI_DEBUG 1
51#endif
52#endif
53
54#ifndef MOCHI_OPTIMIZED
55#ifdef NDEBUG
56#define MOCHI_OPTIMIZED 1
57#else
58#define MOCHI_OPTIMIZED 0
59#endif
60#endif
61
62#ifndef MOCHI_WARN_IF_NOT_OPTIMIZED
63#define MOCHI_WARN_IF_NOT_OPTIMIZED 0
64#endif
65
66#ifndef MOCHI_ASSERT_ENABLED
67#define MOCHI_ASSERT_ENABLED 1
68#endif
69
70#ifndef MOCHI_ASSERT_VERBOSE_ENABLED
71#define MOCHI_ASSERT_VERBOSE_ENABLED (MOCHI_DEBUG && MOCHI_ASSERT_ENABLED)
72#endif
73
74#ifndef MOCHI_LOG_ENABLED
75#define MOCHI_LOG_ENABLED 1
76#endif
77
78#ifndef MOCHI_PROFILE_ENABLE
79#define MOCHI_PROFILE_ENABLE 0
80#endif
81
82/**************************************************************************************************
83 If MOCHI_INTERNAL is defined to 1, then the build will include samples and tests that depend on
84 assets from "assets/internal". Do this only if you have access to the internal assets.
85*/
86
87#ifndef MOCHI_INTERNAL
88#define MOCHI_INTERNAL 0
89#endif
90
91/**************************************************************************************************
92 MOCHI_USE_MPC
93 Gates an optional controller integration at compile time. Defaults to MOCHI_INTERNAL. Define
94 MOCHI_USE_MPC explicitly to override the default.
95*/
96
97#ifndef MOCHI_USE_MPC
98#define MOCHI_USE_MPC MOCHI_INTERNAL
99#endif
100
101/**************************************************************************************************
102 Floating Point
103 - MOCHI_USE_DOUBLE_PRECISION If enabled type superdex::real will be double-precision
104*/
105
106#ifndef MOCHI_USE_DOUBLE_PRECISION
107#define MOCHI_USE_DOUBLE_PRECISION 0
108#endif
109
110#if MOCHI_LANGUAGE_CPP
111namespace superdex {
112#if MOCHI_USE_DOUBLE_PRECISION
113using real = double;
114#else
115using real = float;
116#endif
117
118inline constexpr real operator""_r(long double val) {
119 return static_cast<real>(val);
120}
121inline constexpr real operator""_r(unsigned long long int val) {
122 return static_cast<real>(val);
123}
124
125/**************************************************************************************************
126 Integer literals for size_t and ptrdiff_t. NOTE: These have been recently accepted for the C++23
127 standard. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0330r8.html
128*/
129inline constexpr ptrdiff_t operator""_z(unsigned long long int val) {
130 return static_cast<ptrdiff_t>(val);
131}
132inline constexpr size_t operator""_uz(unsigned long long int val) {
133 return static_cast<size_t>(val);
134}
135
136} // namespace superdex
137#endif
138
139/**************************************************************************************************
140 MOCHI_USE_SIMD
141 By default, Mochi makes use of SIMD vector instructions when supported by the CPU architecture.
142 Define MOCHI_USE_SIMD=0 to disable SIMD and enable scalar emulation instead.
143*/
144#ifndef MOCHI_USE_SIMD
145#define MOCHI_USE_SIMD 1
146#endif
147
148#if MOCHI_USE_SIMD && !MOCHI_ARCH_ARM_NEON && !MOCHI_ARCH_X64_AVX2
149// SIMD not supported for this architecture
150#undef MOCHI_USE_SIMD
151#define MOCHI_USE_SIMD 0
152#endif
153
154#if !MOCHI_USE_SIMD
155// Emulate 32 16-byte SIMD registers. A common use case for SIMD emulation is NVIDIA GPUs, where
156// each thread has access to 255 32-bit registers. 32 SIMD vectors of 16 bytes will take 128 of
157// them.
158#undef MOCHI_SIMD_REGISTER_COUNT
159#undef MOCHI_SIMD_REGISTER_SIZE_BYTES
160#define MOCHI_SIMD_REGISTER_COUNT 32
161#define MOCHI_SIMD_REGISTER_SIZE_BYTES 16
162#endif
163
164/**************************************************************************************************
165 Optional Third Party Libraries
166 - MOCHI_USE_CUDA Enable CUDA
167 - MOCHI_USE_CUDSS Enable cudss (used for some experimental features with CUDA)
168 - MOCHI_USE_EIGEN Enable Eigen (used for some experimental features)
169 - MOCHI_USE_HDF5 Enable HDF5 (used for binary file IO)
170 - MOCHI_USE_TORCH Enable Torch (used for neural network evaluation)
171 - MOCHI_USE_TRACY Enable Tracy (used for profiling)
172 - MOCHI_USE_MATH_ACCELERATION Enable math acceleration libraries (e.g. Accelerate on macOS)
173*/
174
175#ifndef MOCHI_USE_CUDA
176#define MOCHI_USE_CUDA 0
177#endif
178
179#ifndef MOCHI_USE_CUDSS
180#define MOCHI_USE_CUDSS 0
181#endif
182
183#if MOCHI_USE_CUDA == 0 && MOCHI_USE_CUDSS != 0
184#undef MOCHI_USE_CUDSS
185#define MOCHI_USE_CUDSS 0
186#endif
187
188#ifndef MOCHI_USE_EIGEN
189#define MOCHI_USE_EIGEN 0
190#endif
191
192#ifndef MOCHI_USE_HDF5
193#define MOCHI_USE_HDF5 0
194#endif
195
196/**************************************************************************************************
197 MOCHI_USE_OSC
198 Gates the optional Operational Space Controller (OSC) at compile time. Defaults to
199 MOCHI_INTERNAL. Defined separately so OSC can later be toggled independently of MOCHI_INTERNAL.
200*/
201#ifndef MOCHI_USE_OSC
202#define MOCHI_USE_OSC MOCHI_INTERNAL
203#endif
204
205#ifndef MOCHI_USE_TORCH
206#define MOCHI_USE_TORCH 0
207#endif
208
209#ifndef MOCHI_USE_TRACY
210#define MOCHI_USE_TRACY 0
211#endif
212#if MOCHI_USE_TRACY && !defined(TRACY_ENABLE)
213#define TRACY_ENABLE 1
214#endif
215
216#ifndef MOCHI_USE_MATH_ACCELERATION
217#define MOCHI_USE_MATH_ACCELERATION 0
218#endif
219
220/**************************************************************************************************
221 Linking
222*/
223
224// MOCHI_CORE_STATIC_LINKING can only be defined to 1 when building MochiCore, or when building
225// projects that will statically link with MochiCore. Projects that take a header-only dependency
226// on MochiCore should leave the default of 0.
227#ifndef MOCHI_CORE_STATIC_LINKING
228#define MOCHI_CORE_STATIC_LINKING 0
229#endif
230
231// If MOCHI_USE_EXTERN_TEMPLATE is defined to 1, then extern templates will be used in headers
232// to reduce code bloat. However, extern template declarations require static linking with the
233// corresponding definitions. Therefore extern templates are not declared in projects that take
234// a header-only dependency on MochiCore.
235#ifndef MOCHI_USE_EXTERN_TEMPLATE
236#if MOCHI_CORE_STATIC_LINKING
237#define MOCHI_USE_EXTERN_TEMPLATE 1
238#else
239#define MOCHI_USE_EXTERN_TEMPLATE 0
240#endif
241#endif
242
243// Some types have built-in features for Pybind. These are normally compiled out except in select
244// cpp files which redefine MOCHI_INCLUDE_PYBIND_SUPPORT to 1.
245#ifndef MOCHI_INCLUDE_PYBIND_SUPPORT
246#define MOCHI_INCLUDE_PYBIND_SUPPORT 0
247#endif
248
249// Define MOCHI_PMR_USES_JEMALLOC to 1 if jemalloc is used to implement
250// std::pmr::new_delete_resource. A work-around is required in this case.
251#ifndef MOCHI_PMR_USES_JEMALLOC
252#define MOCHI_PMR_USES_JEMALLOC 0
253#endif
254
255#endif // MOCHI_CONFIG_H