Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*
0002  * SPDX-FileCopyrightText: Copyright (c) 2021-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 #ifndef NVTX_EXT_IMPL_PAYLOAD_GUARD
0022 #error Never include this file directly -- it is automatically included by nvToolsExtPayload.h (except when NVTX_NO_IMPL is defined).
0023 #endif
0024 
0025 #if defined(NVTX_AS_SYSTEM_HEADER)
0026 #if defined(__clang__)
0027 #pragma clang system_header
0028 #elif defined(__GNUC__) || defined(__NVCOMPILER)
0029 #pragma GCC system_header
0030 #elif defined(_MSC_VER)
0031 #pragma system_header
0032 #endif
0033 #endif
0034 
0035 #define NVTX_EXT_IMPL_GUARD
0036 #include "nvtxExtImpl.h"
0037 #undef NVTX_EXT_IMPL_GUARD
0038 
0039 #ifndef NVTX_EXT_IMPL_PAYLOAD_V1
0040 #define NVTX_EXT_IMPL_PAYLOAD_V1
0041 
0042 #ifdef __cplusplus
0043 extern "C" {
0044 #endif /* __cplusplus */
0045 
0046 #ifdef NVTX_DISABLE
0047 
0048 #include "nvtxExtHelperMacros.h"
0049 
0050 #define NVTX_EXT_PAYLOAD_IMPL_FN_V1(ret_type, fn_name, signature, arg_names) \
0051 NVTX_DECLSPEC ret_type NVTX_API fn_name signature { \
0052     NVTX_SET_NAME_MANGLING_OPTIONS \
0053     NVTX_EXT_HELPER_UNUSED_ARGS arg_names \
0054     NVTX_EXT_FN_RETURN_INVALID(ret_type) \
0055 }
0056 
0057 #define NVTX_EXT_PAYLOAD_IMPL_FN_NOARGS_V1(ret_type, fn_name) \
0058 NVTX_DECLSPEC ret_type NVTX_API fn_name (void) { \
0059     NVTX_SET_NAME_MANGLING_OPTIONS \
0060     NVTX_EXT_FN_RETURN_INVALID(ret_type) \
0061 }
0062 
0063 #else /* NVTX_DISABLE */
0064 
0065 #include "nvtxExtPayloadTypeInfo.h"
0066 
0067 /*
0068  * Function slots for the payload extension. First entry is the module state,
0069  * initialized to `0` (`NVTX_EXTENSION_FRESH`).
0070  */
0071 #define NVTX_EXT_PAYLOAD_SLOT_COUNT 63
0072 
0073 NVTX_LINKONCE_DEFINE_GLOBAL intptr_t
0074 NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots)[NVTX_EXT_PAYLOAD_SLOT_COUNT + 1]
0075     = {0};
0076 
0077 /* `NVTX_LINKONCE_FWDDECL_FUNCTION` is used to avoid warnings about missing prototypes. */
0078 
0079 /* This helper returns always `1` as `uint8_t`. */
0080 NVTX_LINKONCE_FWDDECL_FUNCTION uint8_t NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxReturnOne)(void);
0081 NVTX_LINKONCE_DEFINE_FUNCTION uint8_t NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxReturnOne)(void)
0082 {
0083     return NVTX_STATIC_CAST(uint8_t, 1);
0084 }
0085 
0086 /*
0087  * If a tool is attached, but does not handle `nvtxDomainIsEnabled`, the latter
0088  * will always return `1` (enabled).
0089  */
0090 NVTX_LINKONCE_FWDDECL_FUNCTION void NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxInitIsDomainEnabledFn)(void);
0091 NVTX_LINKONCE_DEFINE_FUNCTION void NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxInitIsDomainEnabledFn)(void)
0092 {
0093     intptr_t* pSlot = &NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots)[NVTX3EXT_CBID_nvtxDomainIsEnabled + 1];
0094 
0095     /* The initialization disables all slots that have not been set by the tool. */
0096     if (*pSlot == NVTX_EXTENSION_DISABLED)
0097     {
0098         intptr_t* moduleState = NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots);
0099         int isInitFnSet =
0100             NVTX_VERSIONED_IDENTIFIER(nvtxExtGlobals1).injectionFnPtr != NVTX_NULLPTR;
0101 
0102         /* Make `nvtxDomainIsEnabled` return `1`, if the tool does not provide an extension
0103            initialization function or if the tool does not handle `nvtxDomainIsEnabled`. */
0104         if (*moduleState == NVTX_EXTENSION_DISABLED ||
0105             (isInitFnSet && *moduleState != NVTX_EXTENSION_INIT_FN_FAILED))
0106         {
0107             *pSlot = NVTX_REINTERPRET_CAST(intptr_t, NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxReturnOne));
0108         }
0109     }
0110 }
0111 
0112 NVTX_LINKONCE_FWDDECL_FUNCTION void NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadInitOnce)(void);
0113 NVTX_LINKONCE_DEFINE_FUNCTION void NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadInitOnce)(void)
0114 {
0115     intptr_t* fnSlots = NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots) + 1;
0116     nvtxExtModuleSegment_t segment = {
0117         0, /* unused (only one segment) */
0118         NVTX_EXT_PAYLOAD_SLOT_COUNT,
0119         NVTX_NULLPTR /* function slots */
0120     };
0121 
0122     nvtxExtModuleInfo_t module_info = {
0123         NVTX_VERSION, sizeof(nvtxExtModuleInfo_t),
0124         NVTX_EXT_PAYLOAD_MODULEID, NVTX_EXT_PAYLOAD_COMPATID,
0125         1, NVTX_NULLPTR, /* number of segments, segments */
0126         NVTX_NULLPTR, /* no export function needed */
0127         /* bake type sizes and alignment information into program binary */
0128         &(NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadTypeInfo))
0129     };
0130 
0131     segment.functionSlots = fnSlots;
0132     module_info.segments = &segment;
0133 
0134     NVTX_INFO( "%s\n", __FUNCTION__  );
0135 
0136     NVTX_VERSIONED_IDENTIFIER(nvtxExtInitOnce)(&module_info,
0137         NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots));
0138 
0139     NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxInitIsDomainEnabledFn)();
0140 }
0141 
0142 #define NVTX_EXT_PAYLOAD_IMPL_FN_V1(ret_type, fn_name, signature, arg_names) \
0143 typedef ret_type (*fn_name##_impl_fntype)signature; \
0144 NVTX_DECLSPEC ret_type NVTX_API fn_name signature { \
0145     NVTX_SET_NAME_MANGLING_OPTIONS \
0146     intptr_t* pSlot = &NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots)[NVTX3EXT_CBID_##fn_name + 1]; \
0147     intptr_t slot = *pSlot; \
0148     if (slot != NVTX_EXTENSION_DISABLED) { \
0149         if (slot != NVTX_EXTENSION_FRESH) { \
0150             NVTX_EXT_FN_RETURN (*NVTX_REINTERPRET_CAST(fn_name##_impl_fntype, slot)) arg_names; \
0151         } else { \
0152             NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadInitOnce)(); \
0153             /* Re-read function slot after extension initialization. */ \
0154             slot = *pSlot; \
0155             if (slot != NVTX_EXTENSION_DISABLED && slot != NVTX_EXTENSION_FRESH) { \
0156                 NVTX_EXT_FN_RETURN (*NVTX_REINTERPRET_CAST(fn_name##_impl_fntype, slot)) arg_names; \
0157             } \
0158         } \
0159     } \
0160     NVTX_EXT_FN_RETURN_INVALID(ret_type) /* No tool attached. */ \
0161 }
0162 
0163 #define NVTX_EXT_PAYLOAD_IMPL_FN_NOARGS_V1(ret_type, fn_name) \
0164     NVTX_EXT_PAYLOAD_IMPL_FN_V1(ret_type, fn_name, (void), ())
0165 
0166 #endif /* NVTX_DISABLE */
0167 
0168 /* Push/pop functions return `NVTX_NO_PUSH_POP_TRACKING` if no tool is attached. */
0169 #define NVTX_EXT_FN_RETURN return
0170 #define NVTX_EXT_FN_RETURN_INVALID(rtype) return NVTX_NO_PUSH_POP_TRACKING;
0171 
0172 NVTX_EXT_PAYLOAD_IMPL_FN_V1(int, nvtxRangePushPayload,
0173     (nvtxDomainHandle_t domain, const nvtxPayloadData_t* payloadData, size_t count),
0174     (domain, payloadData, count))
0175 
0176 NVTX_EXT_PAYLOAD_IMPL_FN_V1(int, nvtxRangePopPayload,
0177     (nvtxDomainHandle_t domain, const nvtxPayloadData_t* payloadData, size_t count),
0178     (domain, payloadData, count))
0179 
0180 #undef NVTX_EXT_FN_RETURN
0181 #undef NVTX_EXT_FN_RETURN_INVALID
0182 
0183 /* Non-void functions. */
0184 #define NVTX_EXT_FN_RETURN return
0185 #define NVTX_EXT_FN_RETURN_INVALID(rtype) return NVTX_STATIC_CAST(rtype, 0);
0186 
0187 NVTX_EXT_PAYLOAD_IMPL_FN_V1(uint64_t, nvtxPayloadSchemaRegister,
0188     (nvtxDomainHandle_t domain, const nvtxPayloadSchemaAttr_t* attr),
0189     (domain, attr))
0190 
0191 NVTX_EXT_PAYLOAD_IMPL_FN_V1(uint64_t, nvtxPayloadEnumRegister,
0192     (nvtxDomainHandle_t domain, const nvtxPayloadEnumAttr_t* attr),
0193     (domain, attr))
0194 
0195 NVTX_EXT_PAYLOAD_IMPL_FN_V1(nvtxRangeId_t, nvtxRangeStartPayload,
0196     (nvtxDomainHandle_t domain, const nvtxPayloadData_t* payloadData, size_t count),
0197     (domain, payloadData, count))
0198 
0199 NVTX_EXT_PAYLOAD_IMPL_FN_V1(uint8_t, nvtxDomainIsEnabled, (nvtxDomainHandle_t domain), (domain))
0200 
0201 NVTX_EXT_PAYLOAD_IMPL_FN_V1(uint64_t, nvtxScopeRegister, (nvtxDomainHandle_t domain,
0202     const nvtxScopeAttr_t* attr), (domain, attr))
0203 
0204 NVTX_EXT_PAYLOAD_IMPL_FN_NOARGS_V1(int64_t, nvtxTimestampGet)
0205 
0206 NVTX_EXT_PAYLOAD_IMPL_FN_V1(uint64_t, nvtxTimeDomainRegister,
0207     (nvtxDomainHandle_t domain, const nvtxTimeDomainAttr_t* attr),
0208     (domain, attr))
0209 
0210 #undef NVTX_EXT_FN_RETURN
0211 #undef NVTX_EXT_FN_RETURN_INVALID
0212 /* END: Non-void functions. */
0213 
0214 /* void functions. */
0215 #define NVTX_EXT_FN_RETURN
0216 #define NVTX_EXT_FN_RETURN_INVALID(rtype)
0217 
0218 NVTX_EXT_PAYLOAD_IMPL_FN_V1(void, nvtxMarkPayload, (nvtxDomainHandle_t domain,
0219     const nvtxPayloadData_t* payloadData, size_t count), (domain, payloadData, count))
0220 
0221 NVTX_EXT_PAYLOAD_IMPL_FN_V1(void, nvtxRangeEndPayload, (nvtxDomainHandle_t domain,
0222     nvtxRangeId_t id, const nvtxPayloadData_t* payloadData, size_t count),
0223     (domain, id, payloadData, count))
0224 
0225 NVTX_EXT_PAYLOAD_IMPL_FN_V1(void, nvtxTimerSource,
0226     (nvtxDomainHandle_t domain, uint64_t timeDomainId, uint64_t flags, int64_t (*timestampProviderFn)(void)),
0227     (domain, timeDomainId, flags, timestampProviderFn))
0228 
0229 NVTX_EXT_PAYLOAD_IMPL_FN_V1(void, nvtxTimerSourceWithData,
0230     (nvtxDomainHandle_t domain, uint64_t timeDomainId, uint64_t flags, int64_t (*timestampProviderFn)(void* data), void* data),
0231     (domain, timeDomainId, flags, timestampProviderFn, data))
0232 
0233 NVTX_EXT_PAYLOAD_IMPL_FN_V1(void, nvtxTimeSyncPoint,
0234     (nvtxDomainHandle_t domain, uint64_t timeDomainId1, uint64_t timeDomainId2,
0235         int64_t timestamp1, int64_t timestamp2),
0236     (domain, timeDomainId1, timeDomainId2, timestamp1, timestamp2))
0237 
0238 NVTX_EXT_PAYLOAD_IMPL_FN_V1(void, nvtxTimeSyncPointTable,
0239     (nvtxDomainHandle_t domain, uint64_t timeDomainIdSrc, uint64_t timeDomainIdDst,
0240     const nvtxSyncPoint_t* syncPoints, size_t count),
0241     (domain, timeDomainIdSrc, timeDomainIdDst, syncPoints, count))
0242 
0243 NVTX_EXT_PAYLOAD_IMPL_FN_V1(void, nvtxTimestampConversionFactor,
0244     (nvtxDomainHandle_t domain, uint64_t timeDomainIdSrc, uint64_t timeDomainIdDst,
0245         double slope, int64_t timestampSrc, int64_t timestampDst),
0246     (domain, timeDomainIdSrc, timeDomainIdDst, slope, timestampSrc, timestampDst))
0247 
0248 NVTX_EXT_PAYLOAD_IMPL_FN_V1(void, nvtxEventSubmit,
0249     (nvtxDomainHandle_t domain, const nvtxPayloadData_t* payloadData, size_t numPayloads),
0250     (domain, payloadData, numPayloads))
0251 
0252 NVTX_EXT_PAYLOAD_IMPL_FN_V1(void, nvtxEventBatchSubmit, (nvtxDomainHandle_t domain,
0253     const nvtxEventBatch_t* eventBatch), (domain, eventBatch))
0254 
0255 #undef NVTX_EXT_FN_RETURN
0256 #undef NVTX_EXT_FN_RETURN_INVALID
0257 /* END: void functions. */
0258 
0259 /* Keep NVTX_EXT_PAYLOAD_IMPL_FN_V1 defined for a future version of this extension. */
0260 
0261 #ifdef __cplusplus
0262 } /* extern "C" */
0263 #endif /* __cplusplus */
0264 
0265 #endif /* NVTX_EXT_IMPL_PAYLOAD_V1 */