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) 2024-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_COUNTERS_GUARD
0022 #error Never include this file directly -- it is automatically included by nvToolsExtCounters.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_COUNTERS_V1
0040 #define NVTX_EXT_IMPL_COUNTERS_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_COUNTERS_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 #else /* NVTX_DISABLE */
0058 
0059 /*
0060  * Function slots for the counters extension. First entry is the module state,
0061  * initialized to `0` (`NVTX_EXTENSION_FRESH`).
0062  */
0063 #define NVTX_EXT_COUNTERS_SLOT_COUNT 63
0064 
0065 NVTX_LINKONCE_DEFINE_GLOBAL intptr_t
0066 NVTX_EXT_COUNTERS_VERSIONED_ID(nvtxExtCountersSlots)[NVTX_EXT_COUNTERS_SLOT_COUNT + 1]
0067     = {0};
0068 
0069 /* Avoid warnings about missing prototype. */
0070 NVTX_LINKONCE_FWDDECL_FUNCTION void NVTX_EXT_COUNTERS_VERSIONED_ID(nvtxExtCountersInitOnce)(void);
0071 NVTX_LINKONCE_DEFINE_FUNCTION void NVTX_EXT_COUNTERS_VERSIONED_ID(nvtxExtCountersInitOnce)(void)
0072 {
0073     intptr_t* fnSlots = NVTX_EXT_COUNTERS_VERSIONED_ID(nvtxExtCountersSlots) + 1;
0074     nvtxExtModuleSegment_t segment = {
0075         0, /* unused (only one segment) */
0076         NVTX_EXT_COUNTERS_SLOT_COUNT,
0077         NVTX_NULLPTR /* function slots */
0078     };
0079 
0080     nvtxExtModuleInfo_t module_info = {
0081         NVTX_VERSION, sizeof(nvtxExtModuleInfo_t),
0082         NVTX_EXT_COUNTERS_MODULEID, NVTX_EXT_COUNTERS_COMPATID,
0083         1, NVTX_NULLPTR, /* number of segments, segments */
0084         NVTX_NULLPTR, /* no export function needed */
0085         NVTX_NULLPTR /* no extension private info */
0086     };
0087 
0088     segment.functionSlots = fnSlots;
0089     module_info.segments = &segment;
0090 
0091     NVTX_INFO( "%s\n", __FUNCTION__  );
0092 
0093     NVTX_VERSIONED_IDENTIFIER(nvtxExtInitOnce)(&module_info,
0094         NVTX_EXT_COUNTERS_VERSIONED_ID(nvtxExtCountersSlots));
0095 }
0096 
0097 #define NVTX_EXT_COUNTERS_IMPL_FN_V1(ret_type, fn_name, signature, arg_names) \
0098 typedef ret_type (*fn_name##_impl_fntype)signature; \
0099 NVTX_DECLSPEC ret_type NVTX_API fn_name signature { \
0100     NVTX_SET_NAME_MANGLING_OPTIONS \
0101     intptr_t* pSlot = &NVTX_EXT_COUNTERS_VERSIONED_ID(nvtxExtCountersSlots)[NVTX3EXT_CBID_##fn_name + 1]; \
0102     intptr_t slot = *pSlot; \
0103     if (slot != NVTX_EXTENSION_DISABLED) { \
0104         if (slot != NVTX_EXTENSION_FRESH) { \
0105             NVTX_EXT_FN_RETURN (*NVTX_REINTERPRET_CAST(fn_name##_impl_fntype, slot)) arg_names; \
0106         } else { \
0107             NVTX_EXT_COUNTERS_VERSIONED_ID(nvtxExtCountersInitOnce)(); \
0108             /* Re-read function slot after extension initialization. */ \
0109             slot = *pSlot; \
0110             if (slot != NVTX_EXTENSION_DISABLED && slot != NVTX_EXTENSION_FRESH) { \
0111                 NVTX_EXT_FN_RETURN (*NVTX_REINTERPRET_CAST(fn_name##_impl_fntype, slot)) arg_names; \
0112             } \
0113         } \
0114     } \
0115     NVTX_EXT_FN_RETURN_INVALID(ret_type) /* No tool attached. */ \
0116 }
0117 
0118 #endif /* NVTX_DISABLE */
0119 
0120 /* Non-void functions. */
0121 #define NVTX_EXT_FN_RETURN return
0122 #define NVTX_EXT_FN_RETURN_INVALID(rtype) return NVTX_STATIC_CAST(rtype, 0);
0123 
0124 NVTX_EXT_COUNTERS_IMPL_FN_V1(uint64_t, nvtxCounterRegister,
0125     (nvtxDomainHandle_t domain, const nvtxCounterAttr_t* attr),
0126     (domain, attr))
0127 
0128 #undef NVTX_EXT_FN_RETURN
0129 #undef NVTX_EXT_FN_RETURN_INVALID
0130 /* END: Non-void functions. */
0131 
0132 /* void functions. */
0133 #define NVTX_EXT_FN_RETURN
0134 #define NVTX_EXT_FN_RETURN_INVALID(rtype)
0135 
0136 NVTX_EXT_COUNTERS_IMPL_FN_V1(void, nvtxCounterSampleInt64,
0137     (nvtxDomainHandle_t domain, uint64_t counterId, int64_t value),
0138     (domain, counterId, value))
0139 
0140 NVTX_EXT_COUNTERS_IMPL_FN_V1(void, nvtxCounterSampleFloat64,
0141     (nvtxDomainHandle_t domain, uint64_t counterId, double value),
0142     (domain, counterId, value))
0143 
0144 NVTX_EXT_COUNTERS_IMPL_FN_V1(void, nvtxCounterSample,
0145     (nvtxDomainHandle_t domain, uint64_t counterId, const void* values, size_t size),
0146     (domain, counterId, values, size))
0147 
0148 NVTX_EXT_COUNTERS_IMPL_FN_V1(void, nvtxCounterSampleNoValue,
0149     (nvtxDomainHandle_t domain, uint64_t counterId, uint8_t reason),
0150     (domain, counterId, reason))
0151 
0152 NVTX_EXT_COUNTERS_IMPL_FN_V1(void, nvtxCounterBatchSubmit,
0153     (nvtxDomainHandle_t domain, const nvtxCounterBatch_t* counterData),
0154     (domain, counterData))
0155 
0156 #undef NVTX_EXT_FN_RETURN
0157 #undef NVTX_EXT_FN_RETURN_INVALID
0158 /* END: void functions. */
0159 
0160 /* Keep NVTX_EXT_COUNTERS_IMPL_FN_V1 defined for a future version of this extension. */
0161 
0162 #ifdef __cplusplus
0163 } /* extern "C" */
0164 #endif /* __cplusplus */
0165 
0166 #endif /* NVTX_EXT_IMPL_COUNTERS_V1 */