Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:45:13

0001 /*
0002  * SPDX-FileCopyrightText: Copyright (c) 2009-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
0003  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0004  *
0005  * Licensed under the Apache License, Version 2.0 (the "License");
0006  * you may not use this file except in compliance with the License.
0007  * You may obtain a copy of the License at
0008  *
0009  *     http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  *
0017  * Licensed under the Apache License v2.0 with LLVM Exceptions.
0018  * See https://nvidia.github.io/NVTX/LICENSE.txt for license information.
0019  */
0020 
0021 /** \file nvToolsExt.h
0022  */
0023 
0024 /* ========================================================================= */
0025 /** \mainpage
0026  * \tableofcontents
0027  * \section INTRODUCTION Introduction
0028  *
0029  * The NVIDIA Tools Extension library is a set of functions that a
0030  * developer can use to provide additional information to tools.
0031  * The additional information is used by the tool to improve
0032  * analysis and visualization of data.
0033  *
0034  * The library introduces close to zero overhead if no tool is
0035  * attached to the application.  The overhead when a tool is
0036  * attached is specific to the tool.
0037  *
0038  * \section INITIALIZATION Initialization
0039  *
0040  * Typically the tool's library that plugs into NVTX is indirectly
0041  * loaded via environmental properties that are platform specific.
0042  * For some platform or special cases, the user may be required
0043  * to instead explicitly initialize instead though.   This can also
0044  * be helpful to control when the API loads a tool's library instead
0045  * of what would typically be the first function call to emit info.
0046  * For these rare case, see \ref INITIALIZATION for additional information.
0047  *
0048  * \section MARKERS_AND_RANGES Markers and Ranges
0049  *
0050  * Markers and ranges are used to describe events at a specific time (markers)
0051  * or over a time span (ranges) during the execution of the application
0052  * respectively.
0053  *
0054  * \subsection MARKERS Markers
0055  *
0056  * Markers denote specific moments in time.
0057  *
0058  *
0059  * See \ref DOMAINS and \ref EVENT_ATTRIBUTES for additional information on
0060  * how to specify the domain.
0061  *
0062  * \subsection THREAD_RANGES Thread Ranges
0063  *
0064  * Thread ranges denote nested time ranges. Nesting is maintained per thread
0065  * per domain and does not require any additional correlation mechanism. The
0066  * duration of a thread range is defined by the corresponding pair of
0067  * nvtxRangePush* to nvtxRangePop API calls.
0068  *
0069  * See \ref DOMAINS and \ref EVENT_ATTRIBUTES for additional information on
0070  * how to specify the domain.
0071  *
0072  * \subsection PROCESS_RANGES Process Ranges
0073  *
0074  * Process ranges denote a time span that can expose arbitrary concurrency, as
0075  * opposed to thread ranges that only support nesting. In addition the range
0076  * start event can happen on a different thread than the end marker. For the
0077  * correlation of a start/end pair an unique correlation ID is used that is
0078  * returned from the start API call and needs to be passed into the end API
0079  * call.
0080  *
0081  * \subsection EVENT_ATTRIBUTES Event Attributes
0082  *
0083  * \ref MARKERS_AND_RANGES can be annotated with various attributes to provide
0084  * additional information for an event or to guide the tool's visualization of
0085  * the data. Each of the attributes is optional and if left unused the
0086  * attributes fall back to a default value. The attributes include:
0087  * - color
0088  * - category
0089  *
0090  * To specify any attribute other than the text message, the \ref
0091  * EVENT_ATTRIBUTE_STRUCTURE "Event Attribute Structure" must be used.
0092  *
0093  * \section DOMAINS Domains
0094  *
0095  * Domains enable developers to scope annotations. By default all events and
0096  * annotations are in the default domain. Additional domains can be registered.
0097  * This allows developers to scope markers, ranges, and resources names to
0098  * avoid conflicts.
0099  *
0100  * The function ::nvtxDomainCreateA or ::nvtxDomainCreateW is used to create
0101  * a named domain.
0102  *
0103  * Each domain maintains its own
0104  * - categories
0105  * - thread range stacks
0106  * - registered strings
0107  *
0108  * The function ::nvtxDomainDestroy marks the end of the domain. Destroying
0109  * a domain unregisters and destroys all objects associated with it such as
0110  * registered strings, resource objects, named categories, and started ranges.
0111  *
0112  * \section RESOURCE_NAMING Resource Naming
0113  *
0114  * This section covers calls that allow to annotate objects with user-provided
0115  * names in order to allow for a better analysis of complex trace data. All of
0116  * the functions take the handle or the ID of the object to name and the name.
0117  * The functions can be called multiple times during the execution of an
0118  * application, however, in that case it is implementation dependent which
0119  * name will be reported by the tool.
0120  *
0121  * \subsection CATEGORY_NAMING Category Naming
0122  *
0123  * Some function in this library support associating an integer category
0124  * to enable filtering and sorting.  The category naming functions allow
0125  * the application to associate a user friendly name with the integer
0126  * category.  Support for domains have been added in NVTX_VERSION_2 to
0127  * avoid collisions when domains are developed independently.
0128  *
0129  * \subsection RESOURCE_OBJECTS Resource Objects
0130  *
0131  * Resource objects are a generic mechanism for attaching data to an application
0132  * resource.  The identifier field makes the association to a pointer or handle,
0133  * while the type field helps provide deeper understanding of the identifier as
0134  * well as enabling differentiation in cases where handles generated by different
0135  * APIs may collide.  The resource object may also have an associated message to
0136  * associate with the application resource, enabling further annotation of this
0137  * object and how it is used.
0138  *
0139  * The resource object was introduced in NVTX_VERSION_2 to supersede existing naming
0140  * functions and allow the application resource identified by those functions to be
0141  * associated to a domain.  The other naming functions are still supported for backward
0142  * compatibility but will be associated only to the default domain.
0143  *
0144  * \subsection RESOURCE_NAMING_OS Resource Naming
0145  *
0146  * Some operating system resources creation APIs do not support providing a user friendly
0147  * name, such as some OS thread creation APIs.  This API support resource naming though
0148  * both through resource objects and functions following the pattern
0149  * nvtxName[RESOURCE_TYPE][A|W](identifier, name).  Resource objects introduced in NVTX_VERSION 2
0150  * supersede the other functions with a a more general method of assigning names to OS resources,
0151  * along with associating them to domains too.  The older nvtxName* functions are only associated
0152  * with the default domain.
0153  * \section EXTENSIONS Optional Extensions
0154  * Optional extensions will either appear within the existing sections the extend or appear
0155  * in the "Related Pages" when they introduce new concepts.
0156  */
0157 
0158  /**
0159  * Tools Extension API version
0160  */
0161 #if defined(NVTX_VERSION) && NVTX_VERSION < 3
0162 #error "Trying to #include NVTX version 3 in a source file where an older NVTX version has already been included.  If you are not directly using NVTX (the NVIDIA Tools Extension library), you are getting this error because libraries you are using have included different versions of NVTX.  Suggested solutions are: (1) reorder #includes so the newest NVTX version is included first, (2) avoid using the conflicting libraries in the same .c/.cpp file, or (3) update the library using the older NVTX version to use the newer version instead."
0163 #endif
0164 
0165 #if defined(NVTX_AS_SYSTEM_HEADER)
0166 #if defined(__clang__)
0167 #pragma clang system_header
0168 #elif defined(__GNUC__) || defined(__NVCOMPILER)
0169 #pragma GCC system_header
0170 #elif defined(_MSC_VER)
0171 #pragma system_header
0172 #endif
0173 #endif
0174 
0175 /* Header guard */
0176 #if !defined(NVTX_VERSION)
0177 #define NVTX_VERSION 3
0178 
0179 /* Platform-dependent defines:
0180  *
0181  * - NVTX_API - Calling conventions (only used on Windows, and only effects
0182  *   32-bit x86 builds, i.e. callee pops stack instead of caller)
0183  *
0184  * - NVTX_DYNAMIC_EXPORT - Make function an exported entry point from a
0185  *   dynamic library or shared object.
0186  *
0187  * - NVTX_EXPORT_UNMANGLED_FUNCTION_NAME - When used inside the body of a
0188  *   function declared with NVTX_DYNAMIC_EXPORT, ensures the symbol exported
0189  *   for the function is the exact string of the function's name as written
0190  *   in the code.  Name-mangling or name-decoration is disabled.  Note that
0191  *   on many platforms this is not necessary, since either the function name
0192  *   is already exported verbatim, or the dynamic loader also checks for
0193  *   functions with the mangling applied.  Forcing the exports to avoid any
0194  *   mangling simplifies usage across platforms and from other languages.
0195  */
0196 #if defined(_WIN32)
0197 
0198 #define NVTX_API __stdcall
0199 
0200 #if defined(_MSC_VER)
0201 #define NVTX_DYNAMIC_EXPORT __declspec(dllexport)
0202 #else
0203 #define NVTX_DYNAMIC_EXPORT __attribute__((visibility("default"))) __declspec(dllexport)
0204 #endif
0205 
0206 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_ARM64EC))
0207 #define NVTX_EXPORT_UNMANGLED_FUNCTION_NAME _Pragma("comment(linker, \"/EXPORT:\" __FUNCTION__ \"=\" __FUNCDNAME__)")
0208 #else
0209 #define NVTX_EXPORT_UNMANGLED_FUNCTION_NAME
0210 #endif
0211 
0212 #else /* POSIX-like platform */
0213 
0214 #define NVTX_API
0215 
0216 #define NVTX_DYNAMIC_EXPORT __attribute__((visibility("default")))
0217 
0218 #define NVTX_EXPORT_UNMANGLED_FUNCTION_NAME
0219 
0220 #endif /* Platform-dependent defines */
0221 
0222 /* Compiler-dependent defines:
0223  *
0224  * - NVTX_INLINE_STATIC - Ensure function has internal linkage, and suggest
0225  *   avoiding code-gen of the function.  Without this, function has external
0226  *   linkage with a strong symbol, so linker expects only one definition.
0227  */
0228 #if defined(_MSC_VER)
0229 
0230 #define NVTX_INLINE_STATIC __inline static
0231 
0232 #else /* GCC-like compiler */
0233 
0234 #if defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
0235 #define NVTX_INLINE_STATIC inline static
0236 #else
0237 #define NVTX_INLINE_STATIC __inline__ static
0238 #endif
0239 
0240 #endif /* Compiler-dependent defines */
0241 
0242 #if !defined(NVTX_NULLPTR)
0243 #if defined(__cplusplus) && __cplusplus >= 201103L
0244 #define NVTX_NULLPTR nullptr
0245 #else
0246 #define NVTX_NULLPTR NULL
0247 #endif
0248 #endif
0249 
0250 #if defined(__cplusplus)
0251 #define NVTX_STATIC_CAST(type, value)      (static_cast<type>(value))
0252 #define NVTX_REINTERPRET_CAST(type, value) (reinterpret_cast<type>(value))
0253 #else
0254 #define NVTX_STATIC_CAST(type, value)      ((type)(value))
0255 #define NVTX_REINTERPRET_CAST(type, value) ((type)(value))
0256 #endif
0257 
0258 
0259 /* API linkage/export options:
0260  *
0261  * - By default, the NVTX API functions are declared as "inline", with the
0262  *   implementations provided in the headers.  This allows multiple .c/.cpp
0263  *   files in the same project to include NVTX headers without duplicate-
0264  *   definition linker errors.  An optimizing compiler should inline these
0265  *   implementations, ensuring that the overhead of making an NVTX call is as
0266  *   low as possible, even without enabling link-time optimizations.
0267  *
0268  * - NVTX_NO_IMPL - Use when writing NVTX tools.  If this macro is defined,
0269  *   the NVTX headers will provide all the typedefs, macros, and declarations
0270  *   of API functions (not marked inline), but no function implementations.
0271  *
0272  * - NVTX_EXPORT_API - NVTX is normally used in C/C++ applications by simply
0273  *   including the headers.  There is no need to link with a static library,
0274  *   or to ship a dynamic library with the application (this was changed in
0275  *   NVTX v3).  For other languages, it's not convenient to use a header-only
0276  *   C library.  The best way to provide an idiomatic NVTX API for another
0277  *   language is a .c file that includes the NVTX headers and implements
0278  *   functions for that language using its native calling conventions and
0279  *   datatypes -- this method can allow static linking to avoid depending on
0280  *   a separate dynamic library.  Alternatively, other languages may support
0281  *   using C calling conventions to directly call C functions exported from a
0282  *   dynamic library.  To build such a library, write a .c file that defines
0283  *   NVTX_EXPORT_API and includes any/all of the NVTX headers.  Compile this
0284  *   file as a dynamic library, and the NVTX API functions from the included
0285  *   headers will be exported with no name-mangling or decoration.  Defining
0286  *   ABI-compatible NVTX struct and enum types in the other language is the
0287  *   responsibility of the user of this dynamic library.
0288  *
0289  * Whichever of the above modes is chosen, the following macros are defined
0290  * appropriately below to implement that mode.  These macros are only defined
0291  * if not already defined by the user, so they may be overridden by users to
0292  * handle advanced cases.
0293  *
0294  * - NVTX_DECLSPEC - Specify linkage for NVTX API functions.
0295  *
0296  * - NVTX_SET_NAME_MANGLING_OPTIONS - If necessary for the platform, will use
0297  *   platform-dependent syntax for ensuring function name is exported with no
0298  *   name-mangling or decoration.  Certain compiler and calling-convention
0299  *   combinations will add name-mangling or decorations when exporting NVTX
0300  *   function name symbols, which makes it much harder for other languages
0301  *   to access these functions.  This macro must be used inside a function's
0302  *   body because it uses built-in macros to get the current function's name.
0303  */
0304 #if defined(NVTX_NO_IMPL)
0305 
0306 /* When omitting implementation, avoid declaring functions inline
0307  * without definitions, since this causes compiler warnings. */
0308 #if !defined(NVTX_DECLSPEC)
0309 #define NVTX_DECLSPEC
0310 #endif
0311 #if !defined(NVTX_SET_NAME_MANGLING_OPTIONS)
0312 #define NVTX_SET_NAME_MANGLING_OPTIONS
0313 #endif
0314 
0315 #elif defined(NVTX_EXPORT_API)
0316 
0317 /* Add platform-dependent declaration syntax to ensure NVTX API functions are
0318  * exported when compiling as a dynamic library/shared object, and ensure the
0319  * exported names are not mangled/decorated. */
0320 #if !defined(NVTX_DECLSPEC)
0321 #define NVTX_DECLSPEC NVTX_DYNAMIC_EXPORT
0322 #endif
0323 #if !defined(NVTX_SET_NAME_MANGLING_OPTIONS)
0324 #define NVTX_SET_NAME_MANGLING_OPTIONS NVTX_EXPORT_UNMANGLED_FUNCTION_NAME
0325 #endif
0326 
0327 #else /* Normal NVTX usage */
0328 
0329 /* Functions definitions are provided, and functions are declared inline to
0330  * avoid duplicate-definition linker errors when using multiple source files. */
0331 #if !defined(NVTX_DECLSPEC)
0332 #define NVTX_DECLSPEC NVTX_INLINE_STATIC
0333 #endif
0334 #if !defined(NVTX_SET_NAME_MANGLING_OPTIONS)
0335 #define NVTX_SET_NAME_MANGLING_OPTIONS
0336 #endif
0337 
0338 #endif
0339 
0340 /* Platform-dependent helpers for defining global variables in header files.
0341  * Ensures the linker uses only one instance when multiple source files include
0342  * the headers, avoiding duplicate-definition linker errors. */
0343 #include "nvtxDetail/nvtxLinkOnce.h"
0344 
0345 /* Macros for applying major-version-specific suffix to NVTX global symbols, so
0346  * usage of different versions in different source files is supported without
0347  * violating the one-definition rule. */
0348 #define NVTX_VERSIONED_IDENTIFIER_L3(NAME, VERSION) NAME##_v##VERSION
0349 #define NVTX_VERSIONED_IDENTIFIER_L2(NAME, VERSION) NVTX_VERSIONED_IDENTIFIER_L3(NAME, VERSION)
0350 #define NVTX_VERSIONED_IDENTIFIER(NAME) NVTX_VERSIONED_IDENTIFIER_L2(NAME, NVTX_VERSION)
0351 
0352 /**
0353  * The NVTX library depends on stdint.h.  If the build tool chain in use
0354  * does not include stdint.h, then define NVTX_STDINT_TYPES_ALREADY_DEFINED
0355  * and define the following types:
0356  * <ul>
0357  *   <li>uint8_t
0358  *   <li>int8_t
0359  *   <li>uint16_t
0360  *   <li>int16_t
0361  *   <li>uint32_t
0362  *   <li>int32_t
0363  *   <li>uint64_t
0364  *   <li>int64_t
0365  *   <li>uintptr_t
0366  *   <li>intptr_t
0367  * </ul>
0368  * Be sure to define NVTX_STDINT_TYPES_ALREADY_DEFINED if you are using your
0369  * own definitions instead of stdint.h.
0370  */
0371 #ifndef NVTX_STDINT_TYPES_ALREADY_DEFINED
0372 #include <stdint.h>
0373 #endif
0374 
0375 #include <stddef.h>
0376 
0377 #ifdef __cplusplus
0378 extern "C" {
0379 #endif /* __cplusplus */
0380 
0381 /**
0382 * Result Codes used for the NVTX tool loader.
0383 */
0384 #define NVTX_SUCCESS 0
0385 #define NVTX_FAIL 1
0386 #define NVTX_ERR_INIT_LOAD_PROPERTY 2
0387 #define NVTX_ERR_INIT_ACCESS_LIBRARY 3
0388 #define NVTX_ERR_INIT_LOAD_LIBRARY 4
0389 #define NVTX_ERR_INIT_MISSING_LIBRARY_ENTRY_POINT 5
0390 #define NVTX_ERR_INIT_FAILED_LIBRARY_ENTRY_POINT 6
0391 #define NVTX_ERR_NO_INJECTION_LIBRARY_AVAILABLE 7
0392 
0393 /**
0394  * Size of the nvtxEventAttributes_t structure.
0395  */
0396 #define NVTX_EVENT_ATTRIB_STRUCT_SIZE (NVTX_STATIC_CAST(uint16_t, sizeof(nvtxEventAttributes_t)))
0397 
0398 #define NVTX_NO_PUSH_POP_TRACKING (NVTX_STATIC_CAST(int, -2))
0399 
0400 typedef uint64_t nvtxRangeId_t;
0401 
0402 /* Forward declaration of opaque domain registration structure */
0403 struct nvtxDomainRegistration_st;
0404 typedef struct nvtxDomainRegistration_st nvtxDomainRegistration;
0405 
0406 /* \brief Domain Handle Structure.
0407 * \anchor DOMAIN_HANDLE_STRUCTURE
0408 *
0409 * This structure is opaque to the user and is used as a handle to reference
0410 * a domain.  This type is returned from tools when using the NVTX API to
0411 * create a domain.
0412 *
0413 */
0414 typedef nvtxDomainRegistration* nvtxDomainHandle_t;
0415 
0416 /* Forward declaration of opaque string registration structure */
0417 struct nvtxStringRegistration_st;
0418 typedef struct nvtxStringRegistration_st nvtxStringRegistration;
0419 
0420 /* \brief Registered String Handle Structure.
0421 * \anchor REGISTERED_STRING_HANDLE_STRUCTURE
0422 *
0423 * This structure is opaque to the user and is used as a handle to reference
0424 * a registered string.  This type is returned from tools when using the NVTX
0425 * API to create a registered string.
0426 *
0427 */
0428 typedef nvtxStringRegistration* nvtxStringHandle_t;
0429 
0430 /* ========================================================================= */
0431 /** \defgroup GENERAL General
0432  * @{
0433  */
0434 
0435 /** ---------------------------------------------------------------------------
0436  * Color Types
0437  * ------------------------------------------------------------------------- */
0438 typedef enum nvtxColorType_t
0439 {
0440     NVTX_COLOR_UNKNOWN  = 0,                 /**< Color attribute is unused. */
0441     NVTX_COLOR_ARGB     = 1                  /**< An ARGB color is provided. */
0442 } nvtxColorType_t;
0443 
0444 /** ---------------------------------------------------------------------------
0445  * Message Types
0446  * ------------------------------------------------------------------------- */
0447 typedef enum nvtxMessageType_t
0448 {
0449     NVTX_MESSAGE_UNKNOWN          = 0,    /**< Message attribute is unused. */
0450     NVTX_MESSAGE_TYPE_ASCII       = 1,    /**< A character sequence is used as payload. */
0451     NVTX_MESSAGE_TYPE_UNICODE     = 2,     /**< A wide character sequence is used as payload. */
0452     /* NVTX_VERSION_2 */
0453     NVTX_MESSAGE_TYPE_REGISTERED  = 3     /**< A unique string handle that was registered
0454                                                 with \ref nvtxDomainRegisterStringA() or
0455                                                 \ref nvtxDomainRegisterStringW(). */
0456 } nvtxMessageType_t;
0457 
0458 typedef union nvtxMessageValue_t
0459 {
0460     const char* ascii;
0461     const wchar_t* unicode;
0462     /* NVTX_VERSION_2 */
0463     nvtxStringHandle_t registered;
0464 } nvtxMessageValue_t;
0465 
0466 
0467 /* ------------------------------------------------------------------------- */
0468 /** \brief Force initialization (optional)
0469  * \anchor FORCE_INITIALIZATION
0470 *
0471 * Force NVTX library to initialize.  The first call to any NVTX API function
0472 * will automatically initialize the entire API.  This can make the first call
0473 * much slower than subsequent calls.  In applications where the first call to
0474 * NVTX may be in a performance-critical section, calling nvtxInitialize before
0475 * any performance-critical sections will ensure NVTX initialization occurs at
0476 * an acceptable time.  Since nvtxInitialize takes no parameters and has no
0477 * expected behavior besides initialization, it is convenient to add a call to
0478 * nvtxInitialize in NVTX-instrumented applications that need to force earlier
0479 * initialization without changing any other code.  For example, if an app's
0480 * first NVTX call is nvtxDomainCreate, and it is difficult to move that call
0481 * earlier because the domain handle must be stored in an object only created
0482 * at that point, adding a call to nvtxInitialize at the top of main() will
0483 * ensure the later call to nvtxDomainCreate is as fast as possible.
0484 *
0485 * \version NVTX_VERSION_3
0486 *
0487 * \param reserved - must be zero or NULL.
0488 *
0489 * @{ */
0490 NVTX_DECLSPEC void NVTX_API nvtxInitialize(const void* reserved);
0491 /** @} */
0492 
0493 
0494 /** @} */ /*END defgroup*/
0495 
0496 /* ========================================================================= */
0497 /** \defgroup EVENT_ATTRIBUTES Event Attributes
0498 * @{
0499 */
0500 
0501 /** ---------------------------------------------------------------------------
0502 * Payload Types
0503 * ------------------------------------------------------------------------- */
0504 typedef enum nvtxPayloadType_t
0505 {
0506     NVTX_PAYLOAD_UNKNOWN = 0,   /**< Payload attribute is unused. */
0507     NVTX_PAYLOAD_TYPE_UNSIGNED_INT64 = 1,   /**< A 64 bit unsigned integer value is used as payload. */
0508     NVTX_PAYLOAD_TYPE_INT64 = 2,   /**< A 64 bit signed integer value is used as payload. */
0509     NVTX_PAYLOAD_TYPE_DOUBLE = 3,   /**< A 64 bit floating point value is used as payload. */
0510     /* NVTX_VERSION_2 */
0511     NVTX_PAYLOAD_TYPE_UNSIGNED_INT32 = 4,   /**< A 32 bit floating point value is used as payload. */
0512     NVTX_PAYLOAD_TYPE_INT32 = 5,   /**< A 32 bit floating point value is used as payload. */
0513     NVTX_PAYLOAD_TYPE_FLOAT = 6    /**< A 32 bit floating point value is used as payload. */
0514 } nvtxPayloadType_t;
0515 
0516 /** \brief Event Attribute Structure.
0517  * \anchor EVENT_ATTRIBUTE_STRUCTURE
0518  *
0519  * This structure is used to describe the attributes of an event. The layout of
0520  * the structure is defined by a specific version of the tools extension
0521  * library and can change between different versions of the Tools Extension
0522  * library.
0523  *
0524  * \par Guidelines
0525  * The caller should always perform the following three tasks when using
0526  * attributes:
0527  * <ul>
0528  *    <li>Zero the structure
0529  *    <li>Set the version field
0530  *    <li>Set the size field
0531  * </ul>
0532  *
0533  * Zeroing the structure sets all the event attributes types and values
0534  * to the default value.
0535  *
0536  * The version and size field are used by the Tools Extension
0537  * implementation to handle multiple versions of the attributes structure.
0538  *
0539  * It is recommended that the caller use one of the following to methods
0540  * to initialize the event attributes structure:
0541  *
0542  * \par Method 1
0543  * Initializing nvtxEventAttributes for future compatibility:
0544  * \code
0545  * nvtxEventAttributes_t eventAttrib = {0};
0546  * eventAttrib.version = NVTX_VERSION;
0547  * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
0548  * \endcode
0549  *
0550  * \par Method 2
0551  * Initializing nvtxEventAttributes for a specific version:
0552  * \code
0553  * nvtxEventAttributes_t eventAttrib = {0};
0554  * eventAttrib.version = 1;
0555  * eventAttrib.size = (uint16_t)(sizeof(nvtxEventAttributes_v1));
0556  * \endcode
0557  *
0558  * If the caller uses Method 1 it is critical that the entire binary
0559  * layout of the structure be configured to 0 so that all fields
0560  * are initialized to the default value.
0561  *
0562  * The caller should either use both NVTX_VERSION and
0563  * NVTX_EVENT_ATTRIB_STRUCT_SIZE (Method 1) or use explicit values
0564  * and a versioned type (Method 2).  Using a mix of the two methods
0565  * will likely cause either source level incompatibility or binary
0566  * incompatibility in the future.
0567  *
0568  * \par Example
0569  * Populate an attributes structure:
0570  * \code
0571  * // Initialize
0572  * nvtxEventAttributes_t eventAttrib = {0};
0573  * eventAttrib.version = NVTX_VERSION;
0574  * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
0575  *
0576  * // Configure the Attributes
0577  * eventAttrib.colorType = NVTX_COLOR_ARGB;
0578  * eventAttrib.color = 0xFF880000;
0579  * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
0580  * eventAttrib.message.ascii = "Example";
0581  * \endcode
0582  *
0583  * In the example the caller does not have to set the value of
0584  * \ref ::nvtxEventAttributes_v2::category or
0585  * \ref ::nvtxEventAttributes_v2::payload as these fields were set to
0586  * the default value by {0}.
0587  * \sa
0588  * ::nvtxDomainMarkEx
0589  * ::nvtxDomainRangeStartEx
0590  * ::nvtxDomainRangePushEx
0591  */
0592 typedef struct nvtxEventAttributes_v2
0593 {
0594     /**
0595     * \brief Version flag of the structure.
0596     *
0597     * Needs to be set to NVTX_VERSION to indicate the version of NVTX APIs
0598     * supported in this header file. This can optionally be overridden to
0599     * another version of the tools extension library.
0600     */
0601     uint16_t version;
0602 
0603     /**
0604     * \brief Size of the structure.
0605     *
0606     * Needs to be set to the size in bytes of the event attribute
0607     * structure used to specify the event.
0608     */
0609     uint16_t size;
0610 
0611     /**
0612      * \brief ID of the category the event is assigned to.
0613      *
0614      * A category is a user-controlled ID that can be used to group
0615      * events.  The tool may use category IDs to improve filtering or
0616      * enable grouping of events in the same category. The functions
0617      * \ref ::nvtxNameCategoryA or \ref ::nvtxNameCategoryW can be used
0618      * to name a category.
0619      *
0620      * Default Value is 0
0621      */
0622     uint32_t category;
0623 
0624     /** \brief Color type specified in this attribute structure.
0625      *
0626      * Defines the color format of the attribute structure's \ref COLOR_FIELD
0627      * "color" field.
0628      *
0629      * Default Value is NVTX_COLOR_UNKNOWN
0630      */
0631     int32_t colorType;              /* nvtxColorType_t */
0632 
0633     /** \brief Color assigned to this event. \anchor COLOR_FIELD
0634      *
0635      * The color that the tool should use to visualize the event.
0636      */
0637     uint32_t color;
0638 
0639     /**
0640      * \brief Payload type specified in this attribute structure.
0641      *
0642      * Defines the payload format of the attribute structure's \ref PAYLOAD_FIELD
0643      * "payload" field.
0644      *
0645      * Default Value is NVTX_PAYLOAD_UNKNOWN
0646      */
0647     int32_t payloadType;            /* nvtxPayloadType_t */
0648 
0649     int32_t reserved0;
0650 
0651     /**
0652      * \brief Payload assigned to this event. \anchor PAYLOAD_FIELD
0653      *
0654      * A numerical value that can be used to annotate an event. The tool could
0655      * use the payload data to reconstruct graphs and diagrams.
0656      */
0657     union payload_t
0658     {
0659         uint64_t ullValue;
0660         int64_t llValue;
0661         double dValue;
0662         /* NVTX_VERSION_2 */
0663         uint32_t uiValue;
0664         int32_t iValue;
0665         float fValue;
0666     } payload;
0667 
0668     /** \brief Message type specified in this attribute structure.
0669      *
0670      * Defines the message format of the attribute structure's \ref MESSAGE_FIELD
0671      * "message" field.
0672      *
0673      * Default Value is NVTX_MESSAGE_UNKNOWN
0674      */
0675     int32_t messageType;            /* nvtxMessageType_t */
0676 
0677     /** \brief Message assigned to this attribute structure. \anchor MESSAGE_FIELD
0678      *
0679      * The text message that is attached to an event.
0680      */
0681     nvtxMessageValue_t message;
0682 
0683 } nvtxEventAttributes_v2;
0684 
0685 typedef struct nvtxEventAttributes_v2 nvtxEventAttributes_t;
0686 
0687 /** @} */ /*END defgroup*/
0688 /* ========================================================================= */
0689 /** \defgroup MARKERS_AND_RANGES Markers and Ranges
0690  *
0691  * See \ref MARKERS_AND_RANGES for more details
0692  *
0693  * @{
0694  */
0695 
0696 /** \name Marker */
0697 
0698 /* ------------------------------------------------------------------------- */
0699 /** \brief Marks an instantaneous event in the application.
0700 *
0701 * A marker can contain a text message or specify additional information
0702 * using the event attributes structure.  These attributes include a text
0703 * message, color, category, and a payload. Each of the attributes is optional
0704 * and can only be sent out using the \ref nvtxDomainMarkEx function.
0705 *
0706 * nvtxDomainMarkEx(NULL, event) is equivalent to calling
0707 * nvtxMarkEx(event).
0708 *
0709 * \param domain    - The domain of scoping the category.
0710 * \param eventAttrib - The event attribute structure defining the marker's
0711 * attribute types and attribute values.
0712 *
0713 * \sa
0714 * ::nvtxMarkEx
0715 *
0716 * \version NVTX_VERSION_2
0717 * @{ */
0718 NVTX_DECLSPEC void NVTX_API nvtxDomainMarkEx(nvtxDomainHandle_t domain, const nvtxEventAttributes_t* eventAttrib);
0719 /** @} */
0720 
0721 /* ------------------------------------------------------------------------- */
0722 /** \brief Marks an instantaneous event in the application.
0723  *
0724  * A marker can contain a text message or specify additional information
0725  * using the event attributes structure.  These attributes include a text
0726  * message, color, category, and a payload. Each of the attributes is optional
0727  * and can only be sent out using the \ref nvtxMarkEx function.
0728  * If \ref nvtxMarkA or \ref nvtxMarkW are used to specify the marker
0729  * or if an attribute is unspecified then a default value will be used.
0730  *
0731  * \param eventAttrib - The event attribute structure defining the marker's
0732  * attribute types and attribute values.
0733  *
0734  * \par Example
0735  * Place a mark with attributes:
0736  * \code
0737  * // zero the structure
0738  * nvtxEventAttributes_t eventAttrib = {0};
0739  * // set the version and the size information
0740  * eventAttrib.version = NVTX_VERSION;
0741  * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
0742  * // configure the attributes.  0 is the default for all attributes.
0743  * eventAttrib.colorType = NVTX_COLOR_ARGB;
0744  * eventAttrib.color = 0xFF880000;
0745  * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
0746  * eventAttrib.message.ascii = "Example nvtxMarkEx";
0747  * nvtxMarkEx(&eventAttrib);
0748  * \endcode
0749  *
0750  * \sa
0751  * ::nvtxDomainMarkEx
0752  *
0753  * \version NVTX_VERSION_1
0754  * @{ */
0755 NVTX_DECLSPEC void NVTX_API nvtxMarkEx(const nvtxEventAttributes_t* eventAttrib);
0756 /** @} */
0757 
0758 /* ------------------------------------------------------------------------- */
0759 /** \brief Marks an instantaneous event in the application.
0760  *
0761  * A marker created using \ref nvtxMarkA or \ref nvtxMarkW contains only a
0762  * text message.
0763  *
0764  * \param message     - The message associated to this marker event.
0765  *
0766  * \par Example
0767  * Place a mark:
0768  * \code
0769  * nvtxMarkA("Example nvtxMarkA");
0770  * nvtxMarkW(L"Example nvtxMarkW");
0771  * \endcode
0772  *
0773  * \sa
0774  * ::nvtxDomainMarkEx
0775  * ::nvtxMarkEx
0776  *
0777  * \version NVTX_VERSION_0
0778  * @{ */
0779 NVTX_DECLSPEC void NVTX_API nvtxMarkA(const char* message);
0780 NVTX_DECLSPEC void NVTX_API nvtxMarkW(const wchar_t* message);
0781 /** @} */
0782 
0783 
0784 /** \name Process Ranges */
0785 
0786 /* ------------------------------------------------------------------------- */
0787 /** \brief Starts a process range in a domain.
0788 *
0789 * \param domain    - The domain of scoping the category.
0790 * \param eventAttrib - The event attribute structure defining the range's
0791 * attribute types and attribute values.
0792 *
0793 * \return The unique ID used to correlate a pair of Start and End events.
0794 *
0795 * \remarks Ranges defined by Start/End can overlap.
0796 *
0797 * \par Example
0798 * Start a range with attributes for a domain:
0799 * \code
0800 * nvtxDomainHandle_t domain = nvtxDomainCreateA("my domain");
0801 * nvtxEventAttributes_t eventAttrib = {0};
0802 * eventAttrib.version = NVTX_VERSION;
0803 * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
0804 * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
0805 * eventAttrib.message.ascii = "my range";
0806 * nvtxRangeId_t rangeId = nvtxDomainRangeStartEx(domain, &eventAttrib);
0807 * // ...
0808 * nvtxDomainRangeEnd(domain, rangeId);
0809 * \endcode
0810 *
0811 * \sa
0812 * ::nvtxDomainRangeEnd
0813 *
0814 * \version NVTX_VERSION_2
0815 * @{ */
0816 NVTX_DECLSPEC nvtxRangeId_t NVTX_API nvtxDomainRangeStartEx(nvtxDomainHandle_t domain, const nvtxEventAttributes_t* eventAttrib);
0817 /** @} */
0818 
0819 /* ------------------------------------------------------------------------- */
0820 /** \brief Starts a process range.
0821  *
0822  * \param eventAttrib - The event attribute structure defining the range's
0823  * attribute types and attribute values.
0824  *
0825  * \return The unique ID used to correlate a pair of Start and End events.
0826  *
0827  * \remarks Ranges defined by Start/End can overlap.
0828  *
0829  * \par Example
0830  * Start a range with attributes:
0831  * \code
0832  * nvtxEventAttributes_t eventAttrib = {0};
0833  * eventAttrib.version = NVTX_VERSION;
0834  * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
0835  * eventAttrib.category = 3;
0836  * eventAttrib.colorType = NVTX_COLOR_ARGB;
0837  * eventAttrib.color = 0xFF0088FF;
0838  * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
0839  * eventAttrib.message.ascii = "Example Range";
0840  * nvtxRangeId_t rangeId = nvtxRangeStartEx(&eventAttrib);
0841  * // ...
0842  * nvtxRangeEnd(rangeId);
0843  * \endcode
0844  *
0845  * \sa
0846  * ::nvtxRangeEnd
0847  * ::nvtxDomainRangeStartEx
0848  *
0849  * \version NVTX_VERSION_1
0850  * @{ */
0851 NVTX_DECLSPEC nvtxRangeId_t NVTX_API nvtxRangeStartEx(const nvtxEventAttributes_t* eventAttrib);
0852 /** @} */
0853 
0854 /* ------------------------------------------------------------------------- */
0855 /** \brief Starts a process range.
0856  *
0857  * \param message     - The event message associated to this range event.
0858  *
0859  * \return The unique ID used to correlate a pair of Start and End events.
0860  *
0861  * \remarks Ranges defined by Start/End can overlap.
0862  *
0863  * \par Example
0864  * Start a range:
0865  * \code
0866  * nvtxRangeId_t r1 = nvtxRangeStartA("Range 1");
0867  * nvtxRangeId_t r2 = nvtxRangeStartW(L"Range 2");
0868  * nvtxRangeEnd(r1);
0869  * nvtxRangeEnd(r2);
0870  * \endcode
0871  *
0872  * \sa
0873  * ::nvtxRangeEnd
0874  * ::nvtxRangeStartEx
0875  * ::nvtxDomainRangeStartEx
0876  *
0877  * \version NVTX_VERSION_0
0878  * @{ */
0879 NVTX_DECLSPEC nvtxRangeId_t NVTX_API nvtxRangeStartA(const char* message);
0880 NVTX_DECLSPEC nvtxRangeId_t NVTX_API nvtxRangeStartW(const wchar_t* message);
0881 /** @} */
0882 
0883 /* ------------------------------------------------------------------------- */
0884 /** \brief Ends a process range.
0885 *
0886 * \param domain - The domain
0887 * \param id - The correlation ID returned from a nvtxRangeStart call.
0888 *
0889 * \remarks This function is offered completeness but is an alias for ::nvtxRangeEnd.
0890 * It does not need a domain param since that is associated with the range ID at ::nvtxDomainRangeStartEx
0891 *
0892 * \par Example
0893 * End a range for a domain:
0894 * \code
0895 * nvtxDomainHandle_t domain = nvtxDomainCreateA("my domain");
0896 * nvtxEventAttributes_t eventAttrib = {0};
0897 * eventAttrib.version = NVTX_VERSION;
0898 * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
0899 * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
0900 * eventAttrib.message.ascii = "my range";
0901 * nvtxRangeId_t rangeId = nvtxDomainRangeStartEx(domain, &eventAttrib);
0902 * // ...
0903 * nvtxDomainRangeEnd(domain, rangeId);
0904 * \endcode
0905 *
0906 * \sa
0907 * ::nvtxDomainRangeStartEx
0908 *
0909 * \version NVTX_VERSION_2
0910 * @{ */
0911 NVTX_DECLSPEC void NVTX_API nvtxDomainRangeEnd(nvtxDomainHandle_t domain, nvtxRangeId_t id);
0912 /** @} */
0913 
0914 /* ------------------------------------------------------------------------- */
0915 /** \brief Ends a process range.
0916  *
0917  * \param id - The correlation ID returned from an nvtxRangeStart call.
0918  *
0919  * \sa
0920  * ::nvtxDomainRangeStartEx
0921  * ::nvtxRangeStartEx
0922  * ::nvtxRangeStartA
0923  * ::nvtxRangeStartW
0924  *
0925  * \version NVTX_VERSION_0
0926  * @{ */
0927 NVTX_DECLSPEC void NVTX_API nvtxRangeEnd(nvtxRangeId_t id);
0928 /** @} */
0929 
0930 /** \name Thread Ranges */
0931 
0932 /* ------------------------------------------------------------------------- */
0933 /** \brief Starts a nested thread range.
0934 *
0935 * \param domain    - The domain of scoping.
0936 * \param eventAttrib - The event attribute structure defining the range's
0937 * attribute types and attribute values.
0938 *
0939 * \return The 0 based level of range being started. This value is scoped to the domain.
0940 * If an error occurs, a negative value is returned.
0941 *
0942 * \par Example
0943 * Push a range with attributes for a domain:
0944 * \code
0945 * nvtxDomainHandle_t domain = nvtxDomainCreateA("example domain");
0946 * nvtxEventAttributes_t eventAttrib = {0};
0947 * eventAttrib.version = NVTX_VERSION;
0948 * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
0949 * eventAttrib.colorType = NVTX_COLOR_ARGB;
0950 * eventAttrib.color = 0xFFFF0000;
0951 * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
0952 * eventAttrib.message.ascii = "Level 0";
0953 * nvtxDomainRangePushEx(domain, &eventAttrib);
0954 *
0955 * // Re-use eventAttrib
0956 * eventAttrib.messageType = NVTX_MESSAGE_TYPE_UNICODE;
0957 * eventAttrib.message.unicode = L"Level 1";
0958 * nvtxDomainRangePushEx(domain, &eventAttrib);
0959 *
0960 * nvtxDomainRangePop(domain); // Level 1
0961 * nvtxDomainRangePop(domain); // Level 0
0962 * \endcode
0963 *
0964 * \sa
0965 * ::nvtxDomainRangePop
0966 *
0967 * \version NVTX_VERSION_2
0968 * @{ */
0969 NVTX_DECLSPEC int NVTX_API nvtxDomainRangePushEx(nvtxDomainHandle_t domain, const nvtxEventAttributes_t* eventAttrib);
0970 /** @} */
0971 
0972 /* ------------------------------------------------------------------------- */
0973 /** \brief Starts a nested thread range.
0974  *
0975  * \param eventAttrib - The event attribute structure defining the range's
0976  * attribute types and attribute values.
0977  *
0978  * \return The 0 based level of range being started. This level is per domain.
0979  * If an error occurs a negative value is returned.
0980  *
0981  * \par Example
0982  * Push a range with attributes:
0983  * \code
0984  * nvtxEventAttributes_t eventAttrib = {0};
0985  * eventAttrib.version = NVTX_VERSION;
0986  * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
0987  * eventAttrib.colorType = NVTX_COLOR_ARGB;
0988  * eventAttrib.color = 0xFFFF0000;
0989  * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
0990  * eventAttrib.message.ascii = "Level 0";
0991  * nvtxRangePushEx(&eventAttrib);
0992  *
0993  * // Re-use eventAttrib
0994  * eventAttrib.messageType = NVTX_MESSAGE_TYPE_UNICODE;
0995  * eventAttrib.message.unicode = L"Level 1";
0996  * nvtxRangePushEx(&eventAttrib);
0997  *
0998  * nvtxRangePop(); // Level 1
0999  * nvtxRangePop(); // Level 0
1000  * \endcode
1001  *
1002  * \sa
1003  * ::nvtxDomainRangePushEx
1004  * ::nvtxRangePop
1005  *
1006  * \version NVTX_VERSION_1
1007  * @{ */
1008 NVTX_DECLSPEC int NVTX_API nvtxRangePushEx(const nvtxEventAttributes_t* eventAttrib);
1009 /** @} */
1010 
1011 /* ------------------------------------------------------------------------- */
1012 /** \brief Starts a nested thread range.
1013  *
1014  * \param message     - The event message associated to this range event.
1015  *
1016  * \return The 0 based level of range being started.  If an error occurs a
1017  * negative value is returned.
1018  *
1019  * \par Example
1020  * Push a range:
1021  * \code
1022  * nvtxRangePushA("Level 0");
1023  * nvtxRangePushW(L"Level 1");
1024  * nvtxRangePop(); // Level 1
1025  * nvtxRangePop(); // Level 0
1026  * \endcode
1027  *
1028  * \sa
1029  * ::nvtxDomainRangePushEx
1030  * ::nvtxRangePop
1031  *
1032  * \version NVTX_VERSION_0
1033  * @{ */
1034 NVTX_DECLSPEC int NVTX_API nvtxRangePushA(const char* message);
1035 NVTX_DECLSPEC int NVTX_API nvtxRangePushW(const wchar_t* message);
1036 /** @} */
1037 
1038 
1039 /* ------------------------------------------------------------------------- */
1040 /** \brief Ends a nested thread range.
1041 *
1042 * \return The level of the range being ended. If an error occurs a negative
1043 * value is returned on the current thread.
1044 *
1045 * \par Example
1046 * Pop a range for a domain:
1047 * \code
1048 * nvtxDomainHandle_t domain = nvtxDomainCreateA("example domain");
1049 * nvtxEventAttributes_t eventAttrib = {0};
1050 * eventAttrib.version = NVTX_VERSION;
1051 * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
1052 * eventAttrib.colorType = NVTX_COLOR_ARGB;
1053 * eventAttrib.color = 0xFFFF0000;
1054 * eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
1055 * eventAttrib.message.ascii = "Level 0";
1056 * nvtxDomainRangePushEx(domain, &eventAttrib);
1057 *
1058 * // Re-use eventAttrib
1059 * eventAttrib.messageType = NVTX_MESSAGE_TYPE_UNICODE;
1060 * eventAttrib.message.unicode = L"Level 1";
1061 * nvtxDomainRangePushEx(domain, &eventAttrib);
1062 *
1063 * nvtxDomainRangePop(domain); // Level 1
1064 * nvtxDomainRangePop(domain); // Level 0
1065 * \endcode
1066 *
1067 * \sa
1068 * ::nvtxRangePushEx
1069 * ::nvtxRangePushA
1070 * ::nvtxRangePushW
1071 *
1072 * \version NVTX_VERSION_2
1073 * @{ */
1074 NVTX_DECLSPEC int NVTX_API nvtxDomainRangePop(nvtxDomainHandle_t domain);
1075 /** @} */
1076 
1077 /* ------------------------------------------------------------------------- */
1078 /** \brief Ends a nested thread range.
1079  *
1080  * \return The level of the range being ended. If an error occurs a negative
1081  * value is returned on the current thread.
1082  *
1083  * \par Example
1084  * Pop a range:
1085  * \code
1086  * nvtxRangePushA("Level 0");
1087  * nvtxRangePushW(L"Level 1");
1088  * nvtxRangePop(); // Level 1
1089  * nvtxRangePop(); // Level 0
1090  * \endcode
1091  *
1092  * \sa
1093  * ::nvtxRangePushEx
1094  * ::nvtxRangePushA
1095  * ::nvtxRangePushW
1096  *
1097  * \version NVTX_VERSION_0
1098  * @{ */
1099 NVTX_DECLSPEC int NVTX_API nvtxRangePop(void);
1100 /** @} */
1101 
1102 
1103 /** @} */ /*END defgroup*/
1104 /* ========================================================================= */
1105 /** \defgroup RESOURCE_NAMING Resource Naming
1106  *
1107  * See \ref RESOURCE_NAMING for more details
1108  *
1109  * @{
1110  */
1111 
1112 
1113 /*  ------------------------------------------------------------------------- */
1114 /** \name Functions for Generic Resource Naming*/
1115 /*  ------------------------------------------------------------------------- */
1116 
1117 /*  ------------------------------------------------------------------------- */
1118 /** \cond SHOW_HIDDEN
1119 * \brief Resource typing helpers.
1120 *
1121 * Classes are used to make it easy to create a series of resource types
1122 * per API without collisions
1123 */
1124 #define NVTX_RESOURCE_MAKE_TYPE(CLASS, INDEX) (((NVTX_STATIC_CAST(uint32_t, NVTX_RESOURCE_CLASS_ ## CLASS))<<16)|(NVTX_STATIC_CAST(uint32_t, INDEX)))
1125 #define NVTX_RESOURCE_CLASS_GENERIC 1
1126 /** \endcond */
1127 
1128 /* ------------------------------------------------------------------------- */
1129 /** \brief Generic resource type for when a resource class is not available.
1130 *
1131 * \sa
1132 * ::nvtxDomainResourceCreate
1133 *
1134 * \version NVTX_VERSION_2
1135 */
1136 typedef enum nvtxResourceGenericType_t
1137 {
1138     NVTX_RESOURCE_TYPE_UNKNOWN = 0,
1139     NVTX_RESOURCE_TYPE_GENERIC_POINTER = NVTX_RESOURCE_MAKE_TYPE(GENERIC, 1), /**< Generic pointer assumed to have no collisions with other pointers. */
1140     NVTX_RESOURCE_TYPE_GENERIC_HANDLE = NVTX_RESOURCE_MAKE_TYPE(GENERIC, 2), /**< Generic handle assumed to have no collisions with other handles. */
1141     NVTX_RESOURCE_TYPE_GENERIC_THREAD_NATIVE = NVTX_RESOURCE_MAKE_TYPE(GENERIC, 3), /**< OS native thread identifier. */
1142     NVTX_RESOURCE_TYPE_GENERIC_THREAD_POSIX = NVTX_RESOURCE_MAKE_TYPE(GENERIC, 4) /**< POSIX pthread identifier. */
1143 } nvtxResourceGenericType_t;
1144 
1145 
1146 
1147 /** \brief Resource Attribute Structure.
1148 * \anchor RESOURCE_ATTRIBUTE_STRUCTURE
1149 *
1150 * This structure is used to describe the attributes of a resource. The layout of
1151 * the structure is defined by a specific version of the tools extension
1152 * library and can change between different versions of the Tools Extension
1153 * library.
1154 *
1155 * \par Guidelines
1156 * The caller should always perform the following three tasks when using
1157 * attributes:
1158 * <ul>
1159 *    <li>Zero the structure
1160 *    <li>Set the version field
1161 *    <li>Set the size field
1162 * </ul>
1163 *
1164 * Zeroing the structure sets all the resource attributes types and values
1165 * to the default value.
1166 *
1167 * The version and size field are used by the Tools Extension
1168 * implementation to handle multiple versions of the attributes structure.
1169 *
1170 * It is recommended that the caller use one of the following to methods
1171 * to initialize the event attributes structure:
1172 *
1173 * \par Method 1
1174 * Initializing nvtxEventAttributes for future compatibility:
1175 * \code
1176 * nvtxResourceAttributes_t attribs = {0};
1177 * attribs.version = NVTX_VERSION;
1178 * attribs.size = NVTX_RESOURCE_ATTRIB_STRUCT_SIZE;
1179 * \endcode
1180 *
1181 * \par Method 2
1182 * Initializing nvtxEventAttributes for a specific version:
1183 * \code
1184 * nvtxResourceAttributes_v0 attribs = {0};
1185 * attribs.version = 2;
1186 * attribs.size = (uint16_t)(sizeof(nvtxResourceAttributes_v0));
1187 * \endcode
1188 *
1189 * If the caller uses Method 1 it is critical that the entire binary
1190 * layout of the structure be configured to 0 so that all fields
1191 * are initialized to the default value.
1192 *
1193 * The caller should either use both NVTX_VERSION and
1194 * NVTX_RESOURCE_ATTRIB_STRUCT_SIZE (Method 1) or use explicit values
1195 * and a versioned type (Method 2).  Using a mix of the two methods
1196 * will likely cause either source level incompatibility or binary
1197 * incompatibility in the future.
1198 *
1199 * \par Example
1200 * Register a resource and populate its attributes:
1201 * \code
1202 * nvtxDomainHandle_t domain = nvtxDomainCreateA("example domain");
1203 *
1204 * // Initialize
1205 * nvtxResourceAttributes_t attribs = {0};
1206 * attribs.version = NVTX_VERSION;
1207 * attribs.size = NVTX_RESOURCE_ATTRIB_STRUCT_SIZE;
1208 *
1209 * // Configure the Attributes
1210 * attribs.identifierType = NVTX_RESOURCE_TYPE_GENERIC_POINTER;
1211 * attribs.identifier.pValue = (const void*)pMutex;
1212 * attribs.messageType = NVTX_MESSAGE_TYPE_ASCII;
1213 * attribs.message.ascii = "Single thread access to database.";
1214 *
1215 * nvtxResourceHandle_t handle = nvtxDomainResourceCreate(domain, &attribs);
1216 * \endcode
1217 *
1218 * \sa
1219 * ::nvtxDomainResourceCreate
1220 */
1221 typedef struct nvtxResourceAttributes_v0
1222 {
1223     /**
1224     * \brief Version flag of the structure.
1225     *
1226     * Needs to be set to NVTX_VERSION to indicate the version of NVTX APIs
1227     * supported in this header file. This can optionally be overridden to
1228     * another version of the tools extension library.
1229     */
1230     uint16_t version;
1231 
1232     /**
1233     * \brief Size of the structure.
1234     *
1235     * Needs to be set to the size in bytes of this attribute
1236     * structure.
1237     */
1238     uint16_t size;
1239 
1240     /**
1241     * \brief Identifier type specifies how to interpret the identifier field
1242     *
1243     * Defines the identifier format of the attribute structure's \ref RESOURCE_IDENTIFIER_FIELD
1244     * "identifier" field.
1245     *
1246     * Default Value is NVTX_RESOURCE_TYPE_UNKNOWN
1247     */
1248     int32_t identifierType;            /* values from enums following the pattern nvtxResource[name]Type_t */
1249 
1250     /**
1251     * \brief Identifier for the resource.
1252     * \anchor RESOURCE_IDENTIFIER_FIELD
1253     *
1254     * An identifier may be a pointer or a handle to an OS or middleware API object.
1255     * The resource type will assist in avoiding collisions where handles values may collide.
1256     */
1257     union identifier_t
1258     {
1259         const void* pValue;
1260         uint64_t ullValue;
1261     } identifier;
1262 
1263     /** \brief Message type specified in this attribute structure.
1264     *
1265     * Defines the message format of the attribute structure's \ref RESOURCE_MESSAGE_FIELD
1266     * "message" field.
1267     *
1268     * Default Value is NVTX_MESSAGE_UNKNOWN
1269     */
1270     int32_t messageType;            /* nvtxMessageType_t */
1271 
1272     /** \brief Message assigned to this attribute structure. \anchor RESOURCE_MESSAGE_FIELD
1273     *
1274     * The text message that is attached to a resource.
1275     */
1276     nvtxMessageValue_t message;
1277 
1278 } nvtxResourceAttributes_v0;
1279 
1280 typedef struct nvtxResourceAttributes_v0 nvtxResourceAttributes_t;
1281 
1282 /* \cond SHOW_HIDDEN
1283 * \version NVTX_VERSION_2
1284 */
1285 #define NVTX_RESOURCE_ATTRIB_STRUCT_SIZE (NVTX_STATIC_CAST(uint16_t, sizeof(nvtxResourceAttributes_v0)))
1286 typedef struct nvtxResourceHandle* nvtxResourceHandle_t;
1287 /** \endcond */
1288 
1289 
1290 
1291 /* ------------------------------------------------------------------------- */
1292 /** \brief Create a resource object to track and associate data with OS and middleware objects
1293 *
1294 * Allows users to associate an API handle or pointer with a user-provided name.
1295 *
1296 *
1297 * \param domain - Domain to own the resource object
1298 * \param attribs - Attributes to be associated with the resource
1299 *
1300 * \return A handle that represents the newly created resource object.
1301 *
1302 * \par Example
1303 * Register a resource:
1304 * \code
1305 * nvtxDomainHandle_t domain = nvtxDomainCreateA("example domain");
1306 * nvtxResourceAttributes_t attribs = {0};
1307 * attribs.version = NVTX_VERSION;
1308 * attribs.size = NVTX_RESOURCE_ATTRIB_STRUCT_SIZE;
1309 * attribs.identifierType = NVTX_RESOURCE_TYPE_GENERIC_POINTER;
1310 * attribs.identifier.pValue = (const void*)pMutex;
1311 * attribs.messageType = NVTX_MESSAGE_TYPE_ASCII;
1312 * attribs.message.ascii = "Single thread access to database.";
1313 * nvtxResourceHandle_t handle = nvtxDomainResourceCreate(domain, &attribs);
1314 * \endcode
1315 *
1316 * \sa
1317 * ::nvtxResourceAttributes_t
1318 * ::nvtxDomainResourceDestroy
1319 *
1320 * \version NVTX_VERSION_2
1321 * @{ */
1322 NVTX_DECLSPEC nvtxResourceHandle_t NVTX_API nvtxDomainResourceCreate(nvtxDomainHandle_t domain, nvtxResourceAttributes_t* attribs);
1323 /** @} */
1324 
1325 /* ------------------------------------------------------------------------- */
1326 /** \brief Destroy a resource object to track and associate data with OS and middleware objects
1327 *
1328 * Allows users to associate an API handle or pointer with a user-provided name.
1329 *
1330 * \param resource - Handle to the resource in which to operate.
1331 *
1332 * \par Example
1333 * Unregister a resource:
1334 * \code
1335 * nvtxDomainHandle_t domain = nvtxDomainCreateA("example domain");
1336 * nvtxResourceAttributes_t attribs = {0};
1337 * attribs.version = NVTX_VERSION;
1338 * attribs.size = NVTX_RESOURCE_ATTRIB_STRUCT_SIZE;
1339 * attribs.identifierType = NVTX_RESOURCE_TYPE_GENERIC_POINTER;
1340 * attribs.identifier.pValue = (const void*)pMutex;
1341 * attribs.messageType = NVTX_MESSAGE_TYPE_ASCII;
1342 * attribs.message.ascii = "Single thread access to database.";
1343 * nvtxResourceHandle_t handle = nvtxDomainResourceCreate(domain, &attribs);
1344 * // ...
1345 * nvtxDomainResourceDestroy(handle);
1346 * \endcode
1347 *
1348 * \sa
1349 * ::nvtxDomainResourceCreate
1350 *
1351 * \version NVTX_VERSION_2
1352 * @{ */
1353 NVTX_DECLSPEC void NVTX_API nvtxDomainResourceDestroy(nvtxResourceHandle_t resource);
1354 /** @} */
1355 
1356 
1357 /** \name Functions for NVTX Category Naming*/
1358 
1359 /* ------------------------------------------------------------------------- */
1360 /**
1361 * \brief Annotate an NVTX category used within a domain.
1362 *
1363 * Categories are used to group sets of events. Each category is identified
1364 * through a unique ID and that ID is passed into any of the marker/range
1365 * events to assign that event to a specific category. The nvtxDomainNameCategory
1366 * function calls allow the user to assign a name to a category ID that is
1367 * specific to the domain.
1368 *
1369 * nvtxDomainNameCategory(NULL, category, name) is equivalent to calling
1370 * nvtxNameCategory(category, name).
1371 *
1372 * \param domain    - The domain of scoping the category.
1373 * \param category  - The category ID to name.
1374 * \param name      - The name of the category.
1375 *
1376 * \remarks The category names are tracked per domain.
1377 *
1378 * \par Example
1379 * Assign names to categories in a domain:
1380 * \code
1381 * nvtxDomainHandle_t domain = nvtxDomainCreateA("example");
1382 * nvtxDomainNameCategoryA(domain, 1, "Memory Allocation");
1383 * nvtxDomainNameCategoryW(domain, 2, L"Memory Transfer");
1384 * \endcode
1385 *
1386 * \version NVTX_VERSION_2
1387 * @{ */
1388 NVTX_DECLSPEC void NVTX_API nvtxDomainNameCategoryA(nvtxDomainHandle_t domain, uint32_t category, const char* name);
1389 NVTX_DECLSPEC void NVTX_API nvtxDomainNameCategoryW(nvtxDomainHandle_t domain, uint32_t category, const wchar_t* name);
1390 /** @} */
1391 
1392 /** \brief Annotate an NVTX category.
1393  *
1394  * Categories are used to group sets of events. Each category is identified
1395  * through a unique ID and that ID is passed into any of the marker/range
1396  * events to assign that event to a specific category. The nvtxNameCategory
1397  * function calls allow the user to assign a name to a category ID.
1398  *
1399  * \param category - The category ID to name.
1400  * \param name     - The name of the category.
1401  *
1402  * \remarks The category names are tracked per process.
1403  *
1404  * \par Example
1405  * Assign names to categories:
1406  * \code
1407  * nvtxNameCategory(1, "Memory Allocation");
1408  * nvtxNameCategory(2, "Memory Transfer");
1409  * nvtxNameCategory(3, "Memory Object Lifetime");
1410  * \endcode
1411  *
1412  * \version NVTX_VERSION_1
1413  * @{ */
1414 NVTX_DECLSPEC void NVTX_API nvtxNameCategoryA(uint32_t category, const char* name);
1415 NVTX_DECLSPEC void NVTX_API nvtxNameCategoryW(uint32_t category, const wchar_t* name);
1416 /** @} */
1417 
1418 /** \name Functions for OS Threads Naming*/
1419 
1420 /* ------------------------------------------------------------------------- */
1421 /** \brief Annotate an OS thread.
1422  *
1423  * Allows the user to name an active thread of the current process. If an
1424  * invalid thread ID is provided or a thread ID from a different process is
1425  * used the behavior of the tool is implementation dependent.
1426  *
1427  * Tools expect thread ID to be a number that uniquely identifies the thread
1428  * at the time of the call. Note that a thread's ID can be reused after
1429  * it is destroyed. Tools may choose how to handle aliasing of thread IDs.
1430  *
1431  * POSIX pthread_t type returned by pthread_self() may not comply with these
1432  * expectations. Please use OS-specific thread ID instead of pthread_t.
1433  *
1434  * The thread name is associated to the default domain.  To support domains
1435  * use resource objects via ::nvtxDomainResourceCreate.
1436  *
1437  * \param threadId - The ID of the thread to name.
1438  * \param name     - The name of the thread.
1439  *
1440  * \par Examples
1441  * Name a thread based on the given operating system:
1442  *
1443  * Windows:
1444  * \code
1445  * #include <windows.h>
1446  * nvtxNameOsThread(GetCurrentThreadId(), "Current thread");
1447  * nvtxNameOsThread(GetThreadId(SomeThreadHandle), "Other thread");
1448  * \endcode
1449  *
1450  * Android:
1451  * \code
1452  * #include <unistd.h>
1453  * nvtxNameOsThreadA(gettid(), "Current thread");
1454  * nvtxNameOsThreadA(getpid(), "Main thread");
1455  * \endcode
1456  *
1457  * Linux:
1458  * \code
1459  * #include <sys/syscall.h>
1460  * nvtxNameOsThreadA(syscall(SYS_gettid), "Current thread");
1461  * \endcode
1462  * \code
1463  * #include <unistd.h>
1464  * nvtxNameOsThreadA(getpid(), "Main thread");
1465  * \endcode
1466  *
1467  * macOS:
1468  * \code
1469  * #include <sys/syscall.h>
1470  * nvtxNameOsThreadA(syscall(SYS_thread_selfid), "Current thread");
1471  * \endcode
1472  * \code
1473  * #include <pthread.h>
1474  * __uint64_t id;
1475  * pthread_threadid_np(pthread_self(), &id);
1476  * nvtxNameOsThreadA(id, "Current thread");
1477  * pthread_threadid_np(somePThreadId, &id);
1478  * nvtxNameOsThreadA(id, "Other thread");
1479  * \endcode
1480  *
1481  * \version NVTX_VERSION_1
1482  * @{ */
1483 NVTX_DECLSPEC void NVTX_API nvtxNameOsThreadA(uint32_t threadId, const char* name);
1484 NVTX_DECLSPEC void NVTX_API nvtxNameOsThreadW(uint32_t threadId, const wchar_t* name);
1485 /** @} */
1486 
1487 
1488 /** @} */ /*END defgroup*/
1489 /* ========================================================================= */
1490 /** \defgroup STRING_REGISTRATION String Registration
1491 *
1492 * Registered strings are intended to increase performance by lowering instrumentation
1493 * overhead.  String may be registered once and the handle may be passed in place of
1494 * a string where an the APIs may allow.
1495 *
1496 * See \ref STRING_REGISTRATION for more details
1497 *
1498 * @{
1499 */
1500 
1501 /* ------------------------------------------------------------------------- */
1502 /** \brief Register a string.
1503 
1504 * Registers an immutable string with NVTX. Once registered the pointer used
1505 * to register the domain name can be used in nvtxEventAttributes_t
1506 * \ref MESSAGE_FIELD. This allows NVTX implementation to skip copying the
1507 * contents of the message on each event invocation.
1508 *
1509 * String registration is an optimization. It is recommended to use string
1510 * registration if the string will be passed to an event many times.
1511 *
1512 * String are not unregistered, except that by unregistering the entire domain
1513 *
1514 * \param domain  - Domain handle. If NULL then the global domain is used.
1515 * \param string    - A unique pointer to a sequence of characters.
1516 *
1517 * \return A handle representing the registered string.
1518 *
1519 * \par Example
1520 * Register a string:
1521 * \code
1522 * nvtxDomainHandle_t domain = nvtxDomainCreateA("com.nvidia.nvtx.example");
1523 * nvtxStringHandle_t message = nvtxDomainRegisterStringA(domain, "registered string");
1524 * nvtxEventAttributes_t eventAttrib = {0};
1525 * eventAttrib.version = NVTX_VERSION;
1526 * eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
1527 * eventAttrib.messageType = NVTX_MESSAGE_TYPE_REGISTERED;
1528 * eventAttrib.message.registered = message;
1529 * \endcode
1530 *
1531 * \version NVTX_VERSION_2
1532 * @{ */
1533 NVTX_DECLSPEC nvtxStringHandle_t NVTX_API nvtxDomainRegisterStringA(nvtxDomainHandle_t domain, const char* string);
1534 NVTX_DECLSPEC nvtxStringHandle_t NVTX_API nvtxDomainRegisterStringW(nvtxDomainHandle_t domain, const wchar_t* string);
1535 /** @} */
1536 
1537 /** @} */ /*END defgroup*/
1538 /* ========================================================================= */
1539 /** \defgroup DOMAINS Domains
1540 *
1541 * Domains are used to group events to a developer defined scope. Middleware
1542 * vendors may also scope their own events to avoid collisions with the
1543 * the application developer's events, so that the application developer may
1544 * inspect both parts and easily differentiate or filter them.  By default
1545 * all events are scoped to a global domain where NULL is provided or when
1546 * using APIs provided b versions of NVTX below v2
1547 *
1548 * Domains are intended to be typically long lived objects with the intention
1549 * of logically separating events of large modules from each other such as
1550 * middleware libraries from each other and the main application.
1551 *
1552 * See \ref DOMAINS for more details
1553 *
1554 * @{
1555 */
1556 
1557 /* ------------------------------------------------------------------------- */
1558 /** \brief Register a NVTX domain.
1559 *
1560 * Domains are used to scope annotations. All NVTX_VERSION_0 and NVTX_VERSION_1
1561 * annotations are scoped to the global domain. The function nvtxDomainCreate
1562 * creates a new named domain.
1563 *
1564 * Each domain maintains its own nvtxRangePush and nvtxRangePop stack.
1565 *
1566 * \param name - A unique string representing the domain.
1567 *
1568 * \return A handle representing the domain.
1569 *
1570 * \par Example
1571 * Create a domain:
1572 * \code
1573 * nvtxDomainHandle_t domain = nvtxDomainCreateA("com.nvidia.nvtx.example");
1574 *
1575 * nvtxMarkA("nvtxMarkA to global domain");
1576 *
1577 * nvtxEventAttributes_t eventAttrib1 = {0};
1578 * eventAttrib1.version = NVTX_VERSION;
1579 * eventAttrib1.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
1580 * eventAttrib1.message.ascii = "nvtxDomainMarkEx to global domain";
1581 * nvtxDomainMarkEx(NULL, &eventAttrib1);
1582 *
1583 * nvtxEventAttributes_t eventAttrib2 = {0};
1584 * eventAttrib2.version = NVTX_VERSION;
1585 * eventAttrib2.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
1586 * eventAttrib2.message.ascii = "nvtxDomainMarkEx to com.nvidia.nvtx.example";
1587 * nvtxDomainMarkEx(domain, &eventAttrib2);
1588 *
1589 * nvtxDomainDestroy(domain);
1590 * \endcode
1591 *
1592 * \sa
1593 * ::nvtxDomainDestroy
1594 *
1595 * \version NVTX_VERSION_2
1596 * @{ */
1597 NVTX_DECLSPEC nvtxDomainHandle_t NVTX_API nvtxDomainCreateA(const char* name);
1598 NVTX_DECLSPEC nvtxDomainHandle_t NVTX_API nvtxDomainCreateW(const wchar_t* name);
1599 /** @} */
1600 
1601 /* ------------------------------------------------------------------------- */
1602 /** \brief Unregister a NVTX domain.
1603 *
1604 * Unregisters the domain handle and frees all domain specific resources.
1605 *
1606 * \param domain    - the domain handle
1607 *
1608 * \par Example
1609 * Destroy a domain:
1610 * \code
1611 * nvtxDomainHandle_t domain = nvtxDomainCreateA("com.nvidia.nvtx.example");
1612 * // ...
1613 * nvtxDomainDestroy(domain);
1614 * \endcode
1615 *
1616 * \sa
1617 * ::nvtxDomainCreateA
1618 * ::nvtxDomainCreateW
1619 *
1620 * \version NVTX_VERSION_2
1621 * @{ */
1622 NVTX_DECLSPEC void NVTX_API nvtxDomainDestroy(nvtxDomainHandle_t domain);
1623 /** @} */
1624 
1625 
1626 /** @} */ /*END defgroup*/
1627 /* ========================================================================= */
1628 /** \cond SHOW_HIDDEN */
1629 
1630 #ifdef UNICODE
1631     #define nvtxMark            nvtxMarkW
1632     #define nvtxRangeStart      nvtxRangeStartW
1633     #define nvtxRangePush       nvtxRangePushW
1634     #define nvtxNameCategory    nvtxNameCategoryW
1635     #define nvtxNameOsThread    nvtxNameOsThreadW
1636     /* NVTX_VERSION_2 */
1637     #define nvtxDomainCreate         nvtxDomainCreateW
1638     #define nvtxDomainRegisterString nvtxDomainRegisterStringW
1639     #define nvtxDomainNameCategory   nvtxDomainNameCategoryW
1640 #else
1641     #define nvtxMark            nvtxMarkA
1642     #define nvtxRangeStart      nvtxRangeStartA
1643     #define nvtxRangePush       nvtxRangePushA
1644     #define nvtxNameCategory    nvtxNameCategoryA
1645     #define nvtxNameOsThread    nvtxNameOsThreadA
1646     /* NVTX_VERSION_2 */
1647     #define nvtxDomainCreate         nvtxDomainCreateA
1648     #define nvtxDomainRegisterString nvtxDomainRegisterStringA
1649     #define nvtxDomainNameCategory   nvtxDomainNameCategoryA
1650 #endif
1651 
1652 /** \endcond */
1653 
1654 #ifdef __cplusplus
1655 } /* extern "C" */
1656 #endif /* __cplusplus */
1657 
1658 #define NVTX_IMPL_GUARD /* Ensure other headers cannot be included directly */
1659 
1660 #include "nvtxDetail/nvtxTypes.h"
1661 
1662 #ifndef NVTX_NO_IMPL
1663 #include "nvtxDetail/nvtxImpl.h"
1664 #endif /*NVTX_NO_IMPL*/
1665 
1666 #undef NVTX_IMPL_GUARD
1667 
1668 #endif /* !defined(NVTX_VERSION) */