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

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