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 #if defined(NVTX_AS_SYSTEM_HEADER)
0022 #if defined(__clang__)
0023 #pragma clang system_header
0024 #elif defined(__GNUC__) || defined(__NVCOMPILER)
0025 #pragma GCC system_header
0026 #elif defined(_MSC_VER)
0027 #pragma system_header
0028 #endif
0029 #endif
0030 
0031 #include "nvToolsExt.h"
0032 
0033 #ifdef __cplusplus
0034 extern "C" {
0035 #endif /* __cplusplus */
0036 
0037 #ifndef NVTX_EXT_MODULEID_MEM
0038 #define NVTX_EXT_MODULEID_MEM 1
0039 #endif
0040 
0041 /* \cond SHOW_HIDDEN
0042  * \brief A compatibility ID value used in structures and initialization to
0043  * identify version differences.
0044  */
0045 #ifndef NVTX_EXT_COMPATID_MEM
0046 #define NVTX_EXT_COMPATID_MEM 0x0102
0047 #endif
0048 /* \endcond
0049  */
0050 
0051 #ifndef NVTX_MEM_CONTENTS_V1
0052 #define NVTX_MEM_CONTENTS_V1
0053 
0054 /* \cond SHOW_HIDDEN
0055  * \brief This value is returned by functions that return `nvtxMemHeapHandle_t`,
0056  * if a tool is not attached.
0057  */
0058 #define NVTX_MEM_HEAP_HANDLE_NO_TOOL (NVTX_STATIC_CAST(nvtxMemHeapHandle_t, NVTX_STATIC_CAST(intptr_t, -1)))
0059 /* \endcond
0060  */
0061 
0062 /* \cond SHOW_HIDDEN
0063  * \brief This value is returned by functions that return `nvtxMemRegionHandle_t`
0064  * if a tool is not attached.
0065  */
0066 #define NVTX_MEM_REGION_HANDLE_NO_TOOL (NVTX_STATIC_CAST(nvtxMemRegionHandle_t, NVTX_STATIC_CAST(intptr_t, -1)))
0067 /* \endcond
0068  */
0069 
0070 /* \cond SHOW_HIDDEN
0071  * \brief This value is returned by functions that return `nvtxMemPermissionsHandle_t`
0072  * if a tool is not attached.
0073  */
0074 #define NVTX_MEM_PERMISSIONS_HANDLE_NO_TOOL (NVTX_STATIC_CAST(nvtxMemPermissionsHandle_t, -1))
0075 /* \endcond
0076  */
0077 
0078 
0079 /* \cond SHOW_HIDDEN
0080  * \brief This should not be used and is considered an error but defined to
0081  * detect an accidental use of zero or NULL.
0082  */
0083 #define NVTX_MEM_HEAP_USAGE_UNKNOWN 0x0
0084 /* \endcond
0085  */
0086 
0087 
0088 /* \cond SHOW_HIDDEN
0089  * \brief This should not be used and is considered an error but defined to
0090  * detect an accidental use of zero or NULL.
0091  */
0092 #define NVTX_MEM_TYPE_UNKNOWN 0x0
0093 /* \endcond
0094  */
0095 
0096 
0097 /*  ------------------------------------------------------------------------- */
0098 /** \defgroup MEMORY Memory
0099  * See page \ref PAGE_MEMORY.
0100  * @{
0101  */
0102 
0103 /**
0104  * \brief To indicate the full process virtual address space as a heap for
0105  * functions where a nvtxMemHeapHandle_t is accepted.
0106  *
0107  * The heap by default is always read-write-execute permissions without creating regions.
0108  * Regions created in this heap have read-write access by default but not execute.
0109  */
0110 #define NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE (NVTX_STATIC_CAST(nvtxMemHeapHandle_t, 0))
0111 
0112 /** \brief This heap is a sub-allocator.
0113  *
0114  * Heap created with this usage should not be accessed by the user until regions are registered.
0115  * Regions from a heap with this usage have read-write access by default but not execute.
0116  */
0117 #define NVTX_MEM_HEAP_USAGE_TYPE_SUB_ALLOCATOR 0x1
0118 
0119 /**
0120  * \brief This is a heap of memory that has an explicit layout.
0121  *
0122  * The layout could be static or dynamic (calculated). This often represents an algorithm's
0123  * structures that are packed together. By default this heap is assumed to be accessible for
0124  * scopes where the memory is naturally accessible by hardware. Regions may be use to further
0125  * annotate or restrict access. A tool may have an option to be more strict, but special
0126  * consideration must be made for `NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE`.
0127  *
0128  * The behavior of this usage is similar to NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE but
0129  * a tool can use it to track special behaviors and reservation.
0130  *
0131  * Memory in a heap with this usage has read-write permissions by default but not execute without
0132  * creating regions. Regions created in this heap have the same default permission access.
0133  */
0134 #define NVTX_MEM_HEAP_USAGE_TYPE_LAYOUT 0x2
0135 
0136 
0137 /**
0138  * \brief Standard process userspace virtual addresses for linear allocations.
0139  *
0140  * APIs that map into this space, such as CUDA UVA should use this type.
0141  *
0142  * Relevant functions: cudaMalloc, cudaMallocManaged, cudaHostAlloc, cudaMallocHost
0143  * NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE is supported
0144  *
0145  * nvtxMemHeapRegister receives a heapDesc of type nvtxMemVirtualRangeDesc_t
0146  */
0147 #define NVTX_MEM_TYPE_VIRTUAL_ADDRESS 0x1
0148 
0149 
0150 /**
0151  * \brief To indicate you are modifying permissions to the process-wide
0152  * full virtual address space.
0153  *
0154  * This is a companion object to `NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE`.
0155  */
0156 #define NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE (NVTX_STATIC_CAST(nvtxMemPermissionsHandle_t, 0))
0157 
0158 #define NVTX_MEM_PERMISSIONS_CREATE_FLAGS_NONE 0x0
0159 #define NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_READ 0x1
0160 #define NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_WRITE 0x2
0161 #define NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_ATOMIC 0x4
0162 
0163 
0164 /* \cond SHOW_HIDDEN
0165  * \brief Forward declaration of opaque memory heap structure.
0166  */
0167 struct nvtxMemHeap_v1;
0168 typedef struct nvtxMemHeap_v1 nvtxMemHeap_t;
0169 /* \endcond
0170  */
0171 
0172 /** \brief A handle returned by a tool to represent a memory heap. */
0173 typedef nvtxMemHeap_t* nvtxMemHeapHandle_t;
0174 
0175 /* \cond SHOW_HIDDEN
0176  * \brief Forward declaration of opaque memory heap structure.
0177  */
0178 struct nvtxMemRegion_v1;
0179 typedef struct nvtxMemRegion_v1 nvtxMemRegion_t;
0180 /* \endcond
0181  */
0182 
0183 /** \brief A handle returned by a tool to represent a memory region. */
0184 typedef nvtxMemRegion_t* nvtxMemRegionHandle_t;
0185 
0186 /** \brief A reference to a memory region (by pointer or handle).
0187  * Which member of the union will be determined by a type or flag field outside.
0188  */
0189 typedef union nvtxMemRegionRef_t
0190 {
0191     void const* pointer;
0192     nvtxMemRegionHandle_t handle;
0193 } nvtxMemRegionRef_t;
0194 
0195 /* \cond SHOW_HIDDEN
0196  * \brief Forward declaration of opaque memory permissions structure
0197  */
0198 struct nvtxMemPermissions_v1;
0199 typedef struct nvtxMemPermissions_v1 nvtxMemPermissions_t;
0200 /* \endcond
0201  */
0202 
0203 /** \brief A handle returned by a tool to represent a memory permissions mask. */
0204 typedef nvtxMemPermissions_t* nvtxMemPermissionsHandle_t;
0205 
0206 
0207 typedef struct nvtxMemVirtualRangeDesc_v1
0208 {
0209     size_t  size;
0210     void const*  ptr;
0211 } nvtxMemVirtualRangeDesc_v1 ;
0212 typedef nvtxMemVirtualRangeDesc_v1 nvtxMemVirtualRangeDesc_t;
0213 
0214 
0215 /** \brief structure to describe a heap in process virtual memory. */
0216 typedef struct nvtxMemHeapDesc_v1
0217 {
0218     uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
0219     uint16_t structSize; /* Size of the structure. */
0220     uint32_t reserved0;
0221 
0222     /** \brief Usage characteristics of the heap
0223      *
0224      * Usage characteristics help tools like memcheckers, sanitizers,
0225      * as well as other debugging and profiling tools to determine some
0226      * special behaviors they should apply to the heap and its regions.
0227      * The value follows the convention NVTX_MEM_HEAP_USAGE_*
0228      *
0229      * Default Value is 0, which is invalid.
0230      */
0231     uint32_t usage;
0232 
0233     /** \brief Memory type characteristics of the heap
0234      *
0235      * The 'type' indicates how to interpret the ptr field of the heapDesc.
0236      * This is intended to support many additional types of memory, beyond
0237      * standard process virtual memory, such as API specific memory only
0238      * addressed by handles or multi-dimensional memory requiring more complex
0239      * descriptions to handle features like strides, tiling, or interlace.
0240      *
0241      * The values conforms to NVTX_MEM_TYPE_*
0242      *
0243      * The value in the field 'type' identifies the descriptor type that will
0244      * be in the field 'typeSpecificDesc'.  'typeSpecificDesc' is void* because
0245      * it is extensible.  Example usage is if type is NVTX_MEM_TYPE_VIRTUAL_ADDRESS,
0246      * then typeSpecificDesc points to a nvtxMemVirtualRangeDesc_t.
0247      *
0248      * Default Value is 0, which is invalid.
0249      */
0250     uint32_t type;
0251 
0252     /** \brief size of the heap memory descriptor pointed to by typeSpecificDesc
0253      *
0254      * Default Value is 0 which is invalid.
0255      */
0256     size_t typeSpecificDescSize;
0257 
0258     /** \brief Pointer to the heap memory descriptor
0259      *
0260      * The value in the field 'type' identifies the descriptor type that will
0261      * be in the field 'typeSpecificDesc'.  'typeSpecificDesc' is void* because
0262      * it is extensible.  Example usage is if type is NVTX_MEM_TYPE_VIRTUAL_ADDRESS,
0263      * then typeSpecificDesc points to a nvtxMemVirtualRangeDesc_t.
0264      *
0265      * Default Value is 0, which is invalid.
0266      */
0267     void const* typeSpecificDesc;
0268 
0269     /** \brief ID of the category the event is assigned to.
0270      *
0271      * A category is a user-controlled ID that can be used to group
0272      * events.  The tool may use category IDs to improve filtering or
0273      * enable grouping of events in the same category. The functions
0274      * \ref ::nvtxNameCategoryA or \ref ::nvtxNameCategoryW can be used
0275      * to name a category.
0276      *
0277      * Default Value is 0.
0278      */
0279     uint32_t category;
0280 
0281     /** \brief Message type specified in this attribute structure.
0282      *
0283      * Defines the message format of the attribute structure's \ref MEM_MESSAGE_FIELD
0284      * "message" field.
0285      *
0286      * Default Value is `NVTX_MESSAGE_UNKNOWN`.
0287      */
0288     uint32_t messageType;            /* nvtxMessageType_t */
0289 
0290     /** \brief Message assigned to this attribute structure. \anchor MEM_MESSAGE_FIELD
0291      *
0292      * The text message that is attached to an event.
0293      */
0294     nvtxMessageValue_t message;
0295 
0296 } nvtxMemHeapDesc_v1 ;
0297 typedef nvtxMemHeapDesc_v1 nvtxMemHeapDesc_t;
0298 
0299 /**
0300  * \brief Create a memory heap to represent a object or range of memory that will be further
0301  * sub-divided into regions.
0302  *
0303  * The handle used to address the heap will depend on the heap's type.  Where the heap is virtual
0304  * memory accessible, the address of the heap's memory itself is its handle. This will likewise
0305  * be returned from the function.
0306  *
0307  * For more advanced types, where the heap is not virtual memory accessible the tools may be
0308  * responsible for returning a void const * that that uniquely identifies the object. Please see
0309  * the description of each heap type for more details on whether this is expected to be a uniquely
0310  * generated by the tool or otherwise.
0311  */
0312 NVTX_DECLSPEC nvtxMemHeapHandle_t NVTX_API nvtxMemHeapRegister(
0313     nvtxDomainHandle_t domain,
0314     nvtxMemHeapDesc_t const* desc);
0315 
0316  /** \brief Destroy a memory heap. */
0317 NVTX_DECLSPEC void NVTX_API nvtxMemHeapUnregister(
0318     nvtxDomainHandle_t domain,
0319     nvtxMemHeapHandle_t heap);/* NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE is not supported */
0320 
0321 /**
0322  * \brief Reset the memory heap wipes out any changes, as if it were a fresh heap.
0323  *
0324  * This includes invalidating all regions and their handles.
0325  */
0326 NVTX_DECLSPEC void NVTX_API nvtxMemHeapReset(
0327     nvtxDomainHandle_t domain,
0328     nvtxMemHeapHandle_t heap); /* NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE is supported */
0329 
0330 /**
0331  * \brief Register a region of memory inside of a heap.
0332  *
0333  * The heap refers the the heap within which the region resides. This can be from
0334  * `nvtxMemHeapRegister`, `NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE`, or one provided
0335  * from other extension API.
0336  *
0337  * The regionType arg will define which type is used in regionDescArray.
0338  * The most commonly used type is `NVTX_MEM_TYPE_VIRTUAL_ADDRESS`.
0339  * In this case regionDescElements is an array of `nvtxMemVirtualRangeDesc_t`.
0340  *
0341  * The regionCount arg is how many element are in regionDescArray and regionHandleArrayOut.
0342  *
0343  * The regionHandleArrayOut arg points to an array where the tool will provide region handles. If
0344  * a pointer is provided, it is expected to have regionCount elements. This pointer can be NULL if
0345  * regionType is NVTX_MEM_TYPE_VIRTUAL_ADDRESS. In this case, the user can use the pointer to the
0346  * virtual memory to reference the region in other related functions which accept nvtxMemRegionRef_t.
0347  */
0348 typedef struct nvtxMemRegionsRegisterBatch_v1
0349 {
0350     uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
0351     uint16_t structSize; /* Size of the structure. */
0352 
0353     uint32_t regionType; /* NVTX_MEM_TYPE_* */
0354 
0355     nvtxMemHeapHandle_t heap;
0356 
0357     size_t regionCount;
0358     size_t regionDescElementSize;
0359     void const* regionDescElements; /* This will also become the handle for this region. */
0360     nvtxMemRegionHandle_t* regionHandleElementsOut; /* This will also become the handle for this region. */
0361 
0362 } nvtxMemRegionsRegisterBatch_v1;
0363 typedef nvtxMemRegionsRegisterBatch_v1 nvtxMemRegionsRegisterBatch_t;
0364 
0365  /** \brief Register a region of memory inside of a heap of linear process virtual memory
0366  */
0367 NVTX_DECLSPEC void NVTX_API nvtxMemRegionsRegister(
0368     nvtxDomainHandle_t domain,
0369     nvtxMemRegionsRegisterBatch_t const* desc);
0370 
0371 
0372 
0373 /**
0374  * \brief Register a region of memory inside of a heap.
0375  *
0376  * The heap refers the the heap within which the region resides.
0377  * This can be from nvtxMemHeapRegister, NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE, or
0378  * one provided from other extension API.
0379  *
0380  * The regionType arg will define which type is used in regionDescArray.
0381  * The most commonly used type is NVTX_MEM_TYPE_VIRTUAL_ADDRESS.
0382  *
0383  * The regionCount arg is how many element are in regionDescArray and regionHandleArrayOut.
0384  *
0385  * The regionHandleArrayOut arg points to an array where the tool will provide region handles. If
0386  * a pointer if provided, it is expected to have regionCount elements. This pointer can be NULL if
0387  * regionType is NVTX_MEM_TYPE_VIRTUAL_ADDRESS. In this case, the user can use the pointer to the
0388  * virtual memory to reference the region in other related functions which accept nvtxMemRegionRef_t.
0389  */
0390 typedef struct nvtxMemRegionsResizeBatch_v1
0391 {
0392     uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
0393     uint16_t structSize; /* Size of the structure. */
0394 
0395     uint32_t regionType; /* NVTX_MEM_TYPE_* */
0396 
0397     size_t regionDescCount;
0398     size_t regionDescElementSize;
0399     void const* regionDescElements; /* This will also become the handle for this region. */
0400 
0401 } nvtxMemRegionsResizeBatch_v1;
0402 typedef nvtxMemRegionsResizeBatch_v1 nvtxMemRegionsResizeBatch_t;
0403 
0404  /** \brief Register a region of memory inside of a heap of linear process virtual memory
0405  */
0406 NVTX_DECLSPEC void NVTX_API nvtxMemRegionsResize(
0407     nvtxDomainHandle_t domain,
0408     nvtxMemRegionsResizeBatch_t const* desc);
0409 
0410 
0411 #define NVTX_MEM_REGION_REF_TYPE_UNKNOWN 0x0
0412 #define NVTX_MEM_REGION_REF_TYPE_POINTER 0x1
0413 #define NVTX_MEM_REGION_REF_TYPE_HANDLE 0x2
0414 
0415 /**
0416  * \brief Register a region of memory inside of a heap.
0417  *
0418  * The heap refers the the heap within which the region resides.
0419  * This can be from nvtxMemHeapRegister, `NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE`, or
0420  * one provided from other extension API.
0421  *
0422  * The regionType arg will define which type is used in `regionDescArray`.
0423  * The most commonly used type is NVTX_MEM_TYPE_VIRTUAL_ADDRESS.
0424  *
0425  * The regionCount arg is how many element are in regionDescArray and regionHandleArrayOut.
0426  *
0427  * The regionHandleArrayOut arg points to an array where the tool will provide region handles.
0428  * If a pointer if provided, it is expected to have regionCount elements.
0429  * This pointer can be NULL if regionType is NVTX_MEM_TYPE_VIRTUAL_ADDRESS.  In this case,
0430  * the user can use the pointer to the virtual memory to reference the region in other
0431  * related functions which accept a nvtxMemRegionRef_t.
0432  */
0433 typedef struct nvtxMemRegionsUnregisterBatch_v1
0434 {
0435     uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
0436     uint16_t structSize; /* Size of the structure. */
0437 
0438     uint32_t refType; /* NVTX_MEM_REGION_REF_TYPE_* */
0439 
0440     size_t refCount; /* count of elements in refArray */
0441     size_t refElementSize;
0442     nvtxMemRegionRef_t const* refElements; /* This will also become the handle for this region. */
0443 
0444 } nvtxMemRegionsUnregisterBatch_v1;
0445 typedef nvtxMemRegionsUnregisterBatch_v1 nvtxMemRegionsUnregisterBatch_t;
0446 
0447 /**
0448  * \brief Unregistration for regions of process virtual memory
0449  *
0450  * This is not necessary if the nvtx heap destroy function has been called that
0451  * contains this object.
0452  */
0453 NVTX_DECLSPEC void NVTX_API nvtxMemRegionsUnregister(
0454     nvtxDomainHandle_t domain,
0455     nvtxMemRegionsUnregisterBatch_t const* desc);
0456 
0457 typedef struct nvtxMemRegionNameDesc_v1
0458 {
0459     uint32_t regionRefType; /* NVTX_MEM_REGION_REF_TYPE_* */
0460     uint32_t nameType; /* nvtxMessageType_t */
0461 
0462     nvtxMemRegionRef_t region;
0463     nvtxMessageValue_t name;
0464 
0465     uint32_t category;
0466     uint32_t reserved0;
0467 } nvtxMemRegionNameDesc_v1;
0468 typedef nvtxMemRegionNameDesc_v1 nvtxMemRegionNameDesc_t;
0469 
0470 
0471 typedef struct nvtxMemRegionsNameBatch_v1
0472 {
0473     uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
0474     uint16_t structSize; /* Size of the structure. */
0475 
0476     uint32_t reserved0;
0477 
0478     size_t regionCount;
0479     size_t regionElementSize;
0480     nvtxMemRegionNameDesc_t const* regionElements;
0481     size_t reserved1;
0482 } nvtxMemRegionsNameBatch_v1 ;
0483 typedef nvtxMemRegionsNameBatch_v1 nvtxMemRegionsNameBatch_t;
0484 
0485 
0486  /** \brief Name or rename a region. */
0487 NVTX_DECLSPEC void NVTX_API nvtxMemRegionsName(
0488     nvtxDomainHandle_t domain,
0489     nvtxMemRegionsNameBatch_t const* desc);
0490 
0491 /** \brief There are no permissions for this memory. */
0492 #define NVTX_MEM_PERMISSIONS_REGION_FLAGS_NONE 0x0
0493 
0494 /** \brief The memory is readable. */
0495 #define NVTX_MEM_PERMISSIONS_REGION_FLAGS_READ 0x1
0496 
0497 /** \brief The memory is writable. */
0498 #define NVTX_MEM_PERMISSIONS_REGION_FLAGS_WRITE 0x2
0499 
0500 /** \brief The memory is for atomic RW. */
0501 #define NVTX_MEM_PERMISSIONS_REGION_FLAGS_ATOMIC 0x4
0502 
0503 /**
0504  * \brief The memory access permissions are reset for a region.
0505  *
0506  * This is as if never set, rather than documented defaults.  As as result any flags
0507  * indicating how unspecified regions are handle will affect this area.
0508  *
0509  * This should not be used with READ, WRITE, nor ATOMIC, as those flags would have no effect.
0510  */
0511 #define NVTX_MEM_PERMISSIONS_REGION_FLAGS_RESET 0x8
0512 
0513 
0514 typedef struct nvtxMemPermissionsAssignRegionDesc_v1
0515 {
0516     uint32_t flags; /* NVTX_MEM_PERMISSIONS_REGION_FLAGS_* */
0517     uint32_t regionRefType; /* NVTX_MEM_REGION_REF_TYPE_* */
0518     nvtxMemRegionRef_t region;
0519 
0520 } nvtxMemPermissionsAssignRegionDesc_v1 ;
0521 typedef nvtxMemPermissionsAssignRegionDesc_v1 nvtxMemPermissionsAssignRegionDesc_t;
0522 
0523 
0524 typedef struct nvtxMemPermissionsAssignBatch_v1
0525 {
0526     uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
0527     uint16_t structSize; /* Size of the structure. */
0528 
0529     uint32_t reserved0;
0530 
0531     nvtxMemPermissionsHandle_t permissions;
0532 
0533     size_t regionCount;
0534     size_t regionElementSize;
0535     nvtxMemPermissionsAssignRegionDesc_t const* regionElements;
0536 
0537     size_t reserved1;
0538 } nvtxMemPermissionsAssignBatch_v1 ;
0539 typedef nvtxMemPermissionsAssignBatch_v1 nvtxMemPermissionsAssignBatch_t;
0540 
0541 
0542  /** \brief Change the permissions of a region of process virtual memory. */
0543 NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsAssign(
0544     nvtxDomainHandle_t domain,
0545     nvtxMemPermissionsAssignBatch_t const* desc);
0546 
0547 
0548 /**
0549  * \brief Create a permissions object for fine grain thread-local control in
0550  * multi-threading scenarios
0551  *
0552  * Unlike the global permissions object (NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE), a new
0553  * permissions object is empty. There are no regions registered to it, so more memory is accessible
0554  * if bound(bind) without calls to nvtxMemPermissionsSetAccess* first. The permissions are not
0555  * active until nvtxMemPermissionsBind. See `nvtxMemPermissionsBind` for more details.
0556  *
0557  * Use the flags NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_* to control  how the regions in
0558  * this permission object will interact with global permissions when bound. You may choose to
0559  * either replace global memory regions setting or overlay on top of them. The most common uses are
0560  * as follows:
0561  *     * To limit tools to validate writing exclusively specified in this object but inherit all
0562  *       global read access regions use `NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_WRITE`
0563  *     * To limit tools to validate both read & write permissions exclusively specified in this
0564  *        object use NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_READ
0565  *                   & NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_WRITE
0566  *
0567  * Also see `nvtxMemPermissionsBind` & `nvtxMemPermissionsSetAccess*`.
0568  */
0569 NVTX_DECLSPEC nvtxMemPermissionsHandle_t NVTX_API nvtxMemPermissionsCreate(
0570     nvtxDomainHandle_t domain,
0571     int32_t creationflags); /* NVTX_MEM_PERMISSIONS_CREATE_FLAGS_* */
0572 
0573 /**
0574  * \brief Destroy the permissions object.
0575  *
0576  * If bound(bind), destroy will also unbind it.
0577  */
0578 NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsDestroy(
0579     nvtxDomainHandle_t domain,
0580     nvtxMemPermissionsHandle_t permissionsHandle); /* only supported on objects from nvtxMemPermissionsCreate */
0581 
0582 /** \brief Reset the permissions object back to its created state. */
0583 NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsReset(
0584     nvtxDomainHandle_t domain,
0585     nvtxMemPermissionsHandle_t permissionsHandle);
0586 /* NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE and other special handles are supported */
0587 
0588 
0589 #define NVTX_MEM_PERMISSIONS_BIND_FLAGS_NONE 0x0
0590 
0591  /** \brief Upon binding, with the thread, exclude parent scope write regions instead of overlaying on top of them.
0592   *
0593    * EX A developer may chose to first prevent all writes except the ones specified to avoid
0594   * OOB writes, since there are typically fewer regions written to than read from.
0595  **/
0596 #define NVTX_MEM_PERMISSIONS_BIND_FLAGS_STRICT_WRITE 0x2
0597 
0598  /** \brief Upon binding, with the thread, exclude parent scope read regions instead of overlaying on top of them.
0599   *
0600   * EX After eliminating any errors when applying strict writes, a developer may then choose to
0601   * annotate and enforce strict reads behaviors in segments of code.
0602  **/
0603 #define NVTX_MEM_PERMISSIONS_BIND_FLAGS_STRICT_READ 0x1
0604 
0605  /** \brief Upon binding, with the thread, exclude parent scope atomic RW regions instead of overlaying on top of them.
0606   *
0607   * EX After eliminating any errors from read and write, a developer may chose to ensure
0608   * that atomics are in their own region, removing standard read/write, and replacing with
0609   * this strict atomic only access.  This way they know that conventional reads or writes
0610   * will not cause unexpected issues.
0611  **/
0612 #define NVTX_MEM_PERMISSIONS_BIND_FLAGS_STRICT_ATOMIC 0x4
0613 
0614 
0615 #define NVTX_MEM_PERMISSIONS_BIND_SCOPE_UNKNOWN 0x0
0616 
0617  /** \brief Bind to thread scope.  In this case, tools should validate that local thread's
0618   * execution is honoring the permissions as well as the state of NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE
0619   * at the time of binding.  If this is not bound then NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE should be
0620   * used to validate the memory.
0621   *
0622   * Not all tools will support every scope, such a GPU sanitizer.
0623  **/
0624 #define NVTX_MEM_PERMISSIONS_BIND_SCOPE_CPU_THREAD 0x1
0625 
0626 /**
0627  * \brief Bind to CUDA stream scope.
0628  *
0629  * In this case, work enqueued to a CUDA stream should be validated by the tool,
0630  * when it executes, that it respect the permission of the permission at the point
0631  * of binding, as well as the appropriate nvtxMemCudaGetDevicePermissions at the
0632  * time of binding. If this is not bound then nvtxMemCudaGetDevicePermissions at
0633  * the time of stream enqueue should be used to validate the memory.
0634  *
0635  * This could apply to work done either on the GPU like a kernel launch or to
0636  * CPU based callbacks like cudaStreamAddCallback if the tools supports it.
0637  *
0638  * Binding is applies locally to a CPU thread so that if N CPU threads are enqueuing
0639  * work to the same stream (like the default stream) that there cannot be a race
0640  * condition between thread binding vs launching their work. IE users should
0641  * expect the permissions bound in the thread to be honored by the proceeding
0642  * work (launches, copies, etc) invoked from in the CPU thread until unbound.
0643  */
0644 #define NVTX_MEM_PERMISSIONS_BIND_SCOPE_CUDA_STREAM 0x2
0645 
0646 
0647 /**
0648  * \brief Bind the permissions object into a particular scope on the caller thread
0649  *
0650  * Permissions do not take affect until binding. Binding permissions is a thread local
0651  * activity that overrides global behaviors.  This is to avoid multi-threaded race conditions,
0652  *
0653  * The scope dictates what type of processing it applies to, and when in some cases.
0654  * EX1: NVTX_MEM_PERMISSIONS_BIND_SCOPE_CPU_THREAD applies to CPU code accessing memory while bound.
0655  * EX2: NVTX_MEM_PERMISSIONS_BIND_SCOPE_CUDA_STREAM applies to CUDA streams, and the permissions
0656  * must be recorded and applied when the work in the stream dequeues to executes.  In this case
0657  * it could be GPU or CPU, if the tool support both.
0658  *
0659  * Bind can be called again on the same object and thread to take any updates to the
0660  * specified permission object or the inherited properties.
0661  *
0662  * Bind flags support changing how the binding process inherits region access control.
0663  * In the case of thread scope this is NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE and from CUDA_STREAM
0664  * this is nvtxMemCudaGetDevicePermissions.  Choosing stricter modes allows the user to
0665  * further reduce the access with less work, since memory by default, behaves as natural
0666  * until the NVTX annotations instructs a tool to treat it anther way.  See strict flags
0667  * for more details.
0668  *
0669  * Also see nvtxMemPermissionsUnbind
0670  */
0671 NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsBind(
0672     nvtxDomainHandle_t domain,
0673     nvtxMemPermissionsHandle_t permissions, /* special object like NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE are not supported */
0674     uint32_t bindScope, /* NVTX_MEM_PERMISSIONS_BIND_SCOPE_* */
0675     uint32_t bindFlags); /* NVTX_MEM_PERMISSIONS_BIND_FLAGS_* */
0676 
0677 /**
0678  * \brief Unbind the permissions object bound to the caller thread.
0679  *
0680  * Upon unbind, the thread local permissions for a scope are restored to the default
0681  * behavior defined by the scope.
0682  */
0683 NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsUnbind(
0684     nvtxDomainHandle_t domain,
0685     uint32_t bindScope);
0686 
0687 /** @} */
0688 
0689 #endif /* NVTX_MEM_CONTENTS_V1 */
0690 
0691 #ifndef NVTX_MEM_CALLBACK_ID_V1
0692 #define NVTX_MEM_CALLBACK_ID_V1
0693 
0694 #define NVTX3EXT_CBID_nvtxMemHeapRegister                  0
0695 #define NVTX3EXT_CBID_nvtxMemHeapUnregister                1
0696 #define NVTX3EXT_CBID_nvtxMemHeapReset                     2
0697 #define NVTX3EXT_CBID_nvtxMemRegionsRegister               3
0698 #define NVTX3EXT_CBID_nvtxMemRegionsResize                 4
0699 #define NVTX3EXT_CBID_nvtxMemRegionsUnregister             5
0700 #define NVTX3EXT_CBID_nvtxMemRegionsName                   6
0701 #define NVTX3EXT_CBID_nvtxMemPermissionsAssign             7
0702 #define NVTX3EXT_CBID_nvtxMemPermissionsCreate             8
0703 #define NVTX3EXT_CBID_nvtxMemPermissionsDestroy            9
0704 #define NVTX3EXT_CBID_nvtxMemPermissionsReset              10
0705 #define NVTX3EXT_CBID_nvtxMemPermissionsBind               11
0706 #define NVTX3EXT_CBID_nvtxMemPermissionsUnbind             12
0707 
0708 /* 13-16 in nvtxExtImplMemCudaRt_v1.h */
0709 #define NVTX3EXT_CBID_nvtxMemCudaGetProcessWidePermissions 13
0710 #define NVTX3EXT_CBID_nvtxMemCudaGetDeviceWidePermissions  14
0711 #define NVTX3EXT_CBID_nvtxMemCudaSetPeerAccess             15
0712 #define NVTX3EXT_CBID_nvtxMemCudaMarkInitialized           16
0713 
0714 #endif /* NVTX_MEM_CALLBACK_ID_V1 */
0715 
0716 /* Macros to create versioned symbols. */
0717 #ifndef NVTX_EXT_MEM_VERSIONED_IDENTIFIERS_V1
0718 #define NVTX_EXT_MEM_VERSIONED_IDENTIFIERS_V1
0719 #define NVTX_EXT_MEM_VERSIONED_IDENTIFIER_L3(NAME, VERSION, COMPATID) \
0720     NAME##_v##VERSION##_mem##COMPATID
0721 #define NVTX_EXT_MEM_VERSIONED_IDENTIFIER_L2(NAME, VERSION, COMPATID) \
0722     NVTX_EXT_MEM_VERSIONED_IDENTIFIER_L3(NAME, VERSION, COMPATID)
0723 #define NVTX_EXT_MEM_VERSIONED_ID(NAME) \
0724     NVTX_EXT_MEM_VERSIONED_IDENTIFIER_L2(NAME, NVTX_VERSION, NVTX_EXT_COMPATID_MEM)
0725 #endif /* NVTX_EXT_MEM_VERSIONED_IDENTIFIERS_V1 */
0726 
0727 #ifdef __GNUC__
0728 #pragma GCC visibility push(internal)
0729 #endif
0730 
0731 /* Extension types are required for the implementation and the NVTX handler. */
0732 #define NVTX_EXT_TYPES_GUARD /* Ensure other headers cannot be included directly */
0733 #include "nvtxDetail/nvtxExtTypes.h"
0734 #undef NVTX_EXT_TYPES_GUARD
0735 
0736 #ifndef NVTX_NO_IMPL
0737 /* Ensure other headers cannot be included directly */
0738 #define NVTX_EXT_IMPL_MEM_GUARD
0739 #include "nvtxDetail/nvtxExtImplMem_v1.h"
0740 #undef NVTX_EXT_IMPL_MEM_GUARD
0741 #endif /*NVTX_NO_IMPL*/
0742 
0743 #ifdef __GNUC__
0744 #pragma GCC visibility pop
0745 #endif
0746 
0747 #ifdef __cplusplus
0748 }
0749 #endif /* __cplusplus */