NVTX C API Reference v3
NVIDIA Tools Extension Library
Loading...
Searching...
No Matches
nvToolsExtMem.h
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2009-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Licensed under the Apache License v2.0 with LLVM Exceptions.
18 * See https://nvidia.github.io/NVTX/LICENSE.txt for license information.
19 */
20
21#if defined(NVTX_AS_SYSTEM_HEADER)
22#if defined(__clang__)
23#pragma clang system_header
24#elif defined(__GNUC__) || defined(__NVCOMPILER)
25#pragma GCC system_header
26#elif defined(_MSC_VER)
27#pragma system_header
28#endif
29#endif
30
31#include "nvToolsExt.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif /* __cplusplus */
36
37#ifndef NVTX_EXT_MODULEID_MEM
38#define NVTX_EXT_MODULEID_MEM 1
39#endif
40
41/* \cond SHOW_HIDDEN
42 * \brief A compatibility ID value used in structures and initialization to
43 * identify version differences.
44 */
45#ifndef NVTX_EXT_COMPATID_MEM
46#define NVTX_EXT_COMPATID_MEM 0x0102
47#endif
48/* \endcond
49 */
50
51#ifndef NVTX_MEM_CONTENTS_V1
52#define NVTX_MEM_CONTENTS_V1
53
54/* \cond SHOW_HIDDEN
55 * \brief This value is returned by functions that return `nvtxMemHeapHandle_t`,
56 * if a tool is not attached.
57 */
58#define NVTX_MEM_HEAP_HANDLE_NO_TOOL (NVTX_REINTERPRET_CAST(nvtxMemHeapHandle_t, NVTX_STATIC_CAST(intptr_t, -1)))
59/* \endcond
60 */
61
62/* \cond SHOW_HIDDEN
63 * \brief This value is returned by functions that return `nvtxMemRegionHandle_t`
64 * if a tool is not attached.
65 */
66#define NVTX_MEM_REGION_HANDLE_NO_TOOL (NVTX_REINTERPRET_CAST(nvtxMemRegionHandle_t, NVTX_STATIC_CAST(intptr_t, -1)))
67/* \endcond
68 */
69
70/* \cond SHOW_HIDDEN
71 * \brief This value is returned by functions that return `nvtxMemPermissionsHandle_t`
72 * if a tool is not attached.
73 */
74#define NVTX_MEM_PERMISSIONS_HANDLE_NO_TOOL (NVTX_REINTERPRET_CAST(nvtxMemPermissionsHandle_t, -1))
75/* \endcond
76 */
77
78
79/* \cond SHOW_HIDDEN
80 * \brief This should not be used and is considered an error but defined to
81 * detect an accidental use of zero or NULL.
82 */
83#define NVTX_MEM_HEAP_USAGE_UNKNOWN 0x0
84/* \endcond
85 */
86
87
88/* \cond SHOW_HIDDEN
89 * \brief This should not be used and is considered an error but defined to
90 * detect an accidental use of zero or NULL.
91 */
92#define NVTX_MEM_TYPE_UNKNOWN 0x0
93/* \endcond
94 */
95
96
97/* ------------------------------------------------------------------------- */
118#define NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE (NVTX_REINTERPRET_CAST(nvtxMemHeapHandle_t, 0))
119
125#define NVTX_MEM_HEAP_USAGE_TYPE_SUB_ALLOCATOR 0x1
126
142#define NVTX_MEM_HEAP_USAGE_TYPE_LAYOUT 0x2
143
144
155#define NVTX_MEM_TYPE_VIRTUAL_ADDRESS 0x1
156
157
164#define NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE (NVTX_REINTERPRET_CAST(nvtxMemPermissionsHandle_t, 0))
165
166#define NVTX_MEM_PERMISSIONS_CREATE_FLAGS_NONE 0x0
167#define NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_READ 0x1
168#define NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_WRITE 0x2
169#define NVTX_MEM_PERMISSIONS_CREATE_FLAGS_EXCLUDE_GLOBAL_ATOMIC 0x4
170
171
172/* \cond SHOW_HIDDEN
173 * \brief Forward declaration of opaque memory heap structure.
174 */
175struct nvtxMemHeap_v1;
176typedef struct nvtxMemHeap_v1 nvtxMemHeap_t;
177/* \endcond
178 */
179
181typedef nvtxMemHeap_t* nvtxMemHeapHandle_t;
182
183/* \cond SHOW_HIDDEN
184 * \brief Forward declaration of opaque memory heap structure.
185 */
186struct nvtxMemRegion_v1;
187typedef struct nvtxMemRegion_v1 nvtxMemRegion_t;
188/* \endcond
189 */
190
192typedef nvtxMemRegion_t* nvtxMemRegionHandle_t;
193
198{
199 void const* pointer;
202
203/* \cond SHOW_HIDDEN
204 * \brief Forward declaration of opaque memory permissions structure
205 */
206struct nvtxMemPermissions_v1;
207typedef struct nvtxMemPermissions_v1 nvtxMemPermissions_t;
208/* \endcond
209 */
210
212typedef nvtxMemPermissions_t* nvtxMemPermissionsHandle_t;
213
214
216{
217 size_t size;
218 void const* ptr;
221
222
224typedef struct nvtxMemHeapDesc_v1
225{
226 uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
227 uint16_t structSize; /* Size of the structure. */
228 uint32_t reserved0;
229
239 uint32_t usage;
240
258 uint32_t type;
259
265
275 void const* typeSpecificDesc;
276
287 uint32_t category;
288
296 uint32_t messageType; /* nvtxMessageType_t */
297
303
306
321 nvtxDomainHandle_t domain,
322 nvtxMemHeapDesc_t const* desc);
323
325NVTX_DECLSPEC void NVTX_API nvtxMemHeapUnregister(
326 nvtxDomainHandle_t domain,
327 nvtxMemHeapHandle_t heap);/* NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE is not supported */
328
334NVTX_DECLSPEC void NVTX_API nvtxMemHeapReset(
335 nvtxDomainHandle_t domain,
336 nvtxMemHeapHandle_t heap); /* NVTX_MEM_HEAP_HANDLE_PROCESS_WIDE is supported */
337
357{
358 uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
359 uint16_t structSize; /* Size of the structure. */
360
361 uint32_t regionType; /* NVTX_MEM_TYPE_* */
362
364
365 size_t regionCount;
366 size_t regionDescElementSize;
367 void const* regionDescElements; /* This will also become the handle for this region. */
368 nvtxMemRegionHandle_t* regionHandleElementsOut; /* This will also become the handle for this region. */
369
372
375NVTX_DECLSPEC void NVTX_API nvtxMemRegionsRegister(
376 nvtxDomainHandle_t domain,
378
379
380
399{
400 uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
401 uint16_t structSize; /* Size of the structure. */
402
403 uint32_t regionType; /* NVTX_MEM_TYPE_* */
404
405 size_t regionDescCount;
406 size_t regionDescElementSize;
407 void const* regionDescElements; /* This will also become the handle for this region. */
408
411
414NVTX_DECLSPEC void NVTX_API nvtxMemRegionsResize(
415 nvtxDomainHandle_t domain,
416 nvtxMemRegionsResizeBatch_t const* desc);
417
418
419#define NVTX_MEM_REGION_REF_TYPE_UNKNOWN 0x0
420#define NVTX_MEM_REGION_REF_TYPE_POINTER 0x1
421#define NVTX_MEM_REGION_REF_TYPE_HANDLE 0x2
422
442{
443 uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
444 uint16_t structSize; /* Size of the structure. */
445
446 uint32_t refType; /* NVTX_MEM_REGION_REF_TYPE_* */
447
448 size_t refCount; /* count of elements in refArray */
449 size_t refElementSize;
450 nvtxMemRegionRef_t const* refElements; /* This will also become the handle for this region. */
451
454
461NVTX_DECLSPEC void NVTX_API nvtxMemRegionsUnregister(
462 nvtxDomainHandle_t domain,
464
466{
467 uint32_t regionRefType; /* NVTX_MEM_REGION_REF_TYPE_* */
468 uint32_t nameType; /* nvtxMessageType_t */
469
470 nvtxMemRegionRef_t region;
472
473 uint32_t category;
474 uint32_t reserved0;
477
478
480{
481 uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
482 uint16_t structSize; /* Size of the structure. */
483
484 uint32_t reserved0;
485
486 size_t regionCount;
487 size_t regionElementSize;
488 nvtxMemRegionNameDesc_t const* regionElements;
489 size_t reserved1;
492
493
495NVTX_DECLSPEC void NVTX_API nvtxMemRegionsName(
496 nvtxDomainHandle_t domain,
497 nvtxMemRegionsNameBatch_t const* desc);
498
500#define NVTX_MEM_PERMISSIONS_REGION_FLAGS_NONE 0x0
501
503#define NVTX_MEM_PERMISSIONS_REGION_FLAGS_READ 0x1
504
506#define NVTX_MEM_PERMISSIONS_REGION_FLAGS_WRITE 0x2
507
509#define NVTX_MEM_PERMISSIONS_REGION_FLAGS_ATOMIC 0x4
510
519#define NVTX_MEM_PERMISSIONS_REGION_FLAGS_RESET 0x8
520
521
523{
524 uint32_t flags; /* NVTX_MEM_PERMISSIONS_REGION_FLAGS_* */
525 uint32_t regionRefType; /* NVTX_MEM_REGION_REF_TYPE_* */
526 nvtxMemRegionRef_t region;
527
530
531
533{
534 uint16_t extCompatID; /* Set to NVTX_EXT_COMPATID_MEM */
535 uint16_t structSize; /* Size of the structure. */
536
537 uint32_t reserved0;
538
539 nvtxMemPermissionsHandle_t permissions;
540
541 size_t regionCount;
542 size_t regionElementSize;
543 nvtxMemPermissionsAssignRegionDesc_t const* regionElements;
544
545 size_t reserved1;
548
549
551NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsAssign(
552 nvtxDomainHandle_t domain,
554
555
578 nvtxDomainHandle_t domain,
579 int32_t creationflags); /* NVTX_MEM_PERMISSIONS_CREATE_FLAGS_* */
580
586NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsDestroy(
587 nvtxDomainHandle_t domain,
588 nvtxMemPermissionsHandle_t permissionsHandle); /* only supported on objects from nvtxMemPermissionsCreate */
589
591NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsReset(
592 nvtxDomainHandle_t domain,
593 nvtxMemPermissionsHandle_t permissionsHandle);
594/* NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE and other special handles are supported */
595
596
597#define NVTX_MEM_PERMISSIONS_BIND_FLAGS_NONE 0x0
598
604#define NVTX_MEM_PERMISSIONS_BIND_FLAGS_STRICT_WRITE 0x2
605
611#define NVTX_MEM_PERMISSIONS_BIND_FLAGS_STRICT_READ 0x1
612
620#define NVTX_MEM_PERMISSIONS_BIND_FLAGS_STRICT_ATOMIC 0x4
621
622
623#define NVTX_MEM_PERMISSIONS_BIND_SCOPE_UNKNOWN 0x0
624
632#define NVTX_MEM_PERMISSIONS_BIND_SCOPE_CPU_THREAD 0x1
633
652#define NVTX_MEM_PERMISSIONS_BIND_SCOPE_CUDA_STREAM 0x2
653
654
679NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsBind(
680 nvtxDomainHandle_t domain,
681 nvtxMemPermissionsHandle_t permissions, /* special object like NVTX_MEM_PERMISSIONS_HANDLE_PROCESS_WIDE are not supported */
682 uint32_t bindScope, /* NVTX_MEM_PERMISSIONS_BIND_SCOPE_* */
683 uint32_t bindFlags); /* NVTX_MEM_PERMISSIONS_BIND_FLAGS_* */
684
691NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsUnbind(
692 nvtxDomainHandle_t domain,
693 uint32_t bindScope);
694
697#endif /* NVTX_MEM_CONTENTS_V1 */
698
699#ifndef NVTX_MEM_CALLBACK_ID_V1
700#define NVTX_MEM_CALLBACK_ID_V1
701
702#define NVTX3EXT_CBID_nvtxMemHeapRegister 0
703#define NVTX3EXT_CBID_nvtxMemHeapUnregister 1
704#define NVTX3EXT_CBID_nvtxMemHeapReset 2
705#define NVTX3EXT_CBID_nvtxMemRegionsRegister 3
706#define NVTX3EXT_CBID_nvtxMemRegionsResize 4
707#define NVTX3EXT_CBID_nvtxMemRegionsUnregister 5
708#define NVTX3EXT_CBID_nvtxMemRegionsName 6
709#define NVTX3EXT_CBID_nvtxMemPermissionsAssign 7
710#define NVTX3EXT_CBID_nvtxMemPermissionsCreate 8
711#define NVTX3EXT_CBID_nvtxMemPermissionsDestroy 9
712#define NVTX3EXT_CBID_nvtxMemPermissionsReset 10
713#define NVTX3EXT_CBID_nvtxMemPermissionsBind 11
714#define NVTX3EXT_CBID_nvtxMemPermissionsUnbind 12
715
716/* 13-16 in nvtxExtImplMemCudaRt_v1.h */
717#define NVTX3EXT_CBID_nvtxMemCudaGetProcessWidePermissions 13
718#define NVTX3EXT_CBID_nvtxMemCudaGetDeviceWidePermissions 14
719#define NVTX3EXT_CBID_nvtxMemCudaSetPeerAccess 15
720#define NVTX3EXT_CBID_nvtxMemCudaMarkInitialized 16
721
722#endif /* NVTX_MEM_CALLBACK_ID_V1 */
723
724/* Macros to create versioned symbols. */
725#ifndef NVTX_EXT_MEM_VERSIONED_IDENTIFIERS_V1
726#define NVTX_EXT_MEM_VERSIONED_IDENTIFIERS_V1
727#define NVTX_EXT_MEM_VERSIONED_IDENTIFIER_L3(NAME, VERSION, COMPATID) \
728 NAME##_v##VERSION##_mem##COMPATID
729#define NVTX_EXT_MEM_VERSIONED_IDENTIFIER_L2(NAME, VERSION, COMPATID) \
730 NVTX_EXT_MEM_VERSIONED_IDENTIFIER_L3(NAME, VERSION, COMPATID)
731#define NVTX_EXT_MEM_VERSIONED_ID(NAME) \
732 NVTX_EXT_MEM_VERSIONED_IDENTIFIER_L2(NAME, NVTX_VERSION, NVTX_EXT_COMPATID_MEM)
733#endif /* NVTX_EXT_MEM_VERSIONED_IDENTIFIERS_V1 */
734
735#ifdef __GNUC__
736#pragma GCC visibility push(internal)
737#endif
738
739/* Extension types are required for the implementation and the NVTX handler. */
740#define NVTX_EXT_TYPES_GUARD /* Ensure other headers cannot be included directly */
741#include "nvtxDetail/nvtxExtTypes.h"
742#undef NVTX_EXT_TYPES_GUARD
743
744#ifndef NVTX_NO_IMPL
745/* Ensure other headers cannot be included directly */
746#define NVTX_EXT_IMPL_MEM_GUARD
747#include "nvtxDetail/nvtxExtImplMem_v1.h"
748#undef NVTX_EXT_IMPL_MEM_GUARD
749#endif /*NVTX_NO_IMPL*/
750
751#ifdef __GNUC__
752#pragma GCC visibility pop
753#endif
754
755#ifdef __cplusplus
756}
757#endif /* __cplusplus */
NVTX_DECLSPEC void NVTX_API nvtxMemRegionsUnregister(nvtxDomainHandle_t domain, nvtxMemRegionsUnregisterBatch_t const *desc)
Unregistration for regions of process virtual memory.
NVTX_DECLSPEC void NVTX_API nvtxMemRegionsResize(nvtxDomainHandle_t domain, nvtxMemRegionsResizeBatch_t const *desc)
Register a region of memory inside of a heap of linear process virtual memory.
NVTX_DECLSPEC nvtxMemPermissionsHandle_t NVTX_API nvtxMemPermissionsCreate(nvtxDomainHandle_t domain, int32_t creationflags)
Create a permissions object for fine grain thread-local control in multi-threading scenarios.
NVTX_DECLSPEC void NVTX_API nvtxMemRegionsRegister(nvtxDomainHandle_t domain, nvtxMemRegionsRegisterBatch_t const *desc)
Register a region of memory inside of a heap of linear process virtual memory.
NVTX_DECLSPEC void NVTX_API nvtxMemHeapReset(nvtxDomainHandle_t domain, nvtxMemHeapHandle_t heap)
Reset the memory heap wipes out any changes, as if it were a fresh heap.
nvtxMemPermissions_t * nvtxMemPermissionsHandle_t
A handle returned by a tool to represent a memory permissions mask.
NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsBind(nvtxDomainHandle_t domain, nvtxMemPermissionsHandle_t permissions, uint32_t bindScope, uint32_t bindFlags)
Bind the permissions object into a particular scope on the caller thread.
NVTX_DECLSPEC nvtxMemHeapHandle_t NVTX_API nvtxMemHeapRegister(nvtxDomainHandle_t domain, nvtxMemHeapDesc_t const *desc)
Create a memory heap to represent a object or range of memory that will be further sub-divided into r...
NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsDestroy(nvtxDomainHandle_t domain, nvtxMemPermissionsHandle_t permissionsHandle)
Destroy the permissions object.
nvtxMemHeap_t * nvtxMemHeapHandle_t
A handle returned by a tool to represent a memory heap.
NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsReset(nvtxDomainHandle_t domain, nvtxMemPermissionsHandle_t permissionsHandle)
Reset the permissions object back to its created state.
NVTX_DECLSPEC void NVTX_API nvtxMemHeapUnregister(nvtxDomainHandle_t domain, nvtxMemHeapHandle_t heap)
Destroy a memory heap.
NVTX_DECLSPEC void NVTX_API nvtxMemRegionsName(nvtxDomainHandle_t domain, nvtxMemRegionsNameBatch_t const *desc)
Name or rename a region.
nvtxMemRegion_t * nvtxMemRegionHandle_t
A handle returned by a tool to represent a memory region.
NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsAssign(nvtxDomainHandle_t domain, nvtxMemPermissionsAssignBatch_t const *desc)
Change the permissions of a region of process virtual memory.
NVTX_DECLSPEC void NVTX_API nvtxMemPermissionsUnbind(nvtxDomainHandle_t domain, uint32_t bindScope)
Unbind the permissions object bound to the caller thread.
structure to describe a heap in process virtual memory.
uint32_t type
Memory type characteristics of the heap.
uint32_t category
ID of the category the event is assigned to.
uint32_t messageType
Message type specified in this attribute structure.
void const * typeSpecificDesc
Pointer to the heap memory descriptor.
uint32_t usage
Usage characteristics of the heap.
nvtxMessageValue_t message
Message assigned to this attribute structure..
size_t typeSpecificDescSize
size of the heap memory descriptor pointed to by typeSpecificDesc
Register a region of memory inside of a heap.
Register a region of memory inside of a heap.
Register a region of memory inside of a heap.
A reference to a memory region (by pointer or handle). Which member of the union will be determined b...