Add support for RCCL tracing (#1047)

* [Draft]: Add support for RCCL tracing

Address comments

* [Draft]: Add support for RCCL tracing

Address PR comments, changes from RCCL upstream

* Add RCCL library table registration

Working on adding support to rocprofiler-register

* Support compilation w/o <rccl/amd_detail/api_trace.h>

- dummy api_trace.h header
- return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED when RCCL does not have api_trace.h header

* RCCL API tracing tool support

- add to rocprofv3
- add to json-tool

---------

Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
This commit is contained in:
Mythreya
2024-09-11 22:42:58 -07:00
committed by GitHub
parent 72cbcedc9e
commit 2a146259c7
43 changed files with 2270 additions and 30 deletions
@@ -147,6 +147,24 @@ typedef struct
/// ::rocprofiler_marker_name_api_id_t
} rocprofiler_buffer_tracing_marker_api_record_t;
/**
* @brief ROCProfiler Buffer RCCL API Record.
*/
typedef struct
{
uint64_t size; ///< size of this struct
rocprofiler_buffer_tracing_kind_t kind;
rocprofiler_tracing_operation_t operation;
rocprofiler_correlation_id_t correlation_id; ///< correlation ids for record
rocprofiler_timestamp_t start_timestamp; ///< start time in nanoseconds
rocprofiler_timestamp_t end_timestamp; ///< end time in nanoseconds
rocprofiler_thread_id_t thread_id; ///< id for thread generating this record
/// @var kind
/// @brief ::ROCPROFILER_CALLBACK_TRACING_RCCL_API,
/// @brief Specification of the API function, e.g., ::rocprofiler_rccl_api_id_t,
} rocprofiler_buffer_tracing_rccl_api_record_t;
/**
* @brief ROCProfiler Buffer Memory Copy Tracer Record.
*/
@@ -27,6 +27,7 @@
#include <rocprofiler-sdk/hip.h>
#include <rocprofiler-sdk/hsa.h>
#include <rocprofiler-sdk/marker.h>
#include <rocprofiler-sdk/rccl.h>
#include <hsa/hsa.h>
#include <hsa/hsa_amd_tool.h>
@@ -87,6 +88,16 @@ typedef struct
rocprofiler_marker_api_retval_t retval;
} rocprofiler_callback_tracing_marker_api_data_t;
/**
* @brief ROCProfiler RCCL API Callback Data.
*/
typedef struct
{
uint64_t size; ///< size of this struct
rocprofiler_rccl_api_args_t args;
rocprofiler_rccl_api_retval_t retval;
} rocprofiler_callback_tracing_rccl_api_data_t;
/**
* @brief ROCProfiler Code Object Load Tracer Callback Record.
*/
@@ -77,6 +77,7 @@ struct perfetto_category;
ROCPROFILER_DEFINE_CATEGORY(category, hsa_api, "HSA API function")
ROCPROFILER_DEFINE_CATEGORY(category, hip_api, "HIP API function")
ROCPROFILER_DEFINE_CATEGORY(category, marker_api, "Marker API region")
ROCPROFILER_DEFINE_CATEGORY(category, rccl_api, "RCCL API function")
ROCPROFILER_DEFINE_CATEGORY(category, kernel_dispatch, "GPU kernel dispatch")
ROCPROFILER_DEFINE_CATEGORY(category, memory_copy, "Async memory copy")
@@ -84,6 +85,7 @@ ROCPROFILER_DEFINE_CATEGORY(category, memory_copy, "Async memory copy")
ROCPROFILER_PERFETTO_CATEGORY(category::hsa_api), \
ROCPROFILER_PERFETTO_CATEGORY(category::hip_api), \
ROCPROFILER_PERFETTO_CATEGORY(category::marker_api), \
ROCPROFILER_PERFETTO_CATEGORY(category::rccl_api), \
ROCPROFILER_PERFETTO_CATEGORY(category::kernel_dispatch), \
ROCPROFILER_PERFETTO_CATEGORY(category::memory_copy)
@@ -327,6 +327,22 @@ save(ArchiveT& ar, rocprofiler_callback_tracing_memory_copy_data_t data)
ROCP_SDK_SAVE_DATA_FIELD(bytes);
}
template <typename ArchiveT>
void
save(ArchiveT& ar, rocprofiler_rccl_api_retval_t data)
{
ROCP_SDK_SAVE_DATA_FIELD(ncclResult_t_retval);
}
template <typename ArchiveT>
void
save(ArchiveT& ar, rocprofiler_callback_tracing_rccl_api_data_t data)
{
ROCP_SDK_SAVE_DATA_FIELD(size);
// ROCP_SDK_SAVE_DATA_FIELD(args);
ROCP_SDK_SAVE_DATA_FIELD(retval);
}
template <typename ArchiveT>
void
save(ArchiveT& ar, rocprofiler_profile_counting_dispatch_data_t data)
@@ -405,6 +421,13 @@ save(ArchiveT& ar, rocprofiler_buffer_tracing_marker_api_record_t data)
save_buffer_tracing_api_record(ar, data);
}
template <typename ArchiveT>
void
save(ArchiveT& ar, rocprofiler_buffer_tracing_rccl_api_record_t data)
{
save_buffer_tracing_api_record(ar, data);
}
template <typename ArchiveT>
void
save(ArchiveT& ar, rocprofiler_buffer_tracing_kernel_dispatch_record_t data)
@@ -66,6 +66,7 @@ typedef enum // NOLINT(performance-enum-size)
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_MEMORY_COPY,
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_KERNEL_DISPATCH,
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_SCRATCH_MEMORY,
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_RCCL_API,
ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_LAST,
} rocprofiler_external_correlation_id_request_kind_t;
+6 -2
View File
@@ -169,6 +169,7 @@ typedef enum // NOLINT(performance-enum-size)
ROCPROFILER_CALLBACK_TRACING_SCRATCH_MEMORY, ///< @see ::rocprofiler_scratch_memory_operation_t
ROCPROFILER_CALLBACK_TRACING_KERNEL_DISPATCH, ///< Callbacks for kernel dispatches
ROCPROFILER_CALLBACK_TRACING_MEMORY_COPY, ///< @see ::rocprofiler_memory_copy_operation_t
ROCPROFILER_CALLBACK_TRACING_RCCL_API, ///< @RCCL tracing
ROCPROFILER_CALLBACK_TRACING_LAST,
} rocprofiler_callback_tracing_kind_t;
@@ -193,6 +194,7 @@ typedef enum // NOLINT(performance-enum-size)
ROCPROFILER_BUFFER_TRACING_PAGE_MIGRATION, ///< Buffer page migration info
ROCPROFILER_BUFFER_TRACING_SCRATCH_MEMORY, ///< Buffer scratch memory reclaimation info
ROCPROFILER_BUFFER_TRACING_CORRELATION_ID_RETIREMENT, ///< Correlation ID in no longer in use
ROCPROFILER_BUFFER_TRACING_RCCL_API, ///< RCCL tracing
ROCPROFILER_BUFFER_TRACING_LAST,
} rocprofiler_buffer_tracing_kind_t;
@@ -350,7 +352,8 @@ typedef enum
ROCPROFILER_HSA_LIBRARY = (1 << 1),
ROCPROFILER_HIP_LIBRARY = (1 << 2),
ROCPROFILER_MARKER_LIBRARY = (1 << 3),
ROCPROFILER_LIBRARY_LAST = ROCPROFILER_MARKER_LIBRARY,
ROCPROFILER_RCCL_LIBRARY = (1 << 4),
ROCPROFILER_LIBRARY_LAST = ROCPROFILER_RCCL_LIBRARY,
} rocprofiler_runtime_library_t;
/**
@@ -365,7 +368,8 @@ typedef enum
ROCPROFILER_MARKER_CORE_TABLE = (1 << 3),
ROCPROFILER_MARKER_CONTROL_TABLE = (1 << 4),
ROCPROFILER_MARKER_NAME_TABLE = (1 << 5),
ROCPROFILER_TABLE_LAST = ROCPROFILER_MARKER_NAME_TABLE,
ROCPROFILER_RCCL_TABLE = (1 << 6),
ROCPROFILER_TABLE_LAST = ROCPROFILER_RCCL_TABLE,
} rocprofiler_intercept_table_t;
/**
+27
View File
@@ -0,0 +1,27 @@
// MIT License
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <rocprofiler-sdk/rccl/api_args.h>
#include <rocprofiler-sdk/rccl/api_id.h>
#include <rocprofiler-sdk/rccl/table_id.h>
@@ -0,0 +1,308 @@
// MIT License
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <rocprofiler-sdk/defines.h>
#include <rocprofiler-sdk/version.h>
#include <rccl/rccl.h>
#include <stdint.h>
ROCPROFILER_EXTERN_C_INIT
// Empty struct has a size of 0 in C but size of 1 in C++.
// This struct is added to the union members which represent
// functions with no arguments to ensure ABI compatibility
typedef struct rocprofiler_rccl_api_no_args
{
char empty;
} rocprofiler_rccl_api_no_args;
typedef union rocprofiler_rccl_api_retval_t
{
int32_t ncclResult_t_retval;
const char* const_charp_retval;
} rocprofiler_rccl_api_retval_t;
typedef union rocprofiler_rccl_api_args_t
{
struct
{
const void* sendbuff;
void* recvbuff;
size_t sendcount;
ncclDataType_t datatype;
ncclComm_t comm;
hipStream_t stream;
} ncclAllGather;
struct
{
const void* sendbuff;
void* recvbuff;
size_t count;
ncclDataType_t datatype;
ncclRedOp_t op;
struct ncclComm* comm;
hipStream_t stream;
} ncclAllReduce;
struct
{
const void* sendbuff;
void* recvbuff;
size_t count;
ncclDataType_t datatype;
ncclComm_t comm;
hipStream_t stream;
} ncclAllToAll;
struct
{
const void* sendbuff;
const size_t* sendcounts;
const size_t* sdispls;
void* recvbuff;
const size_t* recvcounts;
const size_t* rdispls;
ncclDataType_t datatype;
ncclComm_t comm;
hipStream_t stream;
} ncclAllToAllv;
struct
{
const void* sendbuff;
void* recvbuff;
size_t count;
ncclDataType_t datatype;
int root;
ncclComm_t comm;
hipStream_t stream;
} ncclBroadcast;
struct
{
const void* sendbuff;
void* recvbuff;
size_t sendcount;
ncclDataType_t datatype;
int root;
ncclComm_t comm;
hipStream_t stream;
} ncclGather;
struct
{
const void* sendbuff;
void* recvbuff;
size_t count;
ncclDataType_t datatype;
ncclRedOp_t op;
int root;
ncclComm_t comm;
hipStream_t stream;
} ncclReduce;
struct
{
const void* sendbuff;
void* recvbuff;
size_t recvcount;
ncclDataType_t datatype;
ncclRedOp_t op;
struct ncclComm* comm;
hipStream_t stream;
} ncclReduceScatter;
struct
{
const void* sendbuff;
void* recvbuff;
size_t recvcount;
ncclDataType_t datatype;
int root;
ncclComm_t comm;
hipStream_t stream;
} ncclScatter;
struct
{
const void* sendbuff;
size_t count;
ncclDataType_t datatype;
int peer;
ncclComm_t comm;
hipStream_t stream;
} ncclSend;
struct
{
void* recvbuff;
size_t count;
ncclDataType_t datatype;
int peer;
ncclComm_t comm;
hipStream_t stream;
} ncclRecv;
struct
{
ncclRedOp_t* op;
void* scalar;
ncclDataType_t datatype;
ncclScalarResidence_t residence;
ncclComm_t comm;
} ncclRedOpCreatePreMulSum;
struct
{
ncclRedOp_t op;
ncclComm_t comm;
} ncclRedOpDestroy;
struct
{
rocprofiler_rccl_api_no_args no_args;
} ncclGroupStart;
struct
{
rocprofiler_rccl_api_no_args no_args;
} ncclGroupEnd;
struct
{
int* version;
} ncclGetVersion;
struct
{
ncclUniqueId* out;
} ncclGetUniqueId;
struct
{
ncclComm_t* newcomm;
int nranks;
ncclUniqueId commId;
int myrank;
} ncclCommInitRank;
struct
{
ncclComm_t* comms;
int ndev;
const int* devlist;
} ncclCommInitAll;
struct
{
ncclComm_t* comm;
int nranks;
ncclUniqueId commId;
int myrank;
ncclConfig_t* config;
} ncclCommInitRankConfig;
struct
{
ncclComm_t comm;
} ncclCommFinalize;
struct
{
ncclComm_t comm;
} ncclCommDestroy;
struct
{
ncclComm_t comm;
} ncclCommAbort;
struct
{
ncclComm_t comm;
int color;
int key;
ncclComm_t* newcomm;
ncclConfig_t* config;
} ncclCommSplit;
struct
{
ncclResult_t code;
} ncclGetErrorString;
struct
{
ncclComm_t comm;
} ncclGetLastError;
struct
{
ncclComm_t comm;
ncclResult_t* asyncError;
} ncclCommGetAsyncError;
struct
{
ncclComm_t comm;
int* count;
} ncclCommCount;
struct
{
ncclComm_t comm;
int* devid;
} ncclCommCuDevice;
struct
{
ncclComm_t comm;
int* rank;
} ncclCommUserRank;
struct
{
void** ptr;
size_t size;
} ncclMemAlloc;
struct
{
void* ptr;
} ncclMemFree;
struct
{
const char* mscclAlgoFilePath;
mscclAlgoHandle_t* mscclAlgoHandle;
int rank;
} mscclLoadAlgo;
struct
{
const void* sendBuff;
const size_t* sendCounts;
const size_t* sDisPls;
void* recvBuff;
const size_t* recvCounts;
const size_t* rDisPls;
size_t count;
ncclDataType_t dataType;
int root;
int peer;
ncclRedOp_t op;
mscclAlgoHandle_t mscclAlgoHandle;
ncclComm_t comm;
hipStream_t stream;
} mscclRunAlgo;
struct
{
mscclAlgoHandle_t mscclAlgoHandle;
} mscclUnloadAlgo;
struct
{
ncclComm_t comm;
void* buff;
size_t size;
void** handle;
} ncclCommRegister;
struct
{
ncclComm_t comm;
void* handle;
} ncclCommDeregister;
} rocprofiler_rccl_api_args_t;
ROCPROFILER_EXTERN_C_FINI
@@ -0,0 +1,75 @@
// MIT License
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <rocprofiler-sdk/version.h>
/**
* @brief ROCProfiler enumeration of HSA Core API tracing operations
*/
typedef enum // NOLINT(performance-enum-size)
{
ROCPROFILER_RCCL_API_ID_NONE = -1,
ROCPROFILER_RCCL_API_ID_ncclAllGather = 0,
ROCPROFILER_RCCL_API_ID_ncclAllReduce,
ROCPROFILER_RCCL_API_ID_ncclAllToAll,
ROCPROFILER_RCCL_API_ID_ncclAllToAllv,
ROCPROFILER_RCCL_API_ID_ncclBroadcast,
ROCPROFILER_RCCL_API_ID_ncclGather,
ROCPROFILER_RCCL_API_ID_ncclReduce,
ROCPROFILER_RCCL_API_ID_ncclReduceScatter,
ROCPROFILER_RCCL_API_ID_ncclScatter,
ROCPROFILER_RCCL_API_ID_ncclSend,
ROCPROFILER_RCCL_API_ID_ncclRecv,
ROCPROFILER_RCCL_API_ID_ncclRedOpCreatePreMulSum,
ROCPROFILER_RCCL_API_ID_ncclRedOpDestroy,
ROCPROFILER_RCCL_API_ID_ncclGroupStart,
ROCPROFILER_RCCL_API_ID_ncclGroupEnd,
ROCPROFILER_RCCL_API_ID_ncclGetVersion,
ROCPROFILER_RCCL_API_ID_ncclGetUniqueId,
ROCPROFILER_RCCL_API_ID_ncclCommInitRank,
ROCPROFILER_RCCL_API_ID_ncclCommInitAll,
ROCPROFILER_RCCL_API_ID_ncclCommInitRankConfig,
ROCPROFILER_RCCL_API_ID_ncclCommFinalize,
ROCPROFILER_RCCL_API_ID_ncclCommDestroy,
ROCPROFILER_RCCL_API_ID_ncclCommAbort,
ROCPROFILER_RCCL_API_ID_ncclCommSplit,
ROCPROFILER_RCCL_API_ID_ncclGetErrorString,
ROCPROFILER_RCCL_API_ID_ncclGetLastError,
ROCPROFILER_RCCL_API_ID_ncclCommGetAsyncError,
ROCPROFILER_RCCL_API_ID_ncclCommCount,
ROCPROFILER_RCCL_API_ID_ncclCommCuDevice,
ROCPROFILER_RCCL_API_ID_ncclCommUserRank,
ROCPROFILER_RCCL_API_ID_ncclMemAlloc,
ROCPROFILER_RCCL_API_ID_ncclMemFree,
ROCPROFILER_RCCL_API_ID_mscclLoadAlgo,
ROCPROFILER_RCCL_API_ID_mscclRunAlgo,
ROCPROFILER_RCCL_API_ID_mscclUnloadAlgo,
ROCPROFILER_RCCL_API_ID_ncclCommRegister,
ROCPROFILER_RCCL_API_ID_ncclCommDeregister,
ROCPROFILER_RCCL_API_ID_LAST,
} rocprofiler_rccl_api_id_t;
@@ -0,0 +1,31 @@
// MIT License
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
// NOLINTNEXTLINE(performance-enum-size)
typedef enum
{
ROCPROFILER_RCCL_TABLE_ID_NONE = -1,
ROCPROFILER_RCCL_TABLE_ID = 0,
ROCPROFILER_RCCL_TABLE_ID_LAST,
} rocprofiler_rccl_table_id_t;