ai_api.h
Go to the documentation of this file.
1 // Copyright 2020 Autodesk, Inc. All rights reserved.
2 //
3 // Use of this software is subject to the terms of the Autodesk license
4 // agreement provided at the time of installation or download, or which
5 // otherwise accompanies this software in either electronic or hard copy form.
6 
12 #pragma once
13 
14 #ifdef __cplusplus
15 #define AI_EXTERN_C extern "C"
16 #else
17 #define AI_EXTERN_C extern
18 #endif
19 
20 #if _MSC_VER && !__INTEL_COMPILER
21 // Currently the microsoft compiler does not support these annotations
22 # define AI_PURE_ATTRIBUTE
23 # define AI_CONST_ATTRIBUTE
24 #else
25 // GCC, Clang, and ICC are ok with these
26 # define AI_PURE_ATTRIBUTE pure
27 # define AI_CONST_ATTRIBUTE const
28 #endif
29 
30 #ifdef __CUDACC__
31 # define AI_API
32 # define AI_DEPRECATED
33 # define AI_PURE
34 # define AI_CONST
35 # define AI_UNAVAILABLE
36 #else
37 # ifdef _WIN32
38 // Public functions need a special declaration in Win32
39 # ifdef _ARNOLDDLL
40 # define AI_API AI_EXTERN_C __declspec(dllexport)
41 # else
42 # define AI_API AI_EXTERN_C __declspec(dllimport)
43 # endif
44 # ifdef AI_ENABLE_DEPRECATION_WARNINGS
45 # define AI_DEPRECATED __declspec(deprecated)
46 # endif
47 # define AI_PURE __declspec(AI_PURE_ATTRIBUTE)
48 # define AI_CONST __declspec(AI_CONST_ATTRIBUTE)
49 # define AI_UNAVAILABLE __declspec(deprecated)
50 # else
51 # ifdef AI_ENABLE_DEPRECATION_WARNINGS
52 # define AI_DEPRECATED __attribute__(( deprecated ))
53 # endif
54 # define AI_API AI_EXTERN_C __attribute__(( visibility("default") ))
55 # define AI_PURE __attribute__(( AI_PURE_ATTRIBUTE ))
56 # define AI_CONST __attribute__(( AI_CONST_ATTRIBUTE ))
57 # ifdef __clang__
58 # define AI_UNAVAILABLE __attribute__((unavailable))
59 # elif __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 && !__INTEL_COMPILER
60 # define AI_UNAVAILABLE __attribute__((error("This function is not allowed to be used")))
61 # else
62  // Using deprecated isn't quite strong enough, but it's the best we can do in this compiler
63 # define AI_UNAVAILABLE __attribute__((deprecated))
64 # endif
65 # endif
66 #endif
67 
68 #ifndef AI_ENABLE_DEPRECATION_WARNINGS
69 # define AI_DEPRECATED
70 #endif
71 
72 // Suppress warnings for returning structs such as colors from functions with
73 // C linkage. These are POD types so it is safe. When we switch to C++ linkage
74 // we can remove these pragmas.
75 #ifdef __clang__
76 # pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"
77 #elif defined (_MSC_VER)
78 # pragma warning( disable : 4190 )
79 #endif
80 
81 // Hint to compiler for how to optimize conditional statements. Only use this
82 // for very unlikely and likely conditions. For instance, unlikely means
83 // happens .1% of the time, not 30% of the time. The main transformation this
84 // causes is to move the unlikely code to the end of the function so that L1
85 // instruction cache is not polluted by rare code. See trac#4145
86 #if (defined(_MSC_VER) && !defined(__INTEL_COMPILER)) || defined(__CUDACC__)
87 #define Ai_likely(expr) (expr)
88 #define Ai_unlikely(expr) (expr)
89 #else
90 #define Ai_likely(expr) (__builtin_expect(!!(expr), true))
91 #define Ai_unlikely(expr) (__builtin_expect(!!(expr), false))
92 #endif
93 
94 // This offers stronger guarantees than inline
95 #if defined(__INTEL_COMPILER) || defined(_MSC_VER)
96 # define AI_FORCEINLINE __forceinline
97 #else
98 # define AI_FORCEINLINE __attribute__ ((always_inline))
99 #endif
100 
101 // ARNOLD_FORCEINLINE is deprecated since it adds "inline" keyword on gcc/clang
102 #if defined(__INTEL_COMPILER) || defined(_MSC_VER)
103 #define ARNOLD_FORCEINLINE AI_FORCEINLINE
104 #else
105 // assumes gcc/clang
106 #define ARNOLD_FORCEINLINE AI_FORCEINLINE inline
107 #endif
108 
109 // CUDA compiler support
110 #ifdef __CUDACC__
111 # ifndef AI_DEVICE
112 # define AI_DEVICE __device__
113 # endif
114 # ifndef AI_GPU_COMPILER
115 # define AI_GPU_COMPILER
116 # endif
117 #define AI_GPU_NO_INLINE __noinline__
118 #define AI_GPU_FORCE_INLINE __forceinline__
119 #else
120 # ifndef AI_DEVICE
121 # define AI_DEVICE
122 # endif
123 # ifndef AI_CPU_COMPILER
124 # define AI_CPU_COMPILER
125 # endif
126 #define AI_GPU_NO_INLINE
127 #define AI_GPU_FORCE_INLINE
128 #endif
129 
130 // Utility macro for optional methods
132 #define AI_OPTIONAL_METHOD_INSTALL(methods, name) \
133 static bool ai_install_##name() { methods.name = name; return true; } \
134 static const bool ai_installed_##name = ai_install_##name();
135 
141 {
144 };
asynchronous, non-blocking call; returns ASAP, task completes in the background
Definition: ai_api.h:143
AtBlockingCall
Whether a function call is blocking (synchronous) or not (asynchronous)
Definition: ai_api.h:140
synchronous, blocking call; returns when the task is done
Definition: ai_api.h:142

© 2020 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com