rocprofiler-sdk/defines.h Source File

rocprofiler-sdk/defines.h Source File#

ROCprofiler-SDK developer API: rocprofiler-sdk/defines.h Source File
ROCprofiler-SDK developer API 1.0.0
ROCm Profiling API and tools
defines.h
1// MIT License
2//
3// Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#pragma once
24
25#include <stdint.h>
26
27/**
28 * @defgroup SYMBOL_VERSIONING_GROUP Symbol Versions
29 *
30 * @brief The names used for the shared library versioned symbols.
31 *
32 * Every function is annotated with one of the version macros defined in this
33 * section. Each macro specifies a corresponding symbol version string. After
34 * dynamically loading the shared library with @p dlopen, the address of each
35 * function can be obtained using @p dlsym with the name of the function and
36 * its corresponding symbol version string. An error will be reported by @p
37 * dlvsym if the installed library does not support the version for the
38 * function specified in this version of the interface.
39 *
40 * @{
41 */
42
43/**
44 * @brief The function was introduced in version 0.0 of the interface and has the
45 * symbol version string of ``"ROCPROFILER_SDK_0.0"``.
46 */
47#define ROCPROFILER_SDK_VERSION_0_0
48
49/** @} */
50
51/**
52 * @def ROCPROFILER_SDK_BETA_COMPAT
53 * @brief rocprofiler-sdk clients (i.e. tool using rocprofiler-sdk) should set this definition to 1
54 * before including any rocprofiler-sdk header if it wants rocprofiler-sdk to provide preprocessor
55 * definitions to help with compilation support for tools prior to v1.0.0 release. Note: for v1.0.0
56 * release, rocprofiler-sdk sets the ppdef to 1 by default. Eventually, rocprofiler-sdk will remove
57 * defining this value and it will be up to the tools to define this value.
58 *
59 * For example in version 0.6.0, there was a function `rocprofiler_create_profile_config` and, prior
60 * to the 1.0.0 release, this function was renamed to `rocprofiler_create_counter_config`.
61 * @addtogroup VERSIONING_GROUP
62 *
63 * @def ROCPROFILER_SDK_BETA_COMPAT_SUPPORTED
64 * @brief rocprofiler-sdk will set this preprocessor definition to 1 if it can honor
65 * ::ROCPROFILER_SDK_BETA_COMPAT set to 1. Once backwards compatibility with the beta
66 * rocprofiler-sdk can no longer be supported, this will always be set to 0.
67 * @addtogroup VERSIONING_GROUP
68 *
69 * @def ROCPROFILER_SDK_DEPRECATED_WARNINGS
70 * @brief Set this preprocessor definition to 0 to silent compiler warnings when using features that
71 * are marked as deprecated. By default, rocprofiler-sdk defines this to equal to 1.
72 * @addtogroup VERSIONING_GROUP
73 *
74 * @def ROCPROFILER_SDK_EXPERIMENTAL_WARNINGS
75 * @brief Set this preprocessor definition to 1 to enable compiler warnings when using experimental
76 * features. @see ::ROCPROFILER_SDK_EXPERIMENTAL
77 * @addtogroup VERSIONING_GROUP
78 *
79 * @def ROCPROFILER_SDK_EXPERIMENTAL
80 * @brief When this attribute is added to a type, object, expression, etc., the developer should be
81 * aware that the API and/or ABI is subject to change in subsequent releases.
82 * @addtogroup VERSIONING_GROUP
83 *
84 * @def ROCPROFILER_SDK_COMPUTE_VERSION_VALUE
85 * @param[in] MAX_VERSION_VALUE set to +1 of the maximum value for a given version, e.g. a value of
86 * 100 means that the max value of the major/minor/patch version is 99
87 * @param[in] MAJOR_VERSION major version of library (integral)
88 * @param[in] MINOR_VERSION minor version of library (integral)
89 * @param[in] PATCH_VERSION patch version of library (integral)
90 * @brief Helper macro calculating a generate versioning integer for a library
91 * @addtogroup VERSIONING_GROUP
92 *
93 * @def ROCPROFILER_SDK_COMPUTE_VERSION
94 * @param[in] MAJOR_VERSION major version of library (integral)
95 * @param[in] MINOR_VERSION minor version of library (integral)
96 * @param[in] PATCH_VERSION patch version of library (integral)
97 * @brief Helper macro for users to generate versioning int expected by
98 * rocprofiler-sdk when the library maintains a major, minor, and patch version numbers
99 * @addtogroup VERSIONING_GROUP
100 */
101
102#if !defined(ROCPROFILER_ATTRIBUTE)
103# if defined(_MSC_VER)
104# define ROCPROFILER_ATTRIBUTE(...) __declspec(__VA_ARGS__)
105# else
106# define ROCPROFILER_ATTRIBUTE(...) __attribute__((__VA_ARGS__))
107# endif
108#endif
109
110#if !defined(ROCPROFILER_PUBLIC_API)
111# if defined(_MSC_VER)
112# define ROCPROFILER_PUBLIC_API ROCPROFILER_ATTRIBUTE(dllexport)
113# else
114# define ROCPROFILER_PUBLIC_API ROCPROFILER_ATTRIBUTE(visibility("default"))
115# endif
116#endif
117
118#if !defined(ROCPROFILER_HIDDEN_API)
119# if defined(_MSC_VER)
120# define ROCPROFILER_HIDDEN_API
121# else
122# define ROCPROFILER_HIDDEN_API ROCPROFILER_ATTRIBUTE(visibility("hidden"))
123# endif
124#endif
125
126#if !defined(ROCPROFILER_EXPORT_DECORATOR)
127# define ROCPROFILER_EXPORT_DECORATOR ROCPROFILER_PUBLIC_API
128#endif
129
130#if !defined(ROCPROFILER_IMPORT_DECORATOR)
131# if defined(_MSC_VER)
132# define ROCPROFILER_IMPORT_DECORATOR ROCPROFILER_ATTRIBUTE(dllimport)
133# else
134# define ROCPROFILER_IMPORT_DECORATOR
135# endif
136#endif
137
138#define ROCPROFILER_EXPORT ROCPROFILER_EXPORT_DECORATOR
139#define ROCPROFILER_IMPORT ROCPROFILER_IMPORT_DECORATOR
140
141#if !defined(ROCPROFILER_API)
142# if defined(rocprofiler_EXPORTS)
143# define ROCPROFILER_API ROCPROFILER_EXPORT
144# else
145# define ROCPROFILER_API ROCPROFILER_IMPORT
146# endif
147#endif
148
149#if defined(__has_attribute)
150# if __has_attribute(nonnull)
151# define ROCPROFILER_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
152# else
153# define ROCPROFILER_NONNULL(...)
154# endif
155#else
156# if defined(__GNUC__)
157# define ROCPROFILER_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
158# else
159# define ROCPROFILER_NONNULL(...)
160# endif
161#endif
162
163#if __cplusplus >= 201103L // C++11
164/* c++11 allows extended initializer lists. */
165# define ROCPROFILER_HANDLE_LITERAL(type, value) (type{value})
166#elif __STDC_VERSION__ >= 199901L
167/* c99 allows compound literals. */
168# define ROCPROFILER_HANDLE_LITERAL(type, value) ((type){value})
169#else
170# define ROCPROFILER_HANDLE_LITERAL(type, value) \
171 { \
172 value \
173 }
174#endif
175
176#ifdef __cplusplus
177# define ROCPROFILER_EXTERN_C_INIT extern "C" {
178# define ROCPROFILER_EXTERN_C_FINI }
179# define ROCPROFILER_CXX_CODE(...) __VA_ARGS__
180#else
181# define ROCPROFILER_EXTERN_C_INIT
182# define ROCPROFILER_EXTERN_C_FINI
183# define ROCPROFILER_CXX_CODE(...)
184#endif
185
186#if __cplusplus
187# define ROCPROFILER_UINT64_C(value) uint64_t(value)
188#else
189# define ROCPROFILER_UINT64_C(value) UINT64_C(value)
190#endif
191
192#if defined(__cplusplus) && __cplusplus >= 201402L
193# define ROCPROFILER_SDK_DEPRECATED_MESSAGE(...) [[deprecated(__VA_ARGS__)]]
194#elif !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
195# define ROCPROFILER_SDK_DEPRECATED_MESSAGE(...) [[deprecated(__VA_ARGS__)]]
196#else
197# define ROCPROFILER_SDK_DEPRECATED_MESSAGE(...) ROCPROFILER_ATTRIBUTE(deprecated)
198#endif
199
200// TODO(jomadsen): uncomment below code before v1.0.0
201#if !defined(ROCPROFILER_SDK_DEPRECATED_WARNINGS)
202# define ROCPROFILER_SDK_DEPRECATED_WARNINGS 0
203#endif
204
205#if !defined(ROCPROFILER_SDK_EXPERIMENTAL_WARNINGS)
206# define ROCPROFILER_SDK_EXPERIMENTAL_WARNINGS 0
207#endif
208
209#if defined(ROCPROFILER_SDK_DEPRECATED_WARNINGS) && ROCPROFILER_SDK_DEPRECATED_WARNINGS > 0
210# define ROCPROFILER_SDK_DEPRECATED(...) ROCPROFILER_SDK_DEPRECATED_MESSAGE(__VA_ARGS__)
211#else
212# define ROCPROFILER_SDK_DEPRECATED(...)
213#endif
214
215#define ROCPROFILER_SDK_EXPERIMENTAL_MESSAGE \
216 ROCPROFILER_SDK_DEPRECATED_MESSAGE( \
217 "Note: this feature has been marked as experimental. Define " \
218 "ROCPROFILER_SDK_EXPERIMENTAL_WARNINGS=0 to silence this message.")
219
220#if defined(ROCPROFILER_SDK_EXPERIMENTAL_WARNINGS) && ROCPROFILER_SDK_EXPERIMENTAL_WARNINGS > 0
221# define ROCPROFILER_SDK_EXPERIMENTAL ROCPROFILER_SDK_EXPERIMENTAL_MESSAGE
222#else
223# define ROCPROFILER_SDK_EXPERIMENTAL
224#endif
225
226//
227// if ROCPROFILER_SDK_BETA_COMPAT is > 0, provide some macros to help with compatibility.
228// For 1.0.0 release, we define this by default
229//
230#if !defined(ROCPROFILER_SDK_BETA_COMPAT)
231# define ROCPROFILER_SDK_BETA_COMPAT 1
232#endif
233
234// rocprofiler-sdk will set ROCPROFILER_SDK_BETA_COMPAT_SUPPORTED to 1 if it can support
235// compatibility with rocprofiler-sdk < v1.0.0
236#if defined(ROCPROFILER_SDK_BETA_COMPAT) && ROCPROFILER_SDK_BETA_COMPAT > 0
237# define ROCPROFILER_SDK_BETA_COMPAT_SUPPORTED 1
238#endif
239
240#define ROCPROFILER_SDK_COMPUTE_VERSION_VALUE(MAX_VERSION_VALUE, MAJOR, MINOR, PATCH) \
241 (((MAX_VERSION_VALUE * MAX_VERSION_VALUE) * MAJOR) + (MAX_VERSION_VALUE * MINOR) + (PATCH))
242
243#define ROCPROFILER_SDK_COMPUTE_VERSION(MAJOR, MINOR, PATCH) \
244 ROCPROFILER_SDK_COMPUTE_VERSION_VALUE(100, MAJOR, MINOR, PATCH)