Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CUDA][XPTI] Fix XPTI-based CUDA tracing capabilities #1173

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions scripts/core/INTRO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,31 @@ Unified Runtime loader implements tracing support through the `XPTI framework <h
| **user_data**: A pointer to `function_with_args_t` object, that includes function ID, name, arguments, and return value.
- None

.. list-table:: UR Stream `"ur.adapter.cuda.call"` Notification Signatures
:header-rows: 1

* - Trace Point Type
- Parameter Description
- Metadata
* - `function_with_args_begin`
- | **trace_type**: `xpti::trace_point_type_t::function_with_args_begin` that marks the beginning of a function
| **parent**: nullptr
| **event**: nullptr
| **instance**: Unique ID to allow the correlation of the `function_with_args_begin` event with the `function_with_args_end` event.
| **user_data**: A pointer to `function_with_args_t` object, that includes function ID, name, and arguments.
| `function_with_args_t::args_data` contains a pointer to `CUpti_CallbackData::functionParams`. See CUPTI documentation for more info:
| https://docs.nvidia.com/cupti/annotated.html#structCUpti__CallbackData
- None
* - `function_with_args_end`
- | **trace_type**: `xpti::trace_point_type_t::function_with_args_end` that marks the end of a function
| **parent**: nullptr
| **event**: nullptr
| **instance**: Unique ID to allow the correlation of the `function_with_args_end` event with the `function_with_args_begin` event.
| **user_data**: A pointer to `function_with_args_t` object, that includes function ID, name, arguments, and return value.
| `function_with_args_t::args_data` contains a pointer to `CUpti_CallbackData::functionParams`. See CUPTI documentation for more info:
| https://docs.nvidia.com/cupti/annotated.html#structCUpti__CallbackData
- None

Logging
---------------------

Expand Down
5 changes: 5 additions & 0 deletions source/adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ function(add_ur_adapter name)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../adapter.map.in ${ADAPTER_VERSION_SCRIPT} @ONLY)
target_link_options(${name} PRIVATE "-Wl,--version-script=${ADAPTER_VERSION_SCRIPT}")
endif()
if (UR_ENABLE_TRACING)
target_link_libraries(${name} PRIVATE xpti)
target_include_directories(${name} PRIVATE ${xpti_SOURCE_DIR}/include)
target_compile_definitions(${name} PRIVATE XPTI_ENABLE_INSTRUMENTATION)
endif()
endfunction()

add_subdirectory(null)
Expand Down
4 changes: 4 additions & 0 deletions source/adapters/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ target_link_libraries(${TARGET_NAME} PRIVATE
target_include_directories(${TARGET_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../"
)

if (UR_ENABLE_TRACING)
target_link_libraries(${TARGET_NAME} PRIVATE ${CUDA_cupti_LIBRARY})
endif()
32 changes: 6 additions & 26 deletions source/adapters/cuda/tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@
#include <iostream>

#ifdef XPTI_ENABLE_INSTRUMENTATION
constexpr auto CUDA_CALL_STREAM_NAME = "sycl.experimental.cuda.call";
constexpr auto CUDA_DEBUG_STREAM_NAME = "sycl.experimental.cuda.debug";
constexpr auto CUDA_CALL_STREAM_NAME = "ur.adapter.cuda.call";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the case of UR, the stream name is just ur. For consistency, should we call this one ur.adapter.cuda or rename the ur one to ur.call ? I have no preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, ur.call is a better choice, because there's so much more that I'd like UR to export to XPTI other than calls. Device-side profiling info, diagnostic messages, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing existing stream name is also better done in a separate PR, and I guess, I'll have to prepare PRs for SYCL as well.


thread_local uint64_t CallCorrelationID = 0;
thread_local uint64_t DebugCorrelationID = 0;

static xpti_td *GCallEvent = nullptr;
static xpti_td *GDebugEvent = nullptr;

constexpr auto GVerStr = "0.1";
constexpr int GMajVer = 0;
Expand All @@ -40,31 +37,22 @@ static void cuptiCallback(void *, CUpti_CallbackDomain, CUpti_CallbackId CBID,
if (xptiTraceEnabled()) {
const auto *CBInfo = static_cast<const CUpti_CallbackData *>(CBData);

if (CBInfo->callbackSite == CUPTI_API_ENTER) {
if (CBInfo->callbackSite == CUPTI_API_ENTER)
CallCorrelationID = xptiGetUniqueId();
DebugCorrelationID = xptiGetUniqueId();
}

const char *FuncName = CBInfo->functionName;
uint32_t FuncID = static_cast<uint32_t>(CBID);
uint16_t TraceTypeArgs = CBInfo->callbackSite == CUPTI_API_ENTER
? xpti::trace_function_with_args_begin
: xpti::trace_function_with_args_end;
uint16_t TraceType = CBInfo->callbackSite == CUPTI_API_ENTER
? xpti::trace_function_begin
: xpti::trace_function_end;

uint8_t CallStreamID = xptiRegisterStream(CUDA_CALL_STREAM_NAME);
uint8_t DebugStreamID = xptiRegisterStream(CUDA_DEBUG_STREAM_NAME);

xptiNotifySubscribers(CallStreamID, TraceType, GCallEvent, nullptr,
CallCorrelationID, FuncName);

xpti::function_with_args_t Payload{
FuncID, FuncName, const_cast<void *>(CBInfo->functionParams),
CBInfo->functionReturnValue, CBInfo->context};
xptiNotifySubscribers(DebugStreamID, TraceTypeArgs, GDebugEvent, nullptr,
DebugCorrelationID, &Payload);
xptiNotifySubscribers(CallStreamID, TraceTypeArgs, GCallEvent, nullptr,
CallCorrelationID, &Payload);
}
}
#endif
Expand All @@ -76,18 +64,11 @@ void enableCUDATracing() {

xptiRegisterStream(CUDA_CALL_STREAM_NAME);
xptiInitialize(CUDA_CALL_STREAM_NAME, GMajVer, GMinVer, GVerStr);
xptiRegisterStream(CUDA_DEBUG_STREAM_NAME);
xptiInitialize(CUDA_DEBUG_STREAM_NAME, GMajVer, GMinVer, GVerStr);

uint64_t Dummy;
xpti::payload_t CUDAPayload("CUDA Plugin Layer");
xpti::payload_t CUDAPayload("Unified Runtime CUDA Adapter Layer");
GCallEvent =
xptiMakeEvent("CUDA Plugin Layer", &CUDAPayload,
xpti::trace_algorithm_event, xpti_at::active, &Dummy);

xpti::payload_t CUDADebugPayload("CUDA Plugin Debug Layer");
GDebugEvent =
xptiMakeEvent("CUDA Plugin Debug Layer", &CUDADebugPayload,
xptiMakeEvent("Unified Runtime CUDA Adapter Layer", &CUDAPayload,
xpti::trace_algorithm_event, xpti_at::active, &Dummy);

CUpti_SubscriberHandle Subscriber;
Expand All @@ -106,6 +87,5 @@ void disableCUDATracing() {
return;

xptiFinalize(CUDA_CALL_STREAM_NAME);
xptiFinalize(CUDA_DEBUG_STREAM_NAME);
#endif // XPTI_ENABLE_INSTRUMENTATION
}
Loading