Merge remote-tracking branch 'nccl/master' into HEAD
Этот коммит содержится в:
@@ -10,10 +10,16 @@
|
||||
#include "nccl.h"
|
||||
#include "comm.h"
|
||||
|
||||
struct ncclBootstrapHandle {
|
||||
uint64_t magic;
|
||||
union ncclSocketAddress addr;
|
||||
};
|
||||
static_assert(sizeof(struct ncclBootstrapHandle) <= sizeof(ncclUniqueId), "Bootstrap handle is too large to fit inside NCCL unique ID");
|
||||
|
||||
ncclResult_t bootstrapNetInit();
|
||||
ncclResult_t bootstrapCreateRoot(ncclUniqueId* commId, bool idFromEnv);
|
||||
ncclResult_t bootstrapGetUniqueId(ncclUniqueId* out);
|
||||
ncclResult_t bootstrapInit(ncclUniqueId* id, struct ncclComm* comm);
|
||||
ncclResult_t bootstrapCreateRoot(struct ncclBootstrapHandle* handle, bool idFromEnv);
|
||||
ncclResult_t bootstrapGetUniqueId(struct ncclBootstrapHandle* handle);
|
||||
ncclResult_t bootstrapInit(struct ncclBootstrapHandle* handle, struct ncclComm* comm);
|
||||
ncclResult_t bootstrapAllGather(void* commState, void* allData, int size);
|
||||
ncclResult_t bootstrapSend(void* commState, int peer, int tag, void* data, int size);
|
||||
ncclResult_t bootstrapRecv(void* commState, int peer, int tag, void* data, int size);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
* Copyright (c) 2015-2022, NVIDIA CORPORATION. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
*
|
||||
* See LICENSE.txt for license information
|
||||
************************************************************************/
|
||||
@@ -177,9 +177,12 @@ struct ncclComm {
|
||||
uint64_t* connectSend;
|
||||
uint64_t* connectRecv;
|
||||
|
||||
uint64_t magic; // Magic number for all network communication. Not a security key -- only goal is to detect mismatches.
|
||||
|
||||
int rank; // my rank in the communicator
|
||||
int nRanks; // number of GPUs in communicator
|
||||
int cudaDev; // my cuda device index
|
||||
int compCap; // compute capability of the GPU
|
||||
int64_t busId; // my PCI bus ID in int format
|
||||
cpu_set_t cpuAffinity; // CPU affinity of the GPU
|
||||
int WarpSize;
|
||||
@@ -216,7 +219,7 @@ struct ncclComm {
|
||||
|
||||
// Buffer sizes
|
||||
int buffSizes[NCCL_NUM_PROTOCOLS];
|
||||
int p2pNetChunkSize;
|
||||
int p2pChunkSize;
|
||||
|
||||
// Algorithm/Protocols thresholds
|
||||
ssize_t threadThresholds[NCCL_NUM_ALGORITHMS][NCCL_NUM_PROTOCOLS];
|
||||
@@ -253,7 +256,6 @@ struct ncclComm {
|
||||
// Intra-process sync
|
||||
struct ncclComm* intraComm0; // leader of intra-process comms (self possible)
|
||||
struct ncclComm* intraNext; // next of intra-process comms, intraComm0 is head
|
||||
int intraRefs; // reference count from intra-process comms (zero if not leader else intraRanks)
|
||||
int intraRank;
|
||||
int intraRanks;
|
||||
uint32_t intraBarrierPhase;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
* Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2021 Advanced Micro Devices, Inc. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
*
|
||||
* See LICENSE.txt for license information
|
||||
************************************************************************/
|
||||
@@ -159,20 +159,55 @@ typedef struct gdr_mem_desc {
|
||||
|
||||
#if defined(__HIP_PLATFORM_HCC__) || defined(__HCC__) || defined(__HIPCC__)
|
||||
static gdr_t ncclGdrInit() {
|
||||
return NULL;
|
||||
INFO(NCCL_INIT, "Enabled GDRCopy equivalent memory allocation");
|
||||
return (gdr_t)0x12345678L;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static ncclResult_t ncclGdrCudaCalloc(T** ptr, T** devPtr, size_t nelem, void** gdrHandle) {
|
||||
static ncclResult_t ncclGdrCudaCalloc(T** ptr, T** devPtr, size_t nelem, void** gdrHandle, hipStream_t stream) {
|
||||
gdr_info_t info;
|
||||
size_t mapSize;
|
||||
gdr_mh_t mh;
|
||||
char *devMem;
|
||||
void *gdrMap;
|
||||
|
||||
mapSize = sizeof(T)*nelem;
|
||||
|
||||
// GDRCOPY Pinned buffer has to be a minimum of a GPU_PAGE_SIZE
|
||||
ALIGN_SIZE(mapSize, GPU_PAGE_SIZE);
|
||||
// GDRCOPY Pinned buffer has to be GPU_PAGE_SIZE aligned too
|
||||
NCCLCHECK(ncclCudaCalloc(&devMem, mapSize+GPU_PAGE_SIZE-1, stream, true));
|
||||
|
||||
gdr_mem_desc_t* md;
|
||||
NCCLCHECK(ncclCalloc(&md, 1));
|
||||
md->gdrDevMem = devMem;
|
||||
md->gdrMap = NULL;
|
||||
md->gdrMapSize = mapSize;
|
||||
md->gdrOffset = 0;
|
||||
md->gdrMh.h = 0;
|
||||
*gdrHandle = md;
|
||||
|
||||
*ptr = (T *)(devMem);
|
||||
if (devPtr) *devPtr = (T *)(devMem);
|
||||
|
||||
TRACE(NCCL_INIT, "GDRCOPY : allocated devMem %p gdrMap %p offset %lx mh %lx mapSize %zi at %p",
|
||||
md->gdrDevMem, md->gdrMap, md->gdrOffset, md->gdrMh.h, md->gdrMapSize, *ptr);
|
||||
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static ncclResult_t ncclGdrCudaCopy(void *gdrHandle, T* dst, T* src, size_t nelem) {
|
||||
gdr_mem_desc_t *md = (gdr_mem_desc_t*)gdrHandle;
|
||||
memcpy(dst, src, nelem*sizeof(T));
|
||||
return ncclSuccess;
|
||||
}
|
||||
|
||||
static ncclResult_t ncclGdrCudaFree(void* gdrHandle) {
|
||||
gdr_mem_desc_t *md = (gdr_mem_desc_t*)gdrHandle;
|
||||
CUDACHECK(hipFree(md->gdrDevMem));
|
||||
free(md);
|
||||
|
||||
return ncclSuccess;
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
* Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
*
|
||||
* See LICENSE.txt for license information
|
||||
************************************************************************/
|
||||
@@ -29,6 +29,7 @@ void ncclTopoFree(struct ncclTopoSystem* system);
|
||||
ncclResult_t ncclTopoTrimSystem(struct ncclTopoSystem* system, struct ncclComm* comm);
|
||||
ncclResult_t ncclTopoComputeP2pChannels(struct ncclComm* comm);
|
||||
ncclResult_t ncclTopoGetNvbGpus(struct ncclTopoSystem* system, int rank, int* nranks, int** ranks);
|
||||
int ncclTopoPathAllNVLink(struct ncclTopoSystem* system);
|
||||
|
||||
// Query topology
|
||||
ncclResult_t ncclTopoGetNetDev(struct ncclComm* comm, int rank, struct ncclTopoGraph* graph, int channelId, int peerRank, int* net, int* proxyRank);
|
||||
|
||||
@@ -9,6 +9,77 @@
|
||||
|
||||
#include "nvtx3.hpp"
|
||||
|
||||
#if __cpp_constexpr >= 201304L && !defined(NVTX3_RELAXED_CONSTEXPR)
|
||||
#define NVTX3_RELAXED_CONSTEXPR constexpr
|
||||
#else
|
||||
#define NVTX3_RELAXED_CONSTEXPR
|
||||
#endif
|
||||
|
||||
// Define all NCCL-provided static schema IDs here (avoid duplicates).
|
||||
#define NVTX_SID_CommInitRank 0
|
||||
#define NVTX_SID_CommInitAll 1
|
||||
#define NVTX_SID_CommDestroy 2 // same schema as NVTX_SID_CommInitRank
|
||||
#define NVTX_SID_CommAbort 3 // same schema as NVTX_SID_CommInitRank
|
||||
#define NVTX_SID_AllGather 4
|
||||
#define NVTX_SID_AllReduce 5
|
||||
#define NVTX_SID_Broadcast 6
|
||||
#define NVTX_SID_ReduceScatter 7
|
||||
#define NVTX_SID_Reduce 8
|
||||
#define NVTX_SID_Send 9
|
||||
#define NVTX_SID_Recv 10
|
||||
|
||||
// Define static schema ID for the reduction operation.
|
||||
#define NVTX_PAYLOAD_ENTRY_NCCL_REDOP 11 + NVTX_PAYLOAD_ENTRY_TYPE_SCHEMA_ID_STATIC_START
|
||||
|
||||
extern const nvtxDomainHandle_t ncclNvtxDomainHandle;
|
||||
|
||||
struct nccl_domain{static constexpr char const* name{"NCCL"};};
|
||||
|
||||
class payload_schema {
|
||||
public:
|
||||
NVTX3_RELAXED_CONSTEXPR explicit payload_schema(const nvtxPayloadSchemaEntry_t entries[], size_t numEntries, const uint64_t schemaId, const char* schemaName = nullptr) noexcept
|
||||
{
|
||||
schema_attr.name = schemaName;
|
||||
schema_attr.entries = entries;
|
||||
schema_attr.numEntries = numEntries;
|
||||
schema_attr.schemaId = schemaId;
|
||||
nvtxPayloadSchemaRegister(nvtx3::domain::get<nccl_domain>(), &schema_attr);
|
||||
}
|
||||
|
||||
payload_schema() = delete;
|
||||
~payload_schema() = default;
|
||||
payload_schema(payload_schema const&) = default;
|
||||
payload_schema& operator=(payload_schema const&) = default;
|
||||
payload_schema(payload_schema&&) = default;
|
||||
payload_schema& operator=(payload_schema&&) = default;
|
||||
|
||||
private:
|
||||
nvtxPayloadSchemaAttr_t schema_attr{
|
||||
NVTX_PAYLOAD_SCHEMA_ATTR_TYPE |
|
||||
NVTX_PAYLOAD_SCHEMA_ATTR_ENTRIES |
|
||||
NVTX_PAYLOAD_SCHEMA_ATTR_NUM_ENTRIES |
|
||||
NVTX_PAYLOAD_SCHEMA_ATTR_STATIC_SIZE |
|
||||
NVTX_PAYLOAD_SCHEMA_ATTR_SCHEMA_ID,
|
||||
nullptr,
|
||||
NVTX_PAYLOAD_SCHEMA_TYPE_STATIC,
|
||||
NVTX_PAYLOAD_SCHEMA_FLAG_NONE,
|
||||
nullptr, 0, 0, 0};
|
||||
};
|
||||
|
||||
// Create NVTX push/pop range with parameters
|
||||
// @param name of the operation (see `NVTX_SID_*`)
|
||||
// @param N schema name
|
||||
// @param S schema (entries)
|
||||
// @param P payload (struct)
|
||||
#define NVTX3_FUNC_WITH_PARAMS(ID, S, P) \
|
||||
static const payload_schema schema{S, std::extent<decltype(S)>::value, \
|
||||
NVTX_PAYLOAD_ENTRY_TYPE_SCHEMA_ID_STATIC_START + NVTX_SID_##ID, #ID}; \
|
||||
static ::nvtx3::v1::registered_string<nccl_domain> const nvtx3_func_name__{__func__}; \
|
||||
nvtxPayloadData_t nvtx3_bpl__[] = { \
|
||||
{NVTX_PAYLOAD_ENTRY_TYPE_SCHEMA_ID_STATIC_START + NVTX_SID_##ID, sizeof(P), &(P)}}; \
|
||||
::nvtx3::v1::event_attributes nvtx3_func_attr__{nvtx3_func_name__, nvtx3_bpl__}; \
|
||||
::nvtx3::v1::domain_thread_range<nccl_domain> const nvtx3_range__{nvtx3_func_attr__};
|
||||
|
||||
extern void initNvtxRegisteredEnums();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
/* clang-format on */
|
||||
|
||||
#include <nvtx3/nvToolsExt.h>
|
||||
#include <nvtx3/nvToolsExtPayload.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -1732,6 +1733,22 @@ class event_attributes {
|
||||
attributes_.messageType = m.get_type();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Variadic constructor where the first argument is a binary payload.
|
||||
*
|
||||
* Sets the value of the `EventAttribute`s message based on `m` and forwards
|
||||
* the remaining variadic parameter pack to the next constructor.
|
||||
*
|
||||
*/
|
||||
template <typename... Args>
|
||||
NVTX3_RELAXED_CONSTEXPR explicit event_attributes(nvtxPayloadData_t const* bpl, Args const&... args) noexcept
|
||||
: event_attributes(args...)
|
||||
{
|
||||
attributes_.payloadType = NVTX_PAYLOAD_TYPE_BINARY;
|
||||
attributes_.reserved0 = 1; // NCCL uses only a single binary payload per event.
|
||||
attributes_.payload.ullValue = NVTX_POINTER_AS_PAYLOAD_ULLVALUE(bpl);
|
||||
}
|
||||
|
||||
~event_attributes() = default;
|
||||
event_attributes(event_attributes const&) = default;
|
||||
event_attributes& operator=(event_attributes const&) = default;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "nvToolsExt.h"
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "cuda.h"
|
||||
|
||||
#ifndef NVTOOLSEXT_CUDA_V3
|
||||
#define NVTOOLSEXT_CUDA_V3
|
||||
@@ -42,10 +42,10 @@ extern "C" {
|
||||
*/
|
||||
typedef enum nvtxResourceCUDAType_t
|
||||
{
|
||||
NVTX_RESOURCE_TYPE_CUDA_DEVICE = NVTX_RESOURCE_MAKE_TYPE(CUDA, 1), /* hipDevice_t */
|
||||
NVTX_RESOURCE_TYPE_CUDA_CONTEXT = NVTX_RESOURCE_MAKE_TYPE(CUDA, 2), /* hipCtx_t */
|
||||
NVTX_RESOURCE_TYPE_CUDA_STREAM = NVTX_RESOURCE_MAKE_TYPE(CUDA, 3), /* hipStream_t */
|
||||
NVTX_RESOURCE_TYPE_CUDA_EVENT = NVTX_RESOURCE_MAKE_TYPE(CUDA, 4), /* hipEvent_t */
|
||||
NVTX_RESOURCE_TYPE_CUDA_DEVICE = NVTX_RESOURCE_MAKE_TYPE(CUDA, 1), /* CUdevice */
|
||||
NVTX_RESOURCE_TYPE_CUDA_CONTEXT = NVTX_RESOURCE_MAKE_TYPE(CUDA, 2), /* CUcontext */
|
||||
NVTX_RESOURCE_TYPE_CUDA_STREAM = NVTX_RESOURCE_MAKE_TYPE(CUDA, 3), /* CUstream */
|
||||
NVTX_RESOURCE_TYPE_CUDA_EVENT = NVTX_RESOURCE_MAKE_TYPE(CUDA, 4), /* CUevent */
|
||||
} nvtxResourceCUDAType_t;
|
||||
|
||||
|
||||
@@ -59,8 +59,8 @@ typedef enum nvtxResourceCUDAType_t
|
||||
*
|
||||
* \version \NVTX_VERSION_1
|
||||
* @{ */
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceA(hipDevice_t device, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceW(hipDevice_t device, const wchar_t* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceA(CUdevice device, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceW(CUdevice device, const wchar_t* name);
|
||||
/** @} */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -73,16 +73,16 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceW(hipDevice_t device, const wchar_t*
|
||||
*
|
||||
* \par Example:
|
||||
* \code
|
||||
* hipError_t status = hipCtxCreate( &cuContext, 0, cuDevice );
|
||||
* if ( hipSuccess != status )
|
||||
* CUresult status = cuCtxCreate( &cuContext, 0, cuDevice );
|
||||
* if ( CUDA_SUCCESS != status )
|
||||
* goto Error;
|
||||
* nvtxNameCuContext(cuContext, "CTX_NAME");
|
||||
* \endcode
|
||||
*
|
||||
* \version \NVTX_VERSION_1
|
||||
* @{ */
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuContextA(hipCtx_t context, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuContextW(hipCtx_t context, const wchar_t* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuContextA(CUcontext context, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuContextW(CUcontext context, const wchar_t* name);
|
||||
/** @} */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -95,8 +95,8 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuContextW(hipCtx_t context, const wchar_t*
|
||||
*
|
||||
* \version \NVTX_VERSION_1
|
||||
* @{ */
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamA(hipStream_t stream, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamW(hipStream_t stream, const wchar_t* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamA(CUstream stream, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamW(CUstream stream, const wchar_t* name);
|
||||
/** @} */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -109,8 +109,8 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamW(hipStream_t stream, const wchar_t*
|
||||
*
|
||||
* \version \NVTX_VERSION_1
|
||||
* @{ */
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuEventA(hipEvent_t event, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuEventW(hipEvent_t event, const wchar_t* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuEventA(CUevent event, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuEventW(CUevent event, const wchar_t* name);
|
||||
/** @} */
|
||||
|
||||
/** @} */ /* END RESOURCE_NAMING */
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
#include "nvToolsExt.h"
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/driver_types.h"
|
||||
#include "cuda.h"
|
||||
#include "driver_types.h"
|
||||
|
||||
#ifndef NVTOOLSEXT_CUDART_V3
|
||||
#define NVTOOLSEXT_CUDART_V3
|
||||
@@ -44,8 +44,8 @@ extern "C" {
|
||||
typedef enum nvtxResourceCUDARTType_t
|
||||
{
|
||||
NVTX_RESOURCE_TYPE_CUDART_DEVICE = NVTX_RESOURCE_MAKE_TYPE(CUDART, 0), /* int device */
|
||||
NVTX_RESOURCE_TYPE_CUDART_STREAM = NVTX_RESOURCE_MAKE_TYPE(CUDART, 1), /* hipStream_t */
|
||||
NVTX_RESOURCE_TYPE_CUDART_EVENT = NVTX_RESOURCE_MAKE_TYPE(CUDART, 2), /* hipEvent_t */
|
||||
NVTX_RESOURCE_TYPE_CUDART_STREAM = NVTX_RESOURCE_MAKE_TYPE(CUDART, 1), /* cudaStream_t */
|
||||
NVTX_RESOURCE_TYPE_CUDART_EVENT = NVTX_RESOURCE_MAKE_TYPE(CUDART, 2), /* cudaEvent_t */
|
||||
} nvtxResourceCUDARTType_t;
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCudaDeviceW(int device, const wchar_t* name)
|
||||
*
|
||||
* \version \NVTX_VERSION_1
|
||||
* @{ */
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamA(hipStream_t stream, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamW(hipStream_t stream, const wchar_t* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamA(cudaStream_t stream, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamW(cudaStream_t stream, const wchar_t* name);
|
||||
/** @} */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -87,8 +87,8 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamW(hipStream_t stream, const wchar_
|
||||
*
|
||||
* \version \NVTX_VERSION_1
|
||||
* @{ */
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaEventA(hipEvent_t event, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaEventW(hipEvent_t event, const wchar_t* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaEventA(cudaEvent_t event, const char* name);
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaEventW(cudaEvent_t event, const wchar_t* name);
|
||||
/** @} */
|
||||
|
||||
/** @} */ /* END RESOURCE_NAMING */
|
||||
|
||||
@@ -0,0 +1,776 @@
|
||||
/*
|
||||
* Copyright 2021 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License v2.0 with LLVM Exceptions.
|
||||
* See https://llvm.org/LICENSE.txt for license information.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "nvtx3/nvToolsExt.h"
|
||||
|
||||
#ifndef NVTOOLSEXT_PAYLOAD_H
|
||||
#define NVTOOLSEXT_PAYLOAD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* \brief A compatibility ID value used in initialization to identify version
|
||||
* differences.
|
||||
*/
|
||||
#define NVTX_EXT_COMPATID_PAYLOAD 0x0103
|
||||
|
||||
/**
|
||||
* \brief This module ID identifies the payload extension. It has to be unique
|
||||
* among the extension modules.
|
||||
*/
|
||||
#define NVTX_EXT_MODULEID_PAYLOAD 2
|
||||
|
||||
/**
|
||||
* \brief Additional values for the enum @ref nvtxPayloadType_t
|
||||
*/
|
||||
#define NVTX_PAYLOAD_TYPE_BINARY ((int32_t)0xDFBD0009)
|
||||
|
||||
|
||||
/** ---------------------------------------------------------------------------
|
||||
* Payload schema entry flags.
|
||||
* ------------------------------------------------------------------------- */
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_UNUSED 0
|
||||
|
||||
/**
|
||||
* Absolute pointer into a payload (entry) of the same event.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_POINTER (1 << 1)
|
||||
|
||||
/**
|
||||
* Offset from base address of the payload.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_OFFSET_FROM_BASE (1 << 2)
|
||||
|
||||
/**
|
||||
* Offset from the end of this payload entry.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_OFFSET_FROM_HERE (1 << 3)
|
||||
|
||||
/**
|
||||
* The value is an array with fixed length, set with the field `arrayLength`.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_FIXED_SIZE (1 << 4)
|
||||
|
||||
/**
|
||||
* The value is a zero-/null-terminated array.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_ZERO_TERMINATED (2 << 4)
|
||||
|
||||
/**
|
||||
* \brief A single or multi-dimensional array of variable length.
|
||||
*
|
||||
* The field `arrayLength` contains the index of the schema entry that holds the
|
||||
* length(s). If the other field points to a scalar entry then this will be the
|
||||
* 1D array. If the other field points to a FIXED_SIZE array, then the number of
|
||||
* dimensions is defined with the registration of the scheme. If the other field
|
||||
* is ZERO_TERMINATED, the array the dimensions can be determined at runtime.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_LENGTH_INDEX (3 << 4)
|
||||
|
||||
/**
|
||||
* A tool may not support deep copy and just ignore this flag.
|
||||
* See @ref NVTX_PAYLOAD_SCHEMA_FLAG_DEEP_COPY for more details.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_DEEP_COPY (1 << 9)
|
||||
|
||||
/**
|
||||
* The entry specifies the message in a deferred event. The entry type can be
|
||||
* any string type. The flag is ignored for schemas that are not flagged with
|
||||
* `NVTX_PAYLOAD_SCHEMA_FLAG_RANGE*` or `NVTX_PAYLOAD_SCHEMA_FLAG_MARK`.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_EVENT_MESSAGE (1 << 10)
|
||||
|
||||
/**
|
||||
* @note The ‘array’ flags assume that the array is embedded. Otherwise,
|
||||
* @ref NVTX_PAYLOAD_ENTRY_FLAG_POINTER has to be additionally specified. Some
|
||||
* combinations may be invalid based on the `NVTX_PAYLOAD_SCHEMA_TYPE_*` this
|
||||
* entry is enclosed. For instance, variable length embedded arrays are valid
|
||||
* within @ref NVTX_PAYLOAD_SCHEMA_TYPE_DYNAMIC but invalid with
|
||||
* @ref NVTX_PAYLOAD_SCHEMA_TYPE_STATIC. See `NVTX_PAYLOAD_SCHEMA_TYPE_*` for
|
||||
* additional details.
|
||||
*/
|
||||
|
||||
/* Helper macro to check if an entry represents an array. */
|
||||
#define NVTX_PAYLOAD_ENTRY_FLAG_IS_ARRAY (\
|
||||
NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_FIXED_SIZE | \
|
||||
NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_ZERO_TERMINATED | \
|
||||
NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_LENGTH_INDEX)
|
||||
|
||||
/** ---------------------------------------------------------------------------
|
||||
* Types of entries in a payload schema.
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @note Several of the predefined types contain the size (in bits) in their
|
||||
* names. For some data types the size (in bytes) is not fixed and may differ
|
||||
* for different platforms/operating systems/compilers. To provide portability,
|
||||
* an array of sizes (in bytes) for type 1 to 28 ( @ref
|
||||
* NVTX_PAYLOAD_ENTRY_TYPE_CHAR to @ref NVTX_PAYLOAD_ENTRY_TYPE_INFO_ARRAY_SIZE)
|
||||
* is passed to the NVTX extension initialization function
|
||||
* @ref InitializeInjectionNvtxExtension via the `extInfo` field of
|
||||
* @ref nvtxExtModuleInfo_t.
|
||||
*/
|
||||
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_INVALID 0
|
||||
|
||||
/**
|
||||
* Basic integer types.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_CHAR 1
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UCHAR 2
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_SHORT 3
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_USHORT 4
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_INT 5
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UINT 6
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_LONG 7
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_ULONG 8
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_LONGLONG 9
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_ULONGLONG 10
|
||||
|
||||
/**
|
||||
* Integer types with explicit size.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_INT8 11
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UINT8 12
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_INT16 13
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UINT16 14
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_INT32 15
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UINT32 16
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_INT64 17
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UINT64 18
|
||||
|
||||
/**
|
||||
* C floating point types
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_FLOAT 19
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_DOUBLE 20
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_LONGDOUBLE 21
|
||||
|
||||
/**
|
||||
* Size type (`size_t`)
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_SIZE 22
|
||||
|
||||
/**
|
||||
* Any address, e.g. `void*`. If the pointer type matters, use the flag @ref
|
||||
* NVTX_PAYLOAD_ENTRY_FLAG_POINTER and the respective type instead.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_ADDRESS 23
|
||||
|
||||
/**
|
||||
* Special character types.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_WCHAR 24 /* wide character (since C90) */
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_CHAR8 25 /* since C2x and C++20 */
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_CHAR16 26
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_CHAR32 27
|
||||
|
||||
/**
|
||||
* There is type size and alignment information for all previous types.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_INFO_ARRAY_SIZE (NVTX_PAYLOAD_ENTRY_TYPE_CHAR32 + 1)
|
||||
|
||||
/**
|
||||
* Store raw 8-bit binary data. As with `char`, 1-byte alignment is assumed.
|
||||
* Typically a tool will display this as hex or binary.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_BYTE 32
|
||||
|
||||
/**
|
||||
* These types do not have standardized equivalents. It is assumed that the
|
||||
* number at the end corresponds to the bits used to store the value and that
|
||||
* the alignment corresponds to standardized types of the same size.
|
||||
* A tool may not support these types.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_INT128 33
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UINT128 34
|
||||
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_FLOAT16 42
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_FLOAT32 43
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_FLOAT64 44
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_FLOAT128 45
|
||||
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_BF16 50
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TF32 52
|
||||
|
||||
/**
|
||||
* These types are normalized numbers stored in integers. UNORMs represent 0.0
|
||||
* to 1.0 and SNORMs represent -1.0 to 1.0. The number after represents the
|
||||
* number of integer bits. Alignment is take from equivalent types INT# matching
|
||||
* to SNORM# and UINT# matching to UNORM#.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_SNORM8 61
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UNORM8 62
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_SNORM16 63
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UNORM16 64
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_SNORM32 65
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UNORM32 66
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_SNORM64 67
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UNORM64 68
|
||||
|
||||
/**
|
||||
* String types.
|
||||
*
|
||||
* If `arrayOrUnionDetail` is greater than `0`, the entry is a fixed-size string
|
||||
* with the provided length.
|
||||
*
|
||||
* `NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_FIXED_SIZE` is ignored for string types. It
|
||||
* just specifies once more that the entry is a fixed-size string.
|
||||
*
|
||||
* Setting the flag `NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_ZERO_TERMINATED` indicates a
|
||||
* zero-terminated string. If `arrayOrUnionDetail` is greater than `0`, a zero-
|
||||
* terminated array of fixed-size strings is assumed.
|
||||
*
|
||||
* Setting the flag `NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_LENGTH_INDEX` specifies the
|
||||
* entry index of the entry which contains the string length. It is not possible
|
||||
* to describe a variable length array of strings.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_CSTRING 75 /* `char*`, system LOCALE */
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_CSTRING_UTF8 76
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_CSTRING_UTF16 77
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_CSTRING_UTF32 78
|
||||
|
||||
/**
|
||||
* @ref nvtxStringHandle_t returned by @ref nvtxDomainRegisterString
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_NVTX_REGISTERED_STRING_HANDLE 80
|
||||
|
||||
/**
|
||||
* Entry types to be used in deferred events. Data types are as defined by
|
||||
* NVTXv3 core: category -> uint32_t, color -> uint32_t, color type -> int32_t.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_NVTX_CATEGORY 90
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_NVTX_COLORTYPE 91
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_NVTX_COLOR 92
|
||||
|
||||
/**
|
||||
* This type marks the union selector member (entry index) in schemas used by
|
||||
* a union with internal internal selector.
|
||||
* See @ref NVTX_PAYLOAD_SCHEMA_TYPE_UNION_WITH_INTERNAL_SELECTOR.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_UNION_SELECTOR 100
|
||||
|
||||
/**
|
||||
* Timestamp types occupy the range from 128 to 255
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP64 128 /* data type is uint64_t */
|
||||
|
||||
/**
|
||||
* CPU timestamp sources.
|
||||
* \todo All 64 bits?
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_TSC 129
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_TSC_NONVIRTUALIZED 130
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_CLOCK_GETTIME_REALTIME 131
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_CLOCK_GETTIME_REALTIME_COARSE 132
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_CLOCK_GETTIME_MONOTONIC 133
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_CLOCK_GETTIME_MONOTONIC_RAW 134
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_CLOCK_GETTIME_MONOTONIC_COARSE 135
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_CLOCK_GETTIME_BOOTTIME 136
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_CLOCK_GETTIME_PROCESS_CPUTIME_ID 137
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPU_CLOCK_GETTIME_THREAD_CPUTIME_ID 138
|
||||
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_WIN_QPC 160
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_WIN_GSTAFT 161
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_WIN_GSTAFTP 162
|
||||
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_C_TIME 163
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_C_CLOCK 164
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_C_TIMESPEC_GET 165
|
||||
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPP_STEADY_CLOCK 166
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPP_HIGH_RESOLUTION_CLOCK 167
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPP_SYSTEM_CLOCK 168
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPP_UTC_CLOCK 169
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPP_TAI_CLOCK 170
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPP_GPS_CLOCK 171
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_CPP_FILE_CLOCK 172
|
||||
|
||||
/**
|
||||
* \brief GPU timestamp sources.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_GPU_GLOBALTIMER 192
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_GPU_SM_CLOCK 193
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_GPU_SM_CLOCK64 194
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_GPU_CUPTI 195
|
||||
|
||||
/**
|
||||
* The timestamp was provided by the NVTX handler’s timestamp routine.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_TIMESTAMP_TOOL_PROVIDED 224
|
||||
|
||||
/**
|
||||
* This predefined schema ID can be used in `nvtxPayloadData_t` to indicate that
|
||||
* the payload is a blob of memory which other payload entries may point into.
|
||||
* A tool will not expose this payload directly.
|
||||
*/
|
||||
#define NVTX_TYPE_PAYLOAD_SCHEMA_REFERENCED 1022
|
||||
|
||||
/**
|
||||
* This predefined schema ID can be used in `nvtxPayloadData_t` to indicate that
|
||||
* the payload is a blob which can be shown with an arbitrary data viewer.
|
||||
*/
|
||||
#define NVTX_TYPE_PAYLOAD_SCHEMA_RAW 1023
|
||||
|
||||
/* Custom (static) schema IDs. */
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_SCHEMA_ID_STATIC_START (1 << 24)
|
||||
|
||||
/* Dynamic schema IDs (generated by the tool) start here. */
|
||||
#define NVTX_PAYLOAD_ENTRY_TYPE_SCHEMA_ID_DYNAMIC_START 4294967296 // 1 << 32
|
||||
|
||||
|
||||
/**
|
||||
* \brief Size and alignment information for predefined payload entry types.
|
||||
*
|
||||
* The struct contains the size and the alignment size in bytes. A respective
|
||||
* array for the predefined types is passed via nvtxExtModuleInfo_t to the NVTX
|
||||
* client/handler. The type (ID) is used as index into this array.
|
||||
*/
|
||||
typedef struct nvtxPayloadEntryTypeInfo_t
|
||||
{
|
||||
uint16_t size;
|
||||
uint16_t align;
|
||||
} nvtxPayloadEntryTypeInfo_t;
|
||||
|
||||
/**
|
||||
* \brief Entry in a schema.
|
||||
*
|
||||
* A payload schema consists of an array of payload schema entries. It is
|
||||
* registered with @ref nvtxPayloadSchemaRegister. `flag` can be set to `0` for
|
||||
* simple values, 'type' is the only "required" field. If not set explicitly,
|
||||
* all other fields are zero-initialized, which means that the entry has no name
|
||||
* and the offset is determined based on self-alignment rules.
|
||||
*
|
||||
* Example schema:
|
||||
* nvtxPayloadSchemaEntry_t desc[] = {
|
||||
* {0, NVTX_EXT_PAYLOAD_TYPE_UINT8, "one byte"},
|
||||
* {0, NVTX_EXT_PAYLOAD_TYPE_INT32, "four bytes"}
|
||||
* };
|
||||
*/
|
||||
typedef struct nvtxPayloadSchemaEntry_t
|
||||
{
|
||||
/**
|
||||
* \brief Flags to augment the basic type.
|
||||
*
|
||||
* This field allows additional properties of the payload entry to be
|
||||
* specified. Valid values are `NVTX_PAYLOAD_ENTRY_FLAG_*`.
|
||||
*/
|
||||
uint64_t flags;
|
||||
|
||||
/**
|
||||
* \brief Predefined payload schema entry type or ID of a registered payload
|
||||
* schema.
|
||||
*/
|
||||
uint64_t type;
|
||||
|
||||
/**
|
||||
* \brief Name of the payload entry. (Optional)
|
||||
*
|
||||
* Providing a name is useful to give a meaning to the associated value.
|
||||
*/
|
||||
const char* name;
|
||||
|
||||
/**
|
||||
* \brief Description of the payload entry. (Optional)
|
||||
*/
|
||||
const char* description;
|
||||
|
||||
/**
|
||||
* \brief String or array length or union selector for union types.
|
||||
*
|
||||
* If @ref type is a C string type, this defines the length of the string.
|
||||
*
|
||||
* If @ref flags specify that the entry is an array, this field defines the
|
||||
* length of the array. See `NVTX_PAYLOAD_ENTRY_FLAG_ARRAY_*` for more
|
||||
* details.
|
||||
*
|
||||
* If @ref type implies that the entry is a union with schema type
|
||||
* @ref NVTX_PAYLOAD_SCHEMA_TYPE_UNION (external selection of the union
|
||||
* member), this field contains the index (starting with 0) to an entry of
|
||||
* integer type in the same schema. The associated field contains the
|
||||
* selected union member.
|
||||
*
|
||||
* @note An array of schema type @ref NVTX_PAYLOAD_SCHEMA_TYPE_UNION is not
|
||||
* supported. @ref NVTX_PAYLOAD_SCHEMA_TYPE_UNION_WITH_INTERNAL_SELECTOR can
|
||||
* be used instead.
|
||||
*/
|
||||
uint64_t arrayOrUnionDetail;
|
||||
|
||||
/**
|
||||
* \brief Offset in the binary payload data (in bytes).
|
||||
*
|
||||
* This field specifies the byte offset from the base address of the actual
|
||||
* binary data (blob) to the data of this entry.
|
||||
*
|
||||
* This is an optional field, but it is recommended to specify this field to
|
||||
* avoid issues in the automatic detection of the offset by a tool/handler.
|
||||
*/
|
||||
uint64_t offset;
|
||||
|
||||
/**
|
||||
* Semantics are not yet defined.
|
||||
*/
|
||||
void* semantics;
|
||||
|
||||
/**
|
||||
* Reserved for future use. Do not use it!
|
||||
*/
|
||||
void* reserved;
|
||||
} nvtxPayloadSchemaEntry_t;
|
||||
|
||||
/**
|
||||
* \brief Binary payload data, size and decoding information.
|
||||
*
|
||||
* An array of nvtxPayloadData_t is passed to the NVTX event attribute payload
|
||||
* member. To attach a single payload the macro @ref NVTX_EXT_PAYLOAD_SET_ATTR
|
||||
* can be used.
|
||||
*/
|
||||
typedef struct nvtxPayloadData_t
|
||||
{
|
||||
/**
|
||||
* The schema ID, which defines the layout of the binary data.
|
||||
*/
|
||||
uint64_t schemaId;
|
||||
|
||||
/**
|
||||
* Size of the binary payload (blob) in bytes.
|
||||
*/
|
||||
size_t size;
|
||||
|
||||
/**
|
||||
* Pointer to the binary payload data.
|
||||
*/
|
||||
const void* payload;
|
||||
} nvtxPayloadData_t;
|
||||
|
||||
/* Helper macros for safe double-cast of pointer to uint64_t value */
|
||||
#ifndef NVTX_POINTER_AS_PAYLOAD_ULLVALUE
|
||||
# ifdef __cplusplus
|
||||
# define NVTX_POINTER_AS_PAYLOAD_ULLVALUE(p) \
|
||||
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(p))
|
||||
# else
|
||||
#define NVTX_POINTER_AS_PAYLOAD_ULLVALUE(p) ((uint64_t)(uintptr_t)p)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#define NVTX_PAYLOAD_CONCAT2(a,b) a##b
|
||||
#define NVTX_PAYLOAD_CONCAT(a,b) NVTX_PAYLOAD_CONCAT2(a,b)
|
||||
#define NVTX_DATA_VAR NVTX_PAYLOAD_CONCAT(nvtxDFDB,__LINE__)
|
||||
|
||||
/**
|
||||
* \brief Helper macro to attach a single payload to an NVTX event attribute.
|
||||
*
|
||||
* @note The NVTX push, start or mark operation must not be in the same or a
|
||||
* nested scope.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_EVTATTR_SET(EVTATTR, SCHEMA_ID, PAYLOAD_ADDR, SIZE) \
|
||||
nvtxPayloadData_t NVTX_DATA_VAR[] = {{SCHEMA_ID, SIZE, PAYLOAD_ADDR}}; \
|
||||
(EVTATTR).payload.ullValue = \
|
||||
NVTX_POINTER_AS_PAYLOAD_ULLVALUE(NVTX_DATA_VAR); \
|
||||
(EVTATTR).payloadType = NVTX_PAYLOAD_TYPE_BINARY; \
|
||||
(EVTATTR).reserved0 = 1;
|
||||
|
||||
/**
|
||||
* \brief Helper macro to attach multiple payloads to an NVTX event attribute.
|
||||
*
|
||||
* The payload data array (`nvtxPayloadData_t`) is passed as first argument to
|
||||
* this macro.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_EVTATTR_SET_MULTIPLE(EVTATTR, PAYLOADS) \
|
||||
(EVTATTR).payloadType = NVTX_PAYLOAD_TYPE_BINARY; \
|
||||
(EVTATTR).reserved0 = sizeof(PAYLOADS)/sizeof(nvtxPayloadData_t); \
|
||||
(EVTATTR).payload.ullValue = NVTX_POINTER_AS_PAYLOAD_ULLVALUE(PAYLOADS);
|
||||
|
||||
|
||||
/**
|
||||
* \brief The payload schema type.
|
||||
*
|
||||
* A schema can be either of these types.
|
||||
*/
|
||||
enum nvtxPayloadSchemaType
|
||||
{
|
||||
NVTX_PAYLOAD_SCHEMA_TYPE_INVALID = 0,
|
||||
|
||||
NVTX_PAYLOAD_SCHEMA_TYPE_STATIC = 1,
|
||||
NVTX_PAYLOAD_SCHEMA_TYPE_DYNAMIC = 2,
|
||||
|
||||
NVTX_PAYLOAD_SCHEMA_TYPE_UNION = 3,
|
||||
NVTX_PAYLOAD_SCHEMA_TYPE_UNION_WITH_INTERNAL_SELECTOR = 4
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Flags for static and dynamic schemas.
|
||||
*/
|
||||
enum nvtxPayloadSchemaFlags
|
||||
{
|
||||
NVTX_PAYLOAD_SCHEMA_FLAG_NONE = 0,
|
||||
|
||||
/**
|
||||
* This flag indicates that a schema and the corresponding payloads can
|
||||
* contain fields which require a deep copy.
|
||||
*/
|
||||
NVTX_PAYLOAD_SCHEMA_FLAG_DEEP_COPY = (1 << 1),
|
||||
|
||||
/**
|
||||
* This flag indicates that a schema and the corresponding payloads can
|
||||
* be referenced by another payload of the same event.
|
||||
*/
|
||||
NVTX_PAYLOAD_SCHEMA_FLAG_REFERENCED = (1 << 2),
|
||||
|
||||
/**
|
||||
* The schema describes a deferred event/marker. Such a schema requires one
|
||||
* timestamp entry and one string entry with the flag
|
||||
* `NVTX_PAYLOAD_ENTRY_FLAG_EVENT_MESSAGE`. Category and color can be
|
||||
* optionally specified with the respective entry types. The deferred event
|
||||
* can contain a binary payload itself by using a custom schema ID as type
|
||||
* its schema description. Multiple occurrences of the same event can be
|
||||
* described by specifying an array timestamps.
|
||||
*/
|
||||
NVTX_PAYLOAD_SCHEMA_FLAG_DEFERRED_EVENT = (1 << 3),
|
||||
/**
|
||||
* The schema describes a deferred event/marker. Such a schema requires
|
||||
* one start timestamp, one end timestamp and one string entry with the flag
|
||||
* `NVTX_PAYLOAD_ENTRY_FLAG_EVENT_MESSAGE`. Category and color can be
|
||||
* optionally specified with the respective entry types. The deferred range
|
||||
* can contain a binary payload itself by using a custom schema ID as type
|
||||
* its schema description.
|
||||
*
|
||||
* Timestamps can be provided in different ways:
|
||||
* - A single range has two timestamp entries with the first (smaller entry
|
||||
* index) being used as the start/push timestamp.
|
||||
* - If the range schema contains one array of timestamps, the tool assumes
|
||||
* that the array contains alternating start and end timestamps.
|
||||
* - If two timestamp arrays are specified the first entry (with the
|
||||
* smaller entry index) is assumed to contain the start timestamps. Both
|
||||
* arrays have to be of the same size.
|
||||
*/
|
||||
NVTX_PAYLOAD_SCHEMA_FLAG_DEFERRED_RANGE = (2 << 3)
|
||||
};
|
||||
|
||||
/**
|
||||
* The values allow the valid fields in @ref nvtxPayloadSchemaAttr_t to be
|
||||
* specified via setting the field `fieldMask`.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_SCHEMA_ATTR_NAME (1 << 1)
|
||||
#define NVTX_PAYLOAD_SCHEMA_ATTR_TYPE (1 << 2)
|
||||
#define NVTX_PAYLOAD_SCHEMA_ATTR_FLAGS (1 << 3)
|
||||
#define NVTX_PAYLOAD_SCHEMA_ATTR_ENTRIES (1 << 4)
|
||||
#define NVTX_PAYLOAD_SCHEMA_ATTR_NUM_ENTRIES (1 << 5)
|
||||
#define NVTX_PAYLOAD_SCHEMA_ATTR_STATIC_SIZE (1 << 6)
|
||||
#define NVTX_PAYLOAD_SCHEMA_ATTR_ALIGNMENT (1 << 7)
|
||||
#define NVTX_PAYLOAD_SCHEMA_ATTR_SCHEMA_ID (1 << 8)
|
||||
|
||||
/**
|
||||
* NVTX payload schema attributes.
|
||||
*/
|
||||
typedef struct nvtxPayloadSchemaAttr_t
|
||||
{
|
||||
/**
|
||||
* \brief Mask of valid fields in this structure.
|
||||
*
|
||||
* The values from `enum nvtxPayloadSchemaAttributes` have to be used.
|
||||
*/
|
||||
uint64_t fieldMask;
|
||||
|
||||
/**
|
||||
* \brief Name of the payload schema. (Optional)
|
||||
*/
|
||||
const char* name;
|
||||
|
||||
/**
|
||||
* \brief Payload schema type. (Mandatory) \anchor PAYLOAD_TYPE_FIELD
|
||||
*
|
||||
* A value from `enum nvtxPayloadSchemaType` has to be used.
|
||||
*/
|
||||
uint64_t type;
|
||||
|
||||
/**
|
||||
* \brief Payload schema flags. (Optional)
|
||||
*
|
||||
* Flags defined in `enum nvtxPayloadSchemaFlags` can be used to set
|
||||
* additional properties of the schema.
|
||||
*/
|
||||
uint64_t flags;
|
||||
|
||||
/**
|
||||
* \brief Entries of a payload schema. (Mandatory) \anchor ENTRIES_FIELD
|
||||
*
|
||||
* This field is a pointer to an array of schema entries, each describing a
|
||||
* field in a data structure, e.g. in a C struct or union.
|
||||
*/
|
||||
const nvtxPayloadSchemaEntry_t* entries;
|
||||
|
||||
/**
|
||||
* \brief Number of entries in the payload schema. (Mandatory)
|
||||
*
|
||||
* Number of entries in the array of payload entries \ref ENTRIES_FIELD.
|
||||
*/
|
||||
size_t numEntries;
|
||||
|
||||
/**
|
||||
* \brief The binary payload size in bytes for static payload schemas.
|
||||
*
|
||||
* If \ref PAYLOAD_TYPE_FIELD is @ref NVTX_PAYLOAD_SCHEMA_TYPE_DYNAMIC this
|
||||
* value is ignored. If this field is not specified for a schema of type
|
||||
* @ref NVTX_PAYLOAD_SCHEMA_TYPE_STATIC, the size can be automatically
|
||||
* determined by a tool.
|
||||
*/
|
||||
size_t payloadStaticSize;
|
||||
|
||||
/**
|
||||
* \brief The byte alignment for packed structures.
|
||||
*
|
||||
* If not specified, this field defaults to `0`, which means that the fields
|
||||
* in the data structure are not packed and natural alignment rules can be
|
||||
* applied.
|
||||
*/
|
||||
size_t packAlign;
|
||||
|
||||
/* Static/custom schema ID must be
|
||||
>= NVTX_PAYLOAD_ENTRY_TYPE_SCHEMA_ID_STATIC_START and
|
||||
< NVTX_PAYLOAD_ENTRY_TYPE_SCHEMA_ID_DYNAMIC_START */
|
||||
uint64_t schemaId;
|
||||
} nvtxPayloadSchemaAttr_t;
|
||||
|
||||
/**
|
||||
* \brief Register a payload schema.
|
||||
*
|
||||
* @param domain NVTX domain handle.
|
||||
* @param attr NVTX payload schema attributes.
|
||||
*/
|
||||
NVTX_DECLSPEC uint64_t NVTX_API nvtxPayloadSchemaRegister(
|
||||
nvtxDomainHandle_t domain, const nvtxPayloadSchemaAttr_t* attr);
|
||||
|
||||
/**
|
||||
* \brief Enumeration entry.
|
||||
*
|
||||
* Since the value of an enum entry might not be meaningful for the analysis,
|
||||
* a tool can show the name of enum entry instead.
|
||||
*
|
||||
* @note EXPERIMENTAL
|
||||
*/
|
||||
typedef struct nvtxPayloadEnum_t
|
||||
{
|
||||
/**
|
||||
* Name of the enum value.
|
||||
*/
|
||||
const char* name;
|
||||
|
||||
/**
|
||||
* Value of the enum entry.
|
||||
*/
|
||||
uint64_t value;
|
||||
|
||||
/**
|
||||
* Indicates that this entry sets a specific set of bits, which can be used
|
||||
* to easily define bitsets.
|
||||
*/
|
||||
int8_t isFlag;
|
||||
} nvtxPayloadEnum_t;
|
||||
|
||||
/**
|
||||
* The values are used to set the field `fieldMask` and specify which fields in
|
||||
* `nvtxPayloadEnumAttr_t` are set.
|
||||
*/
|
||||
#define NVTX_PAYLOAD_ENUM_ATTR_NAME (1 << 1)
|
||||
#define NVTX_PAYLOAD_ENUM_ATTR_ENTRIES (1 << 2)
|
||||
#define NVTX_PAYLOAD_ENUM_ATTR_NUM_ENTRIES (1 << 3)
|
||||
#define NVTX_PAYLOAD_ENUM_ATTR_SIZE (1 << 4)
|
||||
#define NVTX_PAYLOAD_ENUM_ATTR_SCHEMA_ID (1 << 5)
|
||||
|
||||
/**
|
||||
* NVTX payload enumeration type attributes.
|
||||
*/
|
||||
typedef struct nvtxPayloadEnumAttr_t {
|
||||
/**
|
||||
* Mask of valid fields in this struct.
|
||||
* The values from `enum nvtxPayloadSchemaAttributes` have to be used.
|
||||
*/
|
||||
uint64_t fieldMask;
|
||||
|
||||
/**
|
||||
* Name of the enum. (Optional)
|
||||
*/
|
||||
const char* name;
|
||||
|
||||
/**
|
||||
* Entries of the enum. (Mandatory)
|
||||
*/
|
||||
const nvtxPayloadEnum_t* entries;
|
||||
|
||||
/**
|
||||
* Number of entries in the enum. (Mandatory)
|
||||
*/
|
||||
size_t numEntries;
|
||||
|
||||
/**
|
||||
* Size of enumeration type in bytes
|
||||
*/
|
||||
size_t sizeOfEnum;
|
||||
|
||||
/**
|
||||
* Static/custom schema ID must be
|
||||
* >= NVTX_PAYLOAD_ENTRY_TYPE_SCHEMA_ID_STATIC_START and
|
||||
* < NVTX_PAYLOAD_ENTRY_TYPE_SCHEMA_ID_DYNAMIC_START
|
||||
*/
|
||||
uint64_t schemaId;
|
||||
} nvtxPayloadEnumAttr_t;
|
||||
|
||||
/**
|
||||
* \brief Register an enumeration type with the payload extension.
|
||||
*
|
||||
* @param domain NVTX domain handle
|
||||
* @param attr NVTX payload enumeration type attributes.
|
||||
*/
|
||||
NVTX_DECLSPEC uint64_t nvtxPayloadEnumRegister(nvtxDomainHandle_t domain,
|
||||
const nvtxPayloadEnumAttr_t* attr);
|
||||
|
||||
/**
|
||||
* \brief Callback Ids of API functions in the payload extension.
|
||||
*
|
||||
* The NVTX handler can use these values to register a handler function. When
|
||||
* InitializeInjectionNvtxExtension(nvtxExtModuleInfo_t* moduleInfo) is
|
||||
* executed, a handler routine 'handlenvtxPayloadRegisterSchema' can be
|
||||
* registered as follows:
|
||||
* moduleInfo->segments->slots[NVTX3EXT_CBID_nvtxPayloadSchemaRegister] =
|
||||
* (intptr_t)handlenvtxPayloadRegisterSchema;
|
||||
*/
|
||||
typedef enum NvtxExtPayloadCallbackId
|
||||
{
|
||||
NVTX3EXT_CBID_nvtxPayloadSchemaRegister = 0,
|
||||
NVTX3EXT_CBID_nvtxPayloadEnumRegister = 1,
|
||||
NVTX3EXT_CBID_PAYLOAD_FN_NUM = 2
|
||||
} NvtxExtPayloadCallbackId;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC visibility push(internal)
|
||||
#endif
|
||||
|
||||
#define NVTX_EXT_TYPES_GUARD /* Ensure other headers cannot include directly */
|
||||
#include "nvtxExtDetail/nvtxExtTypes.h"
|
||||
#undef NVTX_EXT_TYPES_GUARD
|
||||
|
||||
#ifndef NVTX_NO_IMPL
|
||||
#define NVTX_EXT_IMPL_PAYLOAD_GUARD /* Ensure other headers cannot included directly */
|
||||
#include "nvtxExtDetail/nvtxExtPayloadTypeInfo.h"
|
||||
#include "nvtxExtDetail/nvtxExtImplPayload_v1.h"
|
||||
#undef NVTX_EXT_IMPL_PAYLOAD_GUARD
|
||||
#endif /*NVTX_NO_IMPL*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* NVTOOLSEXT_PAYLOAD_H */
|
||||
@@ -16,10 +16,10 @@ extern "C" {
|
||||
|
||||
typedef void (NVTX_API * nvtxNameCudaDeviceA_impl_fntype)(int device, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCudaDeviceW_impl_fntype)(int device, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCudaStreamA_impl_fntype)(hipStream_t stream, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCudaStreamW_impl_fntype)(hipStream_t stream, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCudaEventA_impl_fntype)(hipEvent_t event, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCudaEventW_impl_fntype)(hipEvent_t event, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCudaStreamA_impl_fntype)(cudaStream_t stream, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCudaStreamW_impl_fntype)(cudaStream_t stream, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCudaEventA_impl_fntype)(cudaEvent_t event, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCudaEventW_impl_fntype)(cudaEvent_t event, const wchar_t* name);
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaDeviceA(int device, const char* name)
|
||||
{
|
||||
@@ -39,7 +39,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCudaDeviceW(int device, const wchar_t* name)
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamA(hipStream_t stream, const char* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamA(cudaStream_t stream, const char* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCudaStreamA_impl_fntype local = (nvtxNameCudaStreamA_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCudaStreamA_impl_fnptr;
|
||||
@@ -48,7 +48,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamA(hipStream_t stream, const char*
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamW(hipStream_t stream, const wchar_t* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamW(cudaStream_t stream, const wchar_t* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCudaStreamW_impl_fntype local = (nvtxNameCudaStreamW_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCudaStreamW_impl_fnptr;
|
||||
@@ -57,7 +57,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCudaStreamW(hipStream_t stream, const wchar_
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaEventA(hipEvent_t event, const char* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaEventA(cudaEvent_t event, const char* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCudaEventA_impl_fntype local = (nvtxNameCudaEventA_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCudaEventA_impl_fnptr;
|
||||
@@ -66,7 +66,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCudaEventA(hipEvent_t event, const char* nam
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaEventW(hipEvent_t event, const wchar_t* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCudaEventW(cudaEvent_t event, const wchar_t* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCudaEventW_impl_fntype local = (nvtxNameCudaEventW_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCudaEventW_impl_fnptr;
|
||||
|
||||
@@ -15,16 +15,16 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef void (NVTX_API * nvtxNameCuDeviceA_impl_fntype)(hipDevice_t device, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCuDeviceW_impl_fntype)(hipDevice_t device, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCuContextA_impl_fntype)(hipCtx_t context, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCuContextW_impl_fntype)(hipCtx_t context, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCuStreamA_impl_fntype)(hipStream_t stream, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCuStreamW_impl_fntype)(hipStream_t stream, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCuEventA_impl_fntype)(hipEvent_t event, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCuEventW_impl_fntype)(hipEvent_t event, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCuDeviceA_impl_fntype)(CUdevice device, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCuDeviceW_impl_fntype)(CUdevice device, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCuContextA_impl_fntype)(CUcontext context, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCuContextW_impl_fntype)(CUcontext context, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCuStreamA_impl_fntype)(CUstream stream, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCuStreamW_impl_fntype)(CUstream stream, const wchar_t* name);
|
||||
typedef void (NVTX_API * nvtxNameCuEventA_impl_fntype)(CUevent event, const char* name);
|
||||
typedef void (NVTX_API * nvtxNameCuEventW_impl_fntype)(CUevent event, const wchar_t* name);
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceA(hipDevice_t device, const char* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceA(CUdevice device, const char* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCuDeviceA_impl_fntype local = (nvtxNameCuDeviceA_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCuDeviceA_impl_fnptr;
|
||||
@@ -33,7 +33,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceA(hipDevice_t device, const char* na
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceW(hipDevice_t device, const wchar_t* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceW(CUdevice device, const wchar_t* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCuDeviceW_impl_fntype local = (nvtxNameCuDeviceW_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCuDeviceW_impl_fnptr;
|
||||
@@ -42,7 +42,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuDeviceW(hipDevice_t device, const wchar_t*
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuContextA(hipCtx_t context, const char* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuContextA(CUcontext context, const char* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCuContextA_impl_fntype local = (nvtxNameCuContextA_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCuContextA_impl_fnptr;
|
||||
@@ -51,7 +51,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuContextA(hipCtx_t context, const char* nam
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuContextW(hipCtx_t context, const wchar_t* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuContextW(CUcontext context, const wchar_t* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCuContextW_impl_fntype local = (nvtxNameCuContextW_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCuContextW_impl_fnptr;
|
||||
@@ -60,7 +60,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuContextW(hipCtx_t context, const wchar_t*
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamA(hipStream_t stream, const char* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamA(CUstream stream, const char* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCuStreamA_impl_fntype local = (nvtxNameCuStreamA_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCuStreamA_impl_fnptr;
|
||||
@@ -69,7 +69,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamA(hipStream_t stream, const char* na
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamW(hipStream_t stream, const wchar_t* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamW(CUstream stream, const wchar_t* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCuStreamW_impl_fntype local = (nvtxNameCuStreamW_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCuStreamW_impl_fnptr;
|
||||
@@ -78,7 +78,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuStreamW(hipStream_t stream, const wchar_t*
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuEventA(hipEvent_t event, const char* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuEventA(CUevent event, const char* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCuEventA_impl_fntype local = (nvtxNameCuEventA_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCuEventA_impl_fnptr;
|
||||
@@ -87,7 +87,7 @@ NVTX_DECLSPEC void NVTX_API nvtxNameCuEventA(hipEvent_t event, const char* name)
|
||||
#endif /*NVTX_DISABLE*/
|
||||
}
|
||||
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuEventW(hipEvent_t event, const wchar_t* name)
|
||||
NVTX_DECLSPEC void NVTX_API nvtxNameCuEventW(CUevent event, const wchar_t* name)
|
||||
{
|
||||
#ifndef NVTX_DISABLE
|
||||
nvtxNameCuEventW_impl_fntype local = (nvtxNameCuEventW_impl_fntype)NVTX_VERSIONED_IDENTIFIER(nvtxGlobals).nvtxNameCuEventW_impl_fnptr;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
/* ------ Dependency-free types binary-compatible with real types ------- */
|
||||
|
||||
/* In order to avoid having the NVTX core API headers depend on non-NVTX
|
||||
* headers like hip/hip_runtime.h, NVTX defines binary-compatible types to use for
|
||||
* headers like cuda.h, NVTX defines binary-compatible types to use for
|
||||
* safely making the initialization versions of all NVTX functions without
|
||||
* needing to have definitions for the real types. */
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2009-2020 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License v2.0 with LLVM Exceptions.
|
||||
* See https://llvm.org/LICENSE.txt for license information.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef NVTX_EXT_IMPL_GUARD
|
||||
#error Never include this file directly -- it is automatically included by nvToolsExt.h (except when NVTX_NO_IMPL is defined).
|
||||
#endif
|
||||
|
||||
#ifndef NVTX_EXT_IMPL_H
|
||||
#define NVTX_EXT_IMPL_H
|
||||
/* ---- Include required platform headers ---- */
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/api-level.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(__CYGWIN__)
|
||||
#include <sched.h>
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#endif
|
||||
|
||||
/* ---- Define macros used in this file ---- */
|
||||
|
||||
#ifdef NVTX_DEBUG_PRINT
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
#define NVTX_ERR(...) __android_log_print(ANDROID_LOG_ERROR, "NVTOOLSEXT", __VA_ARGS__);
|
||||
#define NVTX_INFO(...) __android_log_print(ANDROID_LOG_INFO, "NVTOOLSEXT", __VA_ARGS__);
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define NVTX_ERR(...) fprintf(stderr, "NVTX_ERROR: " __VA_ARGS__)
|
||||
#define NVTX_INFO(...) fprintf(stderr, "NVTX_INFO: " __VA_ARGS__)
|
||||
#endif
|
||||
#else /* !defined(NVTX_DEBUG_PRINT) */
|
||||
#define NVTX_ERR(...)
|
||||
#define NVTX_INFO(...)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
// #ifdef __GNUC__
|
||||
// #pragma GCC visibility push(hidden)
|
||||
// #endif
|
||||
|
||||
#define NVTX_EXTENSION_FRESH 0
|
||||
#define NVTX_EXTENSION_DISABLED 1
|
||||
#define NVTX_EXTENSION_STARTING 2
|
||||
#define NVTX_EXTENSION_LOADED 3
|
||||
|
||||
NVTX_LINKONCE_DEFINE_GLOBAL NvtxExtInitializeInjectionFunc_t NVTX_VERSIONED_IDENTIFIER(injectionFnPtr) = (NvtxExtInitializeInjectionFunc_t)0;
|
||||
|
||||
#define NVTX_EXT_INIT_GUARD
|
||||
#include "nvtxExtInit.h"
|
||||
#undef NVTX_EXT_INIT_GUARD
|
||||
|
||||
// #ifdef __GNUC__
|
||||
// #pragma GCC visibility pop
|
||||
// #endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* NVTX_EXT_IMPL_H */
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2021 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License v2.0 with LLVM Exceptions.
|
||||
* See https://llvm.org/LICENSE.txt for license information.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef NVTX_EXT_IMPL_PAYLOAD_GUARD
|
||||
#error Never include this file directly -- it is automatically included by nvToolsExtPayload.h (except when NVTX_NO_IMPL is defined).
|
||||
#endif
|
||||
|
||||
#define NVTX_EXT_IMPL_GUARD
|
||||
#include "nvtxExtImpl.h"
|
||||
#undef NVTX_EXT_IMPL_GUARD
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define NVTX_EXT_PAYLOAD_VERSIONED_IDENTIFIER_L3(NAME, VERSION, COMPATID) \
|
||||
NAME##_v##VERSION##_mem##COMPATID
|
||||
#define NVTX_EXT_PAYLOAD_VERSIONED_IDENTIFIER_L2(NAME, VERSION, COMPATID) \
|
||||
NVTX_EXT_PAYLOAD_VERSIONED_IDENTIFIER_L3(NAME, VERSION, COMPATID)
|
||||
#define NVTX_EXT_PAYLOAD_VERSIONED_ID(NAME) \
|
||||
NVTX_EXT_PAYLOAD_VERSIONED_IDENTIFIER_L2(NAME, NVTX_VERSION, NVTX_EXT_COMPATID_PAYLOAD)
|
||||
|
||||
/*
|
||||
* Function slots for the binary payload extension. First entry is the module
|
||||
* state, initialized to `0` (`NVTX_EXTENSION_FRESH`).
|
||||
*/
|
||||
NVTX_LINKONCE_DEFINE_GLOBAL intptr_t
|
||||
NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots)[NVTX3EXT_CBID_PAYLOAD_FN_NUM + 1]
|
||||
= {0};
|
||||
|
||||
NVTX_LINKONCE_DEFINE_FUNCTION void NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadInitOnce)()
|
||||
{
|
||||
nvtxExtModuleSegment_t segment = {
|
||||
0, // unused (only one segment)
|
||||
NVTX3EXT_CBID_PAYLOAD_FN_NUM,
|
||||
NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots) + 1
|
||||
};
|
||||
|
||||
nvtxExtModuleInfo_t module = {
|
||||
NVTX_VERSION, sizeof(nvtxExtModuleInfo_t),
|
||||
NVTX_EXT_MODULEID_PAYLOAD, NVTX_EXT_COMPATID_PAYLOAD,
|
||||
1, &segment, // number of segments, segments
|
||||
NULL, // no export function needed
|
||||
// bake type sizes and alignment information into program binary
|
||||
&nvtxExtPayloadTypeInfo
|
||||
};
|
||||
|
||||
NVTX_INFO( "%s\n", __FUNCTION__ );
|
||||
|
||||
NVTX_VERSIONED_IDENTIFIER(nvtxExtInitOnce)(&module,
|
||||
NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots));
|
||||
}
|
||||
|
||||
#define NVTX_EXT_FN_IMPL(ret_val, fn_name, signature, arg_names) \
|
||||
typedef ret_val ( * fn_name##_impl_fntype )signature; \
|
||||
NVTX_LINKONCE_DEFINE_FUNCTION ret_val fn_name signature { \
|
||||
intptr_t slot = NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots)[NVTX3EXT_CBID_##fn_name + 1]; \
|
||||
if (slot != NVTX_EXTENSION_DISABLED) { \
|
||||
if (slot) { \
|
||||
return (*(fn_name##_impl_fntype)slot) arg_names; \
|
||||
} else { \
|
||||
NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadInitOnce)(); \
|
||||
slot = NVTX_EXT_PAYLOAD_VERSIONED_ID(nvtxExtPayloadSlots)[NVTX3EXT_CBID_##fn_name + 1]; \
|
||||
if (slot != NVTX_EXTENSION_DISABLED && slot) { \
|
||||
return (*(fn_name##_impl_fntype)slot) arg_names; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
return ((ret_val)(intptr_t)-1); \
|
||||
}
|
||||
|
||||
NVTX_EXT_FN_IMPL(uint64_t, nvtxPayloadSchemaRegister, (nvtxDomainHandle_t domain, const nvtxPayloadSchemaAttr_t* attr), (domain, attr))
|
||||
|
||||
NVTX_EXT_FN_IMPL(uint64_t, nvtxPayloadEnumRegister, (nvtxDomainHandle_t domain, const nvtxPayloadEnumAttr_t* attr), (domain, attr))
|
||||
|
||||
#undef NVTX_EXT_FN_IMPL
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
@@ -0,0 +1,363 @@
|
||||
/*
|
||||
* Copyright 2009-2020 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License v2.0 with LLVM Exceptions.
|
||||
* See https://llvm.org/LICENSE.txt for license information.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef NVTX_EXT_INIT_GUARD
|
||||
#error Never include this file directly -- it is automatically included by nvToolsExt.h (except when NVTX_NO_IMPL is defined).
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* ---- Platform-independent helper definitions and functions ---- */
|
||||
|
||||
/* Prefer macros over inline functions to reduce symbol resolution at link time */
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define NVTX_PATHCHAR wchar_t
|
||||
#define NVTX_STR(x) L##x
|
||||
#define NVTX_GETENV _wgetenv
|
||||
#define NVTX_BUFSIZE MAX_PATH
|
||||
#define NVTX_DLLHANDLE HMODULE
|
||||
#define NVTX_DLLOPEN(x) LoadLibraryW(x)
|
||||
#define NVTX_DLLFUNC GetProcAddress
|
||||
#define NVTX_DLLCLOSE FreeLibrary
|
||||
#define NVTX_YIELD() SwitchToThread()
|
||||
#define NVTX_MEMBAR() MemoryBarrier()
|
||||
#define NVTX_ATOMIC_WRITE_32(address, value) InterlockedExchange((volatile LONG*)address, value)
|
||||
#define NVTX_ATOMIC_CAS_32(old, address, exchange, comparand) old = InterlockedCompareExchange((volatile LONG*)address, exchange, comparand)
|
||||
#define NVTX_ATOMIC_WRITE_PTR(address, value) InterlockedExchangePointer((volatile PVOID*)address, (PVOID)value)
|
||||
#define NVTX_ATOMIC_CAS_PTR(old, address, exchange, comparand) old = (intptr_t)InterlockedCompareExchangePointer((volatile PVOID*)address, (PVOID)exchange, (PVOID)comparand)
|
||||
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
#define NVTX_PATHCHAR char
|
||||
#define NVTX_STR(x) x
|
||||
#define NVTX_GETENV getenv
|
||||
#define NVTX_BUFSIZE PATH_MAX
|
||||
#define NVTX_DLLHANDLE void*
|
||||
#define NVTX_DLLOPEN(x) dlopen(x, RTLD_LAZY)
|
||||
#define NVTX_DLLFUNC dlsym
|
||||
#define NVTX_DLLCLOSE dlclose
|
||||
#define NVTX_YIELD() sched_yield()
|
||||
#define NVTX_MEMBAR() __sync_synchronize()
|
||||
/* Ensure full memory barrier for atomics, to match Windows functions */
|
||||
#define NVTX_ATOMIC_WRITE_32(address, value) __sync_synchronize(); __sync_lock_test_and_set(address, value)
|
||||
#define NVTX_ATOMIC_CAS_32(old, address, exchange, comparand) __sync_synchronize(); old = __sync_val_compare_and_swap(address, exchange, comparand)
|
||||
#define NVTX_ATOMIC_WRITE_PTR(address, value) __sync_synchronize(); __sync_lock_test_and_set(address, value)
|
||||
#define NVTX_ATOMIC_CAS_PTR(old, address, exchange, comparand) __sync_synchronize(); old = __sync_val_compare_and_swap(address, exchange, comparand)
|
||||
#else
|
||||
#error The library does not support your configuration!
|
||||
#endif
|
||||
|
||||
/* Define this to 1 for platforms that where pre-injected libraries can be discovered. */
|
||||
#if defined(_WIN32)
|
||||
/* TODO */
|
||||
#define NVTX_SUPPORT_ALREADY_INJECTED_LIBRARY 0
|
||||
#else
|
||||
#define NVTX_SUPPORT_ALREADY_INJECTED_LIBRARY 0
|
||||
#endif
|
||||
|
||||
/* Define this to 1 for platforms that support environment variables */
|
||||
/* TODO: Detect UWP, a.k.a. Windows Store app, and set this to 0. */
|
||||
/* Try: #if defined(WINAPI_FAMILY_PARTITION) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) */
|
||||
#define NVTX_SUPPORT_ENV_VARS 1
|
||||
|
||||
/* Define this to 1 for platforms that support dynamic/shared libraries */
|
||||
#define NVTX_SUPPORT_DYNAMIC_INJECTION_LIBRARY 1
|
||||
|
||||
/* Injection libraries implementing InitializeInjectionNvtxExtension may be statically linked,
|
||||
* and this will override any dynamic injection. Useful for platforms where dynamic
|
||||
* injection is not available. Since weak symbols not explicitly marked extern are
|
||||
* guaranteed to be initialized to zero if no definitions are found by the linker, the
|
||||
* dynamic injection process proceeds normally if pfnInitializeInjectionNvtx2 is 0. */
|
||||
#if defined(__GNUC__) && !defined(_WIN32) && !defined(__CYGWIN__)
|
||||
#define NVTX_SUPPORT_STATIC_INJECTION_LIBRARY 1
|
||||
/* To statically inject an NVTX library, define InitializeInjectionNvtxExtension_fnptr as a normal
|
||||
* symbol (not weak) pointing to the implementation of InitializeInjectionNvtxExtension (which
|
||||
* does not need to be named "InitializeInjectionNvtxExtension" as is necessary in a dynamic
|
||||
* injection library. */
|
||||
__attribute__((weak)) NvtxExtInitializeInjectionFunc_t InitializeInjectionNvtxExtension_fnptr;
|
||||
#else
|
||||
#define NVTX_SUPPORT_STATIC_INJECTION_LIBRARY 0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* This function tries to find or load an NVTX injection library and get the
|
||||
* address of its InitializeInjectionExtension function. If such a function pointer
|
||||
* is found, it is called, and passed the address of this NVTX instance's
|
||||
* nvtxGetExportTable function, so the injection can attach to this instance.
|
||||
* If the initialization fails for any reason, any dynamic library loaded will
|
||||
* be freed, and all NVTX implementation functions will be set to no-ops. If
|
||||
* initialization succeeds, NVTX functions not attached to the tool will be set
|
||||
* to no-ops. This is implemented as one function instead of several small
|
||||
* functions to minimize the number of weak symbols the linker must resolve.
|
||||
* Order of search is:
|
||||
* - Pre-injected library exporting InitializeInjectionNvtxExtension
|
||||
* - Loadable library exporting InitializeInjectionNvtxExtension
|
||||
* - Path specified by env var NVTX_INJECTION??_PATH (?? is 32 or 64)
|
||||
* - On Android, libNvtxInjection??.so within the package (?? is 32 or 64)
|
||||
* - Statically-linked injection library defining InitializeInjectionNvtx2_fnptr
|
||||
*/
|
||||
NVTX_LINKONCE_FWDDECL_FUNCTION int NVTX_VERSIONED_IDENTIFIER(nvtxExtLoadInjectionLibrary)(NvtxExtInitializeInjectionFunc_t* out_init_fnptr);
|
||||
NVTX_LINKONCE_DEFINE_FUNCTION int NVTX_VERSIONED_IDENTIFIER(nvtxExtLoadInjectionLibrary)(NvtxExtInitializeInjectionFunc_t* out_init_fnptr)
|
||||
{
|
||||
const char* const initFuncName = "InitializeInjectionNvtxExtension";
|
||||
NvtxExtInitializeInjectionFunc_t init_fnptr = (NvtxExtInitializeInjectionFunc_t)0;
|
||||
NVTX_DLLHANDLE injectionLibraryHandle = (NVTX_DLLHANDLE)0;
|
||||
|
||||
if(out_init_fnptr){
|
||||
*out_init_fnptr = (NvtxExtInitializeInjectionFunc_t)0;
|
||||
}
|
||||
|
||||
#if NVTX_SUPPORT_ALREADY_INJECTED_LIBRARY
|
||||
/* Use POSIX global symbol chain to query for init function from any module */
|
||||
init_fnptr = (NvtxExtInitializeInjectionFunc_t)NVTX_DLLFUNC(0, initFuncName);
|
||||
#endif
|
||||
|
||||
#if NVTX_SUPPORT_DYNAMIC_INJECTION_LIBRARY
|
||||
/* Try discovering dynamic injection library to load */
|
||||
if (!init_fnptr)
|
||||
{
|
||||
#if NVTX_SUPPORT_ENV_VARS
|
||||
/* If env var NVTX_INJECTION64_PATH is set, it should contain the path
|
||||
* to a 64-bit dynamic NVTX injection library (and similar for 32-bit). */
|
||||
const NVTX_PATHCHAR* const nvtxEnvVarName = (sizeof(void*) == 4)
|
||||
? NVTX_STR("NVTX_INJECTION32_PATH")
|
||||
: NVTX_STR("NVTX_INJECTION64_PATH");
|
||||
#endif /* NVTX_SUPPORT_ENV_VARS */
|
||||
NVTX_PATHCHAR injectionLibraryPathBuf[NVTX_BUFSIZE];
|
||||
const NVTX_PATHCHAR* injectionLibraryPath = (const NVTX_PATHCHAR*)0;
|
||||
|
||||
/* Refer to this variable explicitly in case all references to it are #if'ed out */
|
||||
(void)injectionLibraryPathBuf;
|
||||
|
||||
#if NVTX_SUPPORT_ENV_VARS
|
||||
/* Disable the warning for getenv & _wgetenv -- this usage is safe because
|
||||
* these functions are not called again before using the returned value. */
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4996 )
|
||||
#endif
|
||||
injectionLibraryPath = NVTX_GETENV(nvtxEnvVarName);
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
if (!injectionLibraryPath)
|
||||
{
|
||||
const char *bits = (sizeof(void*) == 4) ? "32" : "64";
|
||||
char cmdlineBuf[32];
|
||||
char pkgName[PATH_MAX];
|
||||
int count;
|
||||
int pid;
|
||||
FILE *fp;
|
||||
size_t bytesRead;
|
||||
size_t pos;
|
||||
|
||||
pid = (int)getpid();
|
||||
count = snprintf(cmdlineBuf, sizeof(cmdlineBuf), "/proc/%d/cmdline", pid);
|
||||
if (count <= 0 || count >= (int)sizeof(cmdlineBuf))
|
||||
{
|
||||
NVTX_ERR("Path buffer too small for: /proc/%d/cmdline\n", pid);
|
||||
return NVTX_ERR_INIT_ACCESS_LIBRARY;
|
||||
}
|
||||
|
||||
fp = fopen(cmdlineBuf, "r");
|
||||
if (!fp)
|
||||
{
|
||||
NVTX_ERR("File couldn't be opened: %s\n", cmdlineBuf);
|
||||
return NVTX_ERR_INIT_ACCESS_LIBRARY;
|
||||
}
|
||||
|
||||
bytesRead = fread(pkgName, 1, sizeof(pkgName) - 1, fp);
|
||||
fclose(fp);
|
||||
if (bytesRead == 0)
|
||||
{
|
||||
NVTX_ERR("Package name couldn't be read from file: %s\n", cmdlineBuf);
|
||||
return NVTX_ERR_INIT_ACCESS_LIBRARY;
|
||||
}
|
||||
|
||||
pkgName[bytesRead] = 0;
|
||||
|
||||
/* String can contain colon as a process separator. In this case the package name is before the colon. */
|
||||
pos = 0;
|
||||
while (pos < bytesRead && pkgName[pos] != ':' && pkgName[pos] != '\0')
|
||||
{
|
||||
++pos;
|
||||
}
|
||||
pkgName[pos] = 0;
|
||||
|
||||
count = snprintf(injectionLibraryPathBuf, NVTX_BUFSIZE, "/data/data/%s/files/libNvtxInjection%s.so", pkgName, bits);
|
||||
if (count <= 0 || count >= NVTX_BUFSIZE)
|
||||
{
|
||||
NVTX_ERR("Path buffer too small for: /data/data/%s/files/libNvtxInjection%s.so\n", pkgName, bits);
|
||||
return NVTX_ERR_INIT_ACCESS_LIBRARY;
|
||||
}
|
||||
|
||||
/* On Android, verify path is accessible due to aggressive file access restrictions. */
|
||||
/* For dlopen, if the filename contains a leading slash, then it is interpreted as a */
|
||||
/* relative or absolute pathname; otherwise it will follow the rules in ld.so. */
|
||||
if (injectionLibraryPathBuf[0] == '/')
|
||||
{
|
||||
#if (__ANDROID_API__ < 21)
|
||||
int access_err = access(injectionLibraryPathBuf, F_OK | R_OK);
|
||||
#else
|
||||
int access_err = faccessat(AT_FDCWD, injectionLibraryPathBuf, F_OK | R_OK, 0);
|
||||
#endif
|
||||
if (access_err != 0)
|
||||
{
|
||||
NVTX_ERR("Injection library path wasn't accessible [code=%s] [path=%s]\n", strerror(errno), injectionLibraryPathBuf);
|
||||
return NVTX_ERR_INIT_ACCESS_LIBRARY;
|
||||
}
|
||||
}
|
||||
injectionLibraryPath = injectionLibraryPathBuf;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* At this point, injectionLibraryPath is specified if a dynamic
|
||||
* injection library was specified by a tool. */
|
||||
if (injectionLibraryPath)
|
||||
{
|
||||
/* Load the injection library */
|
||||
injectionLibraryHandle = NVTX_DLLOPEN(injectionLibraryPath);
|
||||
if (!injectionLibraryHandle)
|
||||
{
|
||||
NVTX_ERR("Failed to load injection library\n");
|
||||
return NVTX_ERR_INIT_LOAD_LIBRARY;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Attempt to get the injection library's entry-point */
|
||||
init_fnptr = (NvtxExtInitializeInjectionFunc_t)NVTX_DLLFUNC(injectionLibraryHandle, initFuncName);
|
||||
if (!init_fnptr)
|
||||
{
|
||||
NVTX_DLLCLOSE(injectionLibraryHandle);
|
||||
NVTX_ERR("Failed to get address of function %s from injection library\n", initFuncName);
|
||||
return NVTX_ERR_INIT_MISSING_LIBRARY_ENTRY_POINT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NVTX_SUPPORT_STATIC_INJECTION_LIBRARY
|
||||
if (!init_fnptr)
|
||||
{
|
||||
/* Check weakly-defined function pointer. A statically-linked injection can define this as
|
||||
* a normal symbol and it will take precedence over a dynamic injection. */
|
||||
if (InitializeInjectionNvtxExtension_fnptr)
|
||||
{
|
||||
init_fnptr = InitializeInjectionNvtxExtension_fnptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(out_init_fnptr){
|
||||
*out_init_fnptr = init_fnptr;
|
||||
}
|
||||
|
||||
/* At this point, if init_fnptr is not set, then no tool has specified
|
||||
* an NVTX injection library -- return non-success result so all NVTX
|
||||
* API functions will be set to no-ops. */
|
||||
if (!init_fnptr)
|
||||
{
|
||||
return NVTX_ERR_NO_INJECTION_LIBRARY_AVAILABLE;
|
||||
}
|
||||
|
||||
return NVTX_SUCCESS;
|
||||
}
|
||||
|
||||
NVTX_LINKONCE_DEFINE_FUNCTION void NVTX_VERSIONED_IDENTIFIER(nvtxExtInitOnce) (
|
||||
nvtxExtModuleInfo_t* moduleInfo,
|
||||
intptr_t* moduleState
|
||||
)
|
||||
{
|
||||
intptr_t old;
|
||||
|
||||
NVTX_INFO( "%s\n", __FUNCTION__ );
|
||||
|
||||
if( *moduleState == NVTX_EXTENSION_LOADED) {
|
||||
return;
|
||||
}
|
||||
|
||||
NVTX_ATOMIC_CAS_PTR(
|
||||
old,
|
||||
moduleState,
|
||||
NVTX_EXTENSION_STARTING,
|
||||
NVTX_EXTENSION_FRESH);
|
||||
if (old == NVTX_EXTENSION_FRESH)
|
||||
{
|
||||
NvtxExtInitializeInjectionFunc_t init_fnptr = NVTX_VERSIONED_IDENTIFIER(injectionFnPtr);
|
||||
int entryPointStatus = 0;
|
||||
int forceAllToNoops = 0;
|
||||
|
||||
/* Load & initialize injection library -- it will assign the function pointers */
|
||||
if(init_fnptr == 0){
|
||||
int result = 0;
|
||||
|
||||
/* try to load vanilla NVTX first*/
|
||||
nvtxInitialize(0);
|
||||
|
||||
result = NVTX_VERSIONED_IDENTIFIER(nvtxExtLoadInjectionLibrary)(&init_fnptr);
|
||||
/*at this point init_fnptr will be either 0 or a real function*/
|
||||
|
||||
if(result == NVTX_SUCCESS) {
|
||||
NVTX_VERSIONED_IDENTIFIER(injectionFnPtr) = init_fnptr;
|
||||
}
|
||||
else {
|
||||
NVTX_ERR("Failed to load injection library\n");
|
||||
}
|
||||
}
|
||||
|
||||
if(init_fnptr != 0) {
|
||||
/* Invoke injection library's initialization function. If it returns
|
||||
* 0 (failure) and a dynamic injection was loaded, unload it. */
|
||||
entryPointStatus = init_fnptr(moduleInfo);
|
||||
if (entryPointStatus == 0) {
|
||||
NVTX_ERR("Failed to initialize injection library -- initialization function returned 0\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up any functions that are still uninitialized so that they are skipped.
|
||||
* Set all to null if injection init function failed as well.
|
||||
*/
|
||||
forceAllToNoops = (init_fnptr == 0) || (entryPointStatus == 0);
|
||||
for(size_t s = 0; s < moduleInfo->segmentsCount; ++s){
|
||||
nvtxExtModuleSegment_t* segment = moduleInfo->segments+s;
|
||||
for(size_t i = 0; i < segment->slotCount; ++i){
|
||||
if(forceAllToNoops || (segment->functionSlots[i] == NVTX_EXTENSION_FRESH)){
|
||||
segment->functionSlots[i] = NVTX_EXTENSION_DISABLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NVTX_MEMBAR();
|
||||
|
||||
/* Signal that initialization has finished, so now the assigned function pointers will be used */
|
||||
NVTX_ATOMIC_WRITE_PTR(
|
||||
moduleState,
|
||||
NVTX_EXTENSION_LOADED);
|
||||
}
|
||||
else /* Spin-wait until initialization has finished */
|
||||
{
|
||||
NVTX_MEMBAR();
|
||||
while (*moduleState != NVTX_EXTENSION_LOADED)
|
||||
{
|
||||
NVTX_YIELD();
|
||||
NVTX_MEMBAR();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
@@ -0,0 +1,128 @@
|
||||
#ifndef NVTX_EXT_IMPL_PAYLOAD_GUARD
|
||||
#error Never include this file directly -- it is automatically included by nvToolsExtPayload.h (except when NVTX_NO_IMPL is defined).
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Helper array to get the alignment for each predefined C language type.
|
||||
*/
|
||||
|
||||
typedef void* pointer_type;
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L /* or CPP11 */
|
||||
#include <stdalign.h>
|
||||
#define nvtx_alignof(type) alignof(type)
|
||||
#define nvtx_alignof2(type,tname) alignof(type)
|
||||
#else /* __STDC_VERSION__ >= 201112L */
|
||||
#ifndef __cplusplus
|
||||
|
||||
#include <stddef.h>
|
||||
#define nvtx_alignof(type) offsetof(struct {char c; type d;}, d)
|
||||
#define nvtx_alignof2(type,tname) nvtx_alignof(type)
|
||||
|
||||
#else /* __cplusplus */
|
||||
|
||||
#define MKTYPEDEF(TYPE) typedef struct {char c; TYPE d;} _nvtx_##TYPE
|
||||
#define MKTYPEDEF2(TYPE,TNAME) typedef struct {char c; TYPE d;} _nvtx_##TNAME
|
||||
#define nvtx_alignof(TNAME) offsetof(_nvtx_##TNAME, d)
|
||||
#define nvtx_alignof2(type,tname) offsetof(_nvtx_##tname, d)
|
||||
|
||||
MKTYPEDEF(char);
|
||||
MKTYPEDEF2(unsigned char, uchar);
|
||||
MKTYPEDEF(short);
|
||||
MKTYPEDEF2(unsigned short, ushort);
|
||||
MKTYPEDEF(int);
|
||||
MKTYPEDEF2(unsigned int, uint);
|
||||
MKTYPEDEF(long);
|
||||
MKTYPEDEF2(unsigned long, ulong);
|
||||
MKTYPEDEF2(long long, longlong);
|
||||
MKTYPEDEF2(unsigned long long, ulonglong);
|
||||
|
||||
MKTYPEDEF(int8_t);
|
||||
MKTYPEDEF(uint8_t);
|
||||
MKTYPEDEF(int16_t);
|
||||
MKTYPEDEF(uint16_t);
|
||||
MKTYPEDEF(int32_t);
|
||||
MKTYPEDEF(uint32_t);
|
||||
MKTYPEDEF(int64_t);
|
||||
MKTYPEDEF(uint64_t);
|
||||
|
||||
MKTYPEDEF(float);
|
||||
MKTYPEDEF(double);
|
||||
MKTYPEDEF2(long double, longdouble);
|
||||
|
||||
MKTYPEDEF(size_t);
|
||||
MKTYPEDEF(pointer_type);
|
||||
|
||||
MKTYPEDEF(wchar_t);
|
||||
#if (__STDC_VERSION__ > 201710L) || (defined(__cplusplus) && __cplusplus > 201703L)
|
||||
{sizeof(char8_t), nvtx_alignof(char8_t)},
|
||||
MKTYPEDEF(char8_t);
|
||||
#endif
|
||||
#if (__STDC_VERSION__ >= 201112L) || (defined(__cplusplus) && __cplusplus >= 201103L)
|
||||
MKTYPEDEF(char16_t);
|
||||
MKTYPEDEF(char32_t);
|
||||
#endif
|
||||
|
||||
#undef MKTYPEDEF
|
||||
#undef MKTYPEDEF2
|
||||
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __STDC_VERSION__ >= 201112L */
|
||||
|
||||
/*
|
||||
* The order of entries must match the values in`enum nvtxPayloadSchemaEntryType`.
|
||||
*/
|
||||
const nvtxPayloadEntryTypeInfo_t nvtxExtPayloadTypeInfo[NVTX_PAYLOAD_ENTRY_TYPE_INFO_ARRAY_SIZE] =
|
||||
{
|
||||
/* The first entry contains this array's length and the size of each entry in this array. */
|
||||
{NVTX_PAYLOAD_ENTRY_TYPE_INFO_ARRAY_SIZE, sizeof(nvtxPayloadEntryTypeInfo_t)},
|
||||
|
||||
/*** C integer types ***/
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_CHAR */ {sizeof(char), nvtx_alignof(char)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_UCHAR */ {sizeof(unsigned char), nvtx_alignof2(unsigned char, uchar)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_SHORT */ {sizeof(short), nvtx_alignof(short)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_USHORT */ {sizeof(unsigned short), nvtx_alignof2(unsigned short, ushort)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_INT */ {sizeof(int), nvtx_alignof(int)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_UINT */ {sizeof(unsigned int), nvtx_alignof2(unsigned int, uint)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_LONG */ {sizeof(long), nvtx_alignof(long)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_ULONG */ {sizeof(unsigned long), nvtx_alignof2(unsigned long, ulong)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_LONGLONG */ {sizeof(long long), nvtx_alignof2(long long, longlong)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_ULONGLONG */ {sizeof(unsigned long long), nvtx_alignof2(unsigned long long,ulonglong)},
|
||||
|
||||
/*** Integer types with explicit size ***/
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_INT8 */ {sizeof(int8_t), nvtx_alignof(int8_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_UINT8 */ {sizeof(uint8_t), nvtx_alignof(uint8_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_INT16 */ {sizeof(int16_t), nvtx_alignof(int16_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_UINT16 */ {sizeof(uint16_t), nvtx_alignof(uint16_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_INT32 */ {sizeof(int32_t), nvtx_alignof(int32_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_UINT32 */ {sizeof(uint32_t), nvtx_alignof(uint32_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_INT64 */ {sizeof(int64_t), nvtx_alignof(int64_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_UINT64 */ {sizeof(uint64_t), nvtx_alignof(uint64_t)},
|
||||
|
||||
/*** C floating point types ***/
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_FLOAT */ {sizeof(float), nvtx_alignof(float)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_DOUBLE */ {sizeof(double), nvtx_alignof(double)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_LONGDOUBLE */ {sizeof(long double), nvtx_alignof2(long double, longdouble)},
|
||||
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_SIZE */ {sizeof(size_t), nvtx_alignof(size_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_ADDRESS */ {sizeof(pointer_type), nvtx_alignof(pointer_type)},
|
||||
|
||||
/*** Special character types ***/
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_WCHAR */ {sizeof(wchar_t), nvtx_alignof(wchar_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_CHAR8 */
|
||||
#if (__STDC_VERSION__ > 201710L) || (defined(__cplusplus) && __cplusplus > 201703L)
|
||||
{sizeof(char8_t), nvtx_alignof(char8_t)},
|
||||
#else
|
||||
{0, 0},
|
||||
#endif
|
||||
#if (__STDC_VERSION__ >= 201112L) || (defined(__cplusplus) && __cplusplus >= 201103L)
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_CHAR16 */ {sizeof(char16_t), nvtx_alignof(char16_t)},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_CHAR32 */ {sizeof(char32_t), nvtx_alignof(char32_t)}
|
||||
#else
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_CHAR16 */ {0, 0},
|
||||
/* NVTX_PAYLOAD_ENTRY_TYPE_CHAR32 */ {0, 0}
|
||||
#endif
|
||||
};
|
||||
|
||||
#undef nvtx_alignof
|
||||
#undef nvtx_alignof2
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2021 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License v2.0 with LLVM Exceptions.
|
||||
* See https://llvm.org/LICENSE.txt for license information.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
/* This header defines types which are used by the internal implementation
|
||||
* of NVTX and callback subscribers. API clients do not use these types,
|
||||
* so they are defined here instead of in nvToolsExt.h to clarify they are
|
||||
* not part of the NVTX client API. */
|
||||
|
||||
#ifndef NVTXEXTTYPES_H
|
||||
#define NVTXEXTTYPES_H
|
||||
|
||||
#ifndef NVTX_EXT_TYPES_GUARD
|
||||
#error Never include this file directly -- it is automatically included by nvToolsExt[EXTENSION].h.
|
||||
#endif
|
||||
|
||||
typedef intptr_t (NVTX_API * NvtxExtGetExportFunction_t)(uint32_t exportFunctionId);
|
||||
|
||||
typedef struct nvtxExtModuleSegment_t
|
||||
{
|
||||
size_t segmentId;
|
||||
size_t slotCount;
|
||||
intptr_t* functionSlots;
|
||||
} nvtxExtModuleSegment_t;
|
||||
|
||||
typedef struct nvtxExtModuleInfo_t
|
||||
{
|
||||
uint16_t nvtxVer;
|
||||
uint16_t structSize;
|
||||
uint16_t moduleId;
|
||||
uint16_t compatId;
|
||||
size_t segmentsCount;
|
||||
nvtxExtModuleSegment_t* segments;
|
||||
NvtxExtGetExportFunction_t getExportFunction;
|
||||
const void* extInfo;
|
||||
} nvtxExtModuleInfo_t;
|
||||
|
||||
typedef int (NVTX_API * NvtxExtInitializeInjectionFunc_t)(nvtxExtModuleInfo_t* moduleInfo);
|
||||
|
||||
#endif /* NVTXEXTTYPES_H */
|
||||
@@ -7,9 +7,14 @@
|
||||
#ifndef NCCL_NVTX_STUB_H_
|
||||
#define NCCL_NVTX_STUB_H_
|
||||
|
||||
#include <nvtx3/nvToolsExtPayload.h>
|
||||
|
||||
struct nccl_domain{static constexpr char const* name{"NCCL"};};
|
||||
|
||||
#define NVTX3_FUNC_RANGE_IN(domain)
|
||||
#define nvtxNameOsThreadA(syscall, thread)
|
||||
#define NVTX3_FUNC_WITH_PARAMS(ID, S, P)
|
||||
|
||||
#define NVTX_PAYLOAD_ENTRY_NCCL_REDOP 11
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
* Copyright (c) 2017-2022, NVIDIA CORPORATION. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
*
|
||||
* See LICENSE.txt for license information
|
||||
************************************************************************/
|
||||
@@ -30,32 +30,16 @@ void ncclLoadParam(char const* env, int64_t deftVal, int64_t uninitialized, int6
|
||||
#define RCCL_PARAM_DECLARE(name) \
|
||||
int64_t rcclParam##name()
|
||||
|
||||
#define RCCL_PARAM(name, env, default_value) \
|
||||
#define RCCL_PARAM(name, env, deftVal) \
|
||||
pthread_mutex_t rcclParamMutex##name = PTHREAD_MUTEX_INITIALIZER; \
|
||||
int64_t rcclParam##name() { \
|
||||
static_assert(default_value != -1LL, "default value cannot be -1"); \
|
||||
static int64_t value = -1LL; \
|
||||
int64_t localValue; \
|
||||
pthread_mutex_lock(&rcclParamMutex##name); \
|
||||
localValue = value; \
|
||||
char* en = getenv("RCCL_TEST_ENV_VARS"); \
|
||||
if (value == -1LL || (en && (strcmp(en, "ENABLE") == 0))){ \
|
||||
value = default_value; \
|
||||
char* str = getenv("RCCL_" env); \
|
||||
if (str && strlen(str) > 0) { \
|
||||
errno = 0; \
|
||||
int64_t v = strtoll(str, NULL, 0); \
|
||||
if (errno) { \
|
||||
INFO(NCCL_ALL,"Invalid value %s for %s, using default %lu.", str, "RCCL_" env, value); \
|
||||
} else { \
|
||||
value = v; \
|
||||
INFO(NCCL_ALL,"%s set by environment to %lu.", "RCCL_" env, value); \
|
||||
} \
|
||||
constexpr int64_t uninitialized = INT64_MIN; \
|
||||
static_assert(deftVal != uninitialized, "default value cannot be the uninitialized value."); \
|
||||
static int64_t cache = uninitialized; \
|
||||
if (__builtin_expect(__atomic_load_n(&cache, __ATOMIC_RELAXED) == uninitialized, false)) { \
|
||||
ncclLoadParam("RCCL_" env, deftVal, uninitialized, &cache); \
|
||||
} \
|
||||
localValue = value; \
|
||||
} \
|
||||
pthread_mutex_unlock(&rcclParamMutex##name); \
|
||||
return localValue; \
|
||||
}
|
||||
return cache; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
* Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
* Modifications Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
* Modifications Copyright (c) Microsoft Corporation. Licensed under the MIT License.
|
||||
*
|
||||
* See LICENSE.txt for license information
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "info.h"
|
||||
#include "socket.h"
|
||||
#include <pthread.h>
|
||||
#include "shm.h"
|
||||
|
||||
enum ncclProxyOpState { ncclProxyOpNone, ncclProxyOpReady, ncclProxyOpProgress };
|
||||
|
||||
@@ -116,6 +117,7 @@ struct ncclProxyOpsPool {
|
||||
|
||||
struct ncclProxyOps {
|
||||
ncclProxyOpsPool* pool;
|
||||
ncclShmHandle_t handle;
|
||||
int count;
|
||||
int freeOp;
|
||||
int nextOps;
|
||||
@@ -155,6 +157,7 @@ struct ncclProxyPool;
|
||||
struct ncclProxyProgressState {
|
||||
// Used by main threads to send work to progress thread
|
||||
struct ncclProxyOpsPool* opsPool;
|
||||
ncclShmHandle_t handle;
|
||||
char opsPoolShmSuffix[6];
|
||||
|
||||
pthread_t thread;
|
||||
@@ -174,7 +177,6 @@ struct ncclProxyState {
|
||||
struct ncclSocket* listenSock;
|
||||
int stop;
|
||||
CUcontext cudaCtx;
|
||||
int safeAbortFlag;
|
||||
|
||||
// Used by main thread
|
||||
union ncclSocketAddress* peerAddresses;
|
||||
@@ -186,6 +188,15 @@ struct ncclProxyState {
|
||||
struct ncclProxyProgressState progressState;
|
||||
};
|
||||
|
||||
enum proxyConnectState {
|
||||
connUninitialized = 0,
|
||||
connInitialized = 1,
|
||||
connSharedInitialized = 2,
|
||||
connSetupDone = 3,
|
||||
connConnected = 4,
|
||||
numConnStates = 5
|
||||
};
|
||||
|
||||
struct ncclProxyConnection {
|
||||
int send, transport, shared;
|
||||
int localRank;
|
||||
@@ -194,7 +205,7 @@ struct ncclProxyConnection {
|
||||
struct ncclProxyArgs *proxyAppend;
|
||||
struct ncclProxyArgs **proxyAppendPtr;
|
||||
void* transportResources;
|
||||
bool initFlag;
|
||||
proxyConnectState state;
|
||||
};
|
||||
|
||||
typedef ncclResult_t (*threadFunc_t)(struct ncclProxyArgs*);
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
|
||||
#include "nccl.h"
|
||||
|
||||
ncclResult_t ncclShmOpen(char* shmPath, const int shmSize, void** shmPtr, void** devShmPtr, int create);
|
||||
ncclResult_t ncclShmUnlink(const char* shmname);
|
||||
ncclResult_t ncclShmClose(void* shmPtr, void* devShmPtr, const int shmSize);
|
||||
typedef void* ncclShmHandle_t;
|
||||
ncclResult_t ncclShmOpen(char* shmPath, size_t shmSize, void** shmPtr, void** devShmPtr, int refcount, ncclShmHandle_t* handle);
|
||||
ncclResult_t ncclShmClose(ncclShmHandle_t handle);
|
||||
ncclResult_t ncclShmUnlink(ncclShmHandle_t handle);
|
||||
|
||||
#endif
|
||||
|
||||
+38
-11
@@ -21,6 +21,7 @@
|
||||
#define RETRY_REFUSED_TIMES 2e4 // connection refused retry times before reporting a timeout (20 sec)
|
||||
#define RETRY_TIMEDOUT_TIMES 3 // connection timed out retry times (each one can take 20s)
|
||||
#define SOCKET_NAME_MAXLEN (NI_MAXHOST+NI_MAXSERV)
|
||||
#define NCCL_SOCKET_MAGIC 0x564ab9f2fc4b9d6cULL
|
||||
|
||||
/* Common socket address storage structure for IPv4/IPv6 */
|
||||
union ncclSocketAddress {
|
||||
@@ -30,32 +31,59 @@ union ncclSocketAddress {
|
||||
};
|
||||
|
||||
enum ncclSocketState {
|
||||
ncclSocketConnecting = 0,
|
||||
ncclSocketConnected = 1,
|
||||
ncclSocketError = 2,
|
||||
ncclSocketStateNum = 3
|
||||
} ;
|
||||
ncclSocketStateNone = 0,
|
||||
ncclSocketStateInitialized = 1,
|
||||
ncclSocketStateAccepting = 2,
|
||||
ncclSocketStateAccepted = 3,
|
||||
ncclSocketStateConnecting = 4,
|
||||
ncclSocketStateConnectPolling = 5,
|
||||
ncclSocketStateConnected = 6,
|
||||
ncclSocketStateReady = 7,
|
||||
ncclSocketStateClosed = 8,
|
||||
ncclSocketStateError = 9,
|
||||
ncclSocketStateNum = 10
|
||||
};
|
||||
|
||||
enum ncclSocketType {
|
||||
ncclSocketTypeUnknown = 0,
|
||||
ncclSocketTypeBootstrap = 1,
|
||||
ncclSocketTypeProxy = 2,
|
||||
ncclSocketTypeNetSocket = 3,
|
||||
ncclSocketTypeNetIb = 4
|
||||
};
|
||||
|
||||
struct ncclSocket {
|
||||
int fd;
|
||||
int acceptFd;
|
||||
int timedOutRetries;
|
||||
int refusedRetries;
|
||||
union ncclSocketAddress addr;
|
||||
volatile uint32_t* abortFlag;
|
||||
int asyncFlag;
|
||||
enum ncclSocketState state;
|
||||
int salen;
|
||||
uint64_t magic;
|
||||
enum ncclSocketType type;
|
||||
};
|
||||
|
||||
const char *ncclSocketToString(union ncclSocketAddress *addr, char *buf, const int numericHostForm = 1);
|
||||
ncclResult_t ncclGetSocketAddrFromString(union ncclSocketAddress* ua, const char* ip_port_pair);
|
||||
ncclResult_t ncclSocketGetAddrFromString(union ncclSocketAddress* ua, const char* ip_port_pair);
|
||||
int ncclFindInterfaceMatchSubnet(char* ifNames, union ncclSocketAddress* localAddrs, union ncclSocketAddress* remoteAddr, int ifNameMaxSize, int maxIfs);
|
||||
int ncclFindInterfaces(char* ifNames, union ncclSocketAddress *ifAddrs, int ifNameMaxSize, int maxIfs);
|
||||
|
||||
// Initialize a socket
|
||||
ncclResult_t ncclSocketInit(struct ncclSocket* sock, union ncclSocketAddress* addr = NULL, uint64_t magic = NCCL_SOCKET_MAGIC, enum ncclSocketType type = ncclSocketTypeUnknown, volatile uint32_t* abortFlag = NULL, int asyncFlag = 0);
|
||||
// Create a listening socket. sock->addr can be pre-filled with IP & port info. sock->fd is set after a successful call
|
||||
ncclResult_t ncclSocketListen(struct ncclSocket* sock);
|
||||
ncclResult_t ncclSocketGetAddr(struct ncclSocket* sock, union ncclSocketAddress* addr);
|
||||
// Connect to sock->addr. sock->fd is set after a successful call.
|
||||
ncclResult_t ncclSocketConnect(struct ncclSocket* sock, int portReuse = 0);
|
||||
// Return socket connection state.
|
||||
ncclResult_t ncclGetSocketState(struct ncclSocket* sock, enum ncclSocketState* state);
|
||||
// Accept an incoming connection from listenSocket->fd and keep the file descriptor in sock->fd, with the remote side IP/port in sock->addr.
|
||||
ncclResult_t ncclSocketAccept(struct ncclSocket* sock, struct ncclSocket* listenSocket);
|
||||
ncclResult_t ncclSocketReady(struct ncclSocket* sock, int *running);
|
||||
// Accept an incoming connection from listenSock->fd and keep the file descriptor in sock->fd, with the remote side IP/port in sock->addr.
|
||||
ncclResult_t ncclSocketAccept(struct ncclSocket* sock, struct ncclSocket* ulistenSock);
|
||||
ncclResult_t ncclSocketGetFd(struct ncclSocket* sock, int* fd);
|
||||
ncclResult_t ncclSocketSetFd(int fd, struct ncclSocket* sock);
|
||||
|
||||
#define NCCL_SOCKET_SEND 0
|
||||
#define NCCL_SOCKET_RECV 1
|
||||
@@ -65,6 +93,5 @@ ncclResult_t ncclSocketWait(int op, struct ncclSocket* sock, void* ptr, int size
|
||||
ncclResult_t ncclSocketSend(struct ncclSocket* sock, void* ptr, int size);
|
||||
ncclResult_t ncclSocketRecv(struct ncclSocket* sock, void* ptr, int size);
|
||||
ncclResult_t ncclSocketTryRecv(struct ncclSocket* sock, void* ptr, int size, int* closed);
|
||||
/* initialize a socket. */
|
||||
ncclResult_t ncclSocketInit(struct ncclSocket* sock, union ncclSocketAddress* addr = NULL, volatile uint32_t* abortFlag = NULL, int asyncFlag = 0);
|
||||
ncclResult_t ncclSocketClose(struct ncclSocket* sock);
|
||||
#endif
|
||||
|
||||
@@ -98,16 +98,19 @@ ncclResult_t ncclStrongStreamLaunchKernel(
|
||||
);
|
||||
|
||||
// Cause `a` to wait for the current state `b`. Both `a` and `b` must be acquired.
|
||||
// `b_subsumes_a` indicates that all work in `a` is already present in `b`, thus
|
||||
// we want to fast-forward `a` to be a clone of `b`. Knowing this permits the
|
||||
// implementation to induce few graph dependencies.
|
||||
ncclResult_t ncclStrongStreamWaitStream(
|
||||
struct ncclCudaGraph graph, struct ncclStrongStream* a, struct ncclStrongStream* b
|
||||
struct ncclCudaGraph graph, struct ncclStrongStream* a, struct ncclStrongStream* b, bool b_subsumes_a=false
|
||||
);
|
||||
// `b` must be capturing within `graph`.
|
||||
ncclResult_t ncclStrongStreamWaitStream(
|
||||
struct ncclCudaGraph graph, struct ncclStrongStream* a, cudaStream_t b
|
||||
struct ncclCudaGraph graph, struct ncclStrongStream* a, cudaStream_t b, bool b_subsumes_a=false
|
||||
);
|
||||
// `a` must be capturing within `graph`.
|
||||
ncclResult_t ncclStrongStreamWaitStream(
|
||||
struct ncclCudaGraph graph, cudaStream_t a, struct ncclStrongStream* b
|
||||
struct ncclCudaGraph graph, cudaStream_t a, struct ncclStrongStream* b, bool b_subsumes_a=false
|
||||
);
|
||||
|
||||
// Synchrnoization does not need the strong stream to be acquired.
|
||||
|
||||
@@ -27,6 +27,7 @@ ncclResult_t getHostName(char* hostname, int maxlen, const char delim);
|
||||
uint64_t getHash(const char* string, int n);
|
||||
uint64_t getHostHash();
|
||||
uint64_t getPidHash();
|
||||
ncclResult_t getRandomData(void* buffer, size_t bytes);
|
||||
|
||||
struct netIf {
|
||||
char prefix[64];
|
||||
@@ -48,6 +49,19 @@ inline uint64_t clockNano() {
|
||||
return uint64_t(ts.tv_sec)*1000*1000*1000 + ts.tv_nsec;
|
||||
}
|
||||
|
||||
/* get any bytes of random data from /dev/urandom, return 0 if it succeeds; else
|
||||
* return -1 */
|
||||
inline ncclResult_t getRandomData(void* buffer, size_t bytes) {
|
||||
ncclResult_t ret = ncclSuccess;
|
||||
if (bytes > 0) {
|
||||
const size_t one = 1UL;
|
||||
FILE* fp = fopen("/dev/urandom", "r");
|
||||
if (buffer == NULL || fp == NULL || fread(buffer, bytes, one, fp) != one) ret = ncclSystemError;
|
||||
if (fp) fclose(fp);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename Int>
|
||||
|
||||
Ссылка в новой задаче
Block a user