From d60635a3eac7c98818fb678bec976a1693472d47 Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Tue, 25 Aug 2026 17:24:06 +0200 Subject: [PATCH 01/11] [xpupti] Don't emit ac2g flow endpoints on XPU_DRIVER records The SYCL runtime record, the Level Zero driver (ze*) record and the device kernel share one correlation id, and handleRuntimeKernelMemcpyMemsetActivities sets flow.id/flow.type on all of them. The driver record then becomes an extra ac2g flow endpoint, so Perfetto draws a redundant host->host arrow from the runtime "submit" slice to its nested ze* child; non-launch ze* calls (which get fresh correlation ids) also emit dangling flow finishes with no matching start. Gate the flow assignment on a new carriesFlow() predicate so only the runtime (flow source) and the device activities (kernel/memcpy/memset, flow destination) carry the ac2g flow; XPU_DRIVER records carry none. Add predicate unit tests and a handler-level test. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../plugin/xpupti/XpuptiActivityHandlers.cpp | 9 +- .../xpupti/XpuptiActivityProfilerSession.cpp | 12 +++ .../xpupti/XpuptiActivityProfilerSession.h | 4 + .../xpupti/XpuptiActivityHandlersTest.cpp | 82 +++++++++++++++++++ .../test/xpupti/XpuptiFlowCorrelationTest.cpp | 27 ++++++ 5 files changed, 132 insertions(+), 2 deletions(-) diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp index f39cc0d28..d13c853a7 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp @@ -200,8 +200,13 @@ void XpuptiActivityProfilerSession::handleRuntimeKernelMemcpyMemsetActivities( trace_activity->startTime = activity->_start_timestamp; trace_activity->endTime = activity->_end_timestamp; trace_activity->threadId = activity->_thread_id; - trace_activity->flow.id = activity->_correlation_id; - trace_activity->flow.type = libkineto::kLinkAsyncCpuGpu; + // Avoid a redundant flow arrow from the XPU_RUNTIME submit to its nested + // XPU_DRIVER (ze*) subspan: leave the flow id 0 so output_json's + // `flowId() > 0` guard skips the endpoint. + if (carriesFlow(activityType)) { + trace_activity->flow.id = activity->_correlation_id; + trace_activity->flow.type = libkineto::kLinkAsyncCpuGpu; + } trace_activity->id = activity->_correlation_id; trace_activity->linked = diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp index b864739c1..7645219ce 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp @@ -32,6 +32,18 @@ bool XpuptiActivityProfilerSession::startsFlow(ActivityType activityType) { return activityType == ActivityType::XPU_RUNTIME; } +bool XpuptiActivityProfilerSession::carriesFlow(ActivityType activityType) { + switch (activityType) { + case ActivityType::XPU_RUNTIME: + case ActivityType::CONCURRENT_KERNEL: + case ActivityType::GPU_MEMCPY: + case ActivityType::GPU_MEMSET: + return true; + default: + return false; + } +} + // =========== Session Constructor ============= // XpuptiActivityProfilerSession::XpuptiActivityProfilerSession( XpuptiActivityApi& xpti, diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h index 9fd9df5d6..66a44bf03 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h @@ -73,6 +73,10 @@ class XpuptiActivityProfilerSession // Static so it can be unit-tested without real hardware. static bool startsFlow(ActivityType activityType); + // Whether the record is a CPU->GPU flow endpoint (runtime source or device + // destination); XPU_DRIVER subspans are not. Static for unit testing. + static bool carriesFlow(ActivityType activityType); + private: void checkTimestampOrder(const ITraceActivity* act1); void removeCorrelatedPtiActivities(const ITraceActivity* act1); diff --git a/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp b/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp index e4f3726d7..0e2f045a1 100644 --- a/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp +++ b/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp @@ -16,11 +16,22 @@ #include +#include #include namespace KN = KINETO_NAMESPACE; using namespace libkineto; +// Tests below pass &record._view_kind as a pti_view_record_base* (the handler +// casts it back by view kind, the PTI C-API idiom). That is only valid if the +// base record is the first member -- enforce it at compile time. +static_assert( + offsetof(pti_view_record_api, _view_kind) == 0, + "base record must be first member"); +static_assert( + offsetof(pti_view_record_kernel, _view_kind) == 0, + "base record must be first member"); + // Mock XpuptiActivityApi that delivers hand-crafted PTI records // through the virtual processActivities without needing PTI runtime. class MockXpuptiActivityApi : public KN::XpuptiActivityApi { @@ -333,6 +344,77 @@ TEST_F(XpuptiActivityHandlersTest, SynchronizationActivityOutOfRange) { EXPECT_EQ(traceBuffer->activities.size(), 0); } +// --- CPU->GPU flow endpoint tests --- + +// A SYCL "submit" (XPU_RUNTIME), its nested Level Zero append (XPU_DRIVER) and +// the resulting device kernel all share one correlation id. Only the runtime +// record (source) and the kernel record (destination) may be ac2g flow +// endpoints. The driver record must carry no flow, otherwise Perfetto draws a +// redundant host->host arrow from the runtime "submit" slice to its nested ze* +// child. Uses _api_id/_api_group 84/LEVELZERO for the api records so +// ptiViewGetApiIdName() resolves a name (same as the synchronization tests). +TEST_F( + XpuptiActivityHandlersTest, + DriverRecordCarriesNoFlowKernelAndRuntimeDo) { + constexpr uint32_t kCorrelationId = 42; + + pti_view_record_api runtime_record{}; + runtime_record._view_kind._view_kind = PTI_VIEW_RUNTIME_API; + runtime_record._start_timestamp = 100; + runtime_record._end_timestamp = 150; + runtime_record._process_id = 1; + runtime_record._thread_id = 7; + runtime_record._correlation_id = kCorrelationId; + runtime_record._api_id = 84; + runtime_record._api_group = static_cast(1); + + pti_view_record_api driver_record{}; + driver_record._view_kind._view_kind = PTI_VIEW_DRIVER_API; + driver_record._start_timestamp = 110; + driver_record._end_timestamp = 140; + driver_record._process_id = 1; + driver_record._thread_id = 7; + driver_record._correlation_id = kCorrelationId; + driver_record._api_id = 84; + driver_record._api_group = static_cast(1); + + pti_view_record_kernel kernel_record{}; + kernel_record._view_kind._view_kind = PTI_VIEW_DEVICE_GPU_KERNEL; + kernel_record._name = "gemm_kernel"; + kernel_record._start_timestamp = 200; + kernel_record._end_timestamp = 260; + kernel_record._thread_id = 7; + kernel_record._correlation_id = kCorrelationId; + kernel_record._sycl_queue_id = 3; + kernel_record._kernel_id = 9; + + mockApi_.records.push_back(&runtime_record._view_kind); + mockApi_.records.push_back(&driver_record._view_kind); + mockApi_.records.push_back(&kernel_record._view_kind); + + auto traceBuffer = processAndGetTrace(); + ASSERT_EQ(traceBuffer->activities.size(), 3); + + auto& runtime_activity = *traceBuffer->activities[0]; + EXPECT_EQ(runtime_activity.type(), ActivityType::XPU_RUNTIME); + EXPECT_EQ(runtime_activity.flowId(), kCorrelationId); + EXPECT_EQ(runtime_activity.flowType(), kLinkAsyncCpuGpu); + EXPECT_TRUE(runtime_activity.flowStart()); + + auto& driver_activity = *traceBuffer->activities[1]; + EXPECT_EQ(driver_activity.type(), ActivityType::XPU_DRIVER); + // The regression: no flow endpoint on the driver record (id stays 0, so + // output_json's `flowId() > 0` guard emits no link -> no redundant arrow). + EXPECT_EQ(driver_activity.flowId(), 0); + EXPECT_FALSE(driver_activity.flowStart()); + + auto& kernel_activity = *traceBuffer->activities[2]; + EXPECT_EQ(kernel_activity.type(), ActivityType::CONCURRENT_KERNEL); + EXPECT_EQ(kernel_activity.flowId(), kCorrelationId); + EXPECT_EQ(kernel_activity.flowType(), kLinkAsyncCpuGpu); + EXPECT_FALSE(kernel_activity.flowStart()); +} + // --- Mixed dispatch test --- TEST_F(XpuptiActivityHandlersTest, MixedCommunicationAndSynchronization) { diff --git a/libkineto/test/xpupti/XpuptiFlowCorrelationTest.cpp b/libkineto/test/xpupti/XpuptiFlowCorrelationTest.cpp index 08cd4e953..6d1a7a1ff 100644 --- a/libkineto/test/xpupti/XpuptiFlowCorrelationTest.cpp +++ b/libkineto/test/xpupti/XpuptiFlowCorrelationTest.cpp @@ -39,3 +39,30 @@ TEST(XpuptiFlowCorrelationTest, DeviceRecordsDoNotStartFlow) { EXPECT_FALSE(KN::XpuptiActivityProfilerSession::startsFlow( KN::ActivityType::GPU_MEMSET)); } + +// startsFlow() only picks the flow *source*. carriesFlow() decides whether a +// record is a flow endpoint at all -- the bug was that driver (ze*) records +// were still flow *ends* (sharing the runtime record's id), which draws a +// redundant host->host arrow. They must carry no flow. + +TEST(XpuptiFlowCorrelationTest, RuntimeAndDeviceRecordsCarryFlow) { + // The runtime record is the flow source; device activities are its + // destinations. All are genuine ac2g endpoints. + EXPECT_TRUE(KN::XpuptiActivityProfilerSession::carriesFlow( + KN::ActivityType::XPU_RUNTIME)); + EXPECT_TRUE(KN::XpuptiActivityProfilerSession::carriesFlow( + KN::ActivityType::CONCURRENT_KERNEL)); + EXPECT_TRUE(KN::XpuptiActivityProfilerSession::carriesFlow( + KN::ActivityType::GPU_MEMCPY)); + EXPECT_TRUE(KN::XpuptiActivityProfilerSession::carriesFlow( + KN::ActivityType::GPU_MEMSET)); +} + +TEST(XpuptiFlowCorrelationTest, DriverRecordsCarryNoFlow) { + // Driver (ze*) records share the runtime record's correlation id and are + // nested under the runtime "submit" slice on the same host track. A flow + // endpoint on them only produces a redundant host->host arrow, so they must + // carry no flow (neither start nor end). + EXPECT_FALSE(KN::XpuptiActivityProfilerSession::carriesFlow( + KN::ActivityType::XPU_DRIVER)); +} From bbb65fc3abcc4272e64c839593331455a2730054 Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Mon, 31 Aug 2026 21:04:41 +0200 Subject: [PATCH 02/11] [xpupti] Fold the ac2g flow predicates into one role function Review feedback on #1549: `carriesFlow` claimed to test whether a record is a "CPU->GPU flow endpoint", yet returned true for XPU_RUNTIME -- the host side, which is the flow *source*, not its destination. The name also did not say which of the two flow types (fwdbwd, ac2g) it meant. Replace `startsFlow` and `carriesFlow` with a single `ac2gFlowRole()` returning {None, Source, Destination}: the flow type is named in the predicate, `Source`/`Destination` replaces the ambiguous "endpoint", and one list of activity types can no longer drift out of sync with a second one -- flow id, type and start are now set together in one place. Scoping the name to ac2g is accurate rather than provisional: the plugin never emits fwdbwd, which the PyTorch CPU-side profiler generates and no device backend sees. Both predicates were public static members only so the unit test could reach them, and a test that re-asserts the switch's own table proves little. Drop XpuptiFlowCorrelationTest, move the function into an anonymous namespace in the only translation unit that uses it, and assert the observable behaviour in XpuptiActivityHandlersTest instead: memcpy and memset records are flow destinations, and the driver record's flow *type* stays 0 along with its id (an id with type 0 reaches handleGenericLink, which then logs "Unknown flow type" for every such record). --- .../plugin/xpupti/XpuptiActivityHandlers.cpp | 35 ++++++++-- .../xpupti/XpuptiActivityProfilerSession.cpp | 21 ------ .../xpupti/XpuptiActivityProfilerSession.h | 10 --- libkineto/test/xpupti/CMakeLists.txt | 5 -- .../xpupti/XpuptiActivityHandlersTest.cpp | 61 ++++++++++++++++- .../test/xpupti/XpuptiFlowCorrelationTest.cpp | 68 ------------------- 6 files changed, 89 insertions(+), 111 deletions(-) delete mode 100644 libkineto/test/xpupti/XpuptiFlowCorrelationTest.cpp diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp index d13c853a7..11a2321f2 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp @@ -159,6 +159,30 @@ static void addTimestampMetadata( label, formatTimeLikeOutputJson(signedFromUnsignedDiff(time, time_ref))); } +namespace { + +// Part a record plays in the async CPU->GPU ("ac2g") flow linking a host submit +// to the device operation it enqueued. +enum class Ac2gFlowRole : uint8_t { None, Source, Destination }; + +// XPU_DRIVER (ze*) subspans share the runtime record's correlation id but play +// no part: they are nested under the submit on the same host track, so an arrow +// to them would run host->host. +Ac2gFlowRole ac2gFlowRole(ActivityType activityType) { + switch (activityType) { + case ActivityType::XPU_RUNTIME: + return Ac2gFlowRole::Source; + case ActivityType::CONCURRENT_KERNEL: + case ActivityType::GPU_MEMCPY: + case ActivityType::GPU_MEMSET: + return Ac2gFlowRole::Destination; + default: + return Ac2gFlowRole::None; + } +} + +} // namespace + template void XpuptiActivityProfilerSession::handleRuntimeKernelMemcpyMemsetActivities( ActivityType activityType, @@ -200,12 +224,13 @@ void XpuptiActivityProfilerSession::handleRuntimeKernelMemcpyMemsetActivities( trace_activity->startTime = activity->_start_timestamp; trace_activity->endTime = activity->_end_timestamp; trace_activity->threadId = activity->_thread_id; - // Avoid a redundant flow arrow from the XPU_RUNTIME submit to its nested - // XPU_DRIVER (ze*) subspan: leave the flow id 0 so output_json's - // `flowId() > 0` guard skips the endpoint. - if (carriesFlow(activityType)) { + // Records with no role keep flow id 0, which output_json's `flowId() > 0` + // guard skips -- that is what suppresses the arrow. + if (const auto role = ac2gFlowRole(activityType); + role != Ac2gFlowRole::None) { trace_activity->flow.id = activity->_correlation_id; trace_activity->flow.type = libkineto::kLinkAsyncCpuGpu; + trace_activity->flow.start = (role == Ac2gFlowRole::Source); } trace_activity->id = activity->_correlation_id; @@ -218,11 +243,9 @@ void XpuptiActivityProfilerSession::handleRuntimeKernelMemcpyMemsetActivities( if constexpr (handleRuntimeActivities) { trace_activity->device = activity->_process_id; trace_activity->resource = activity->_thread_id; - trace_activity->flow.start = startsFlow(activityType); } else { trace_activity->device = getDeviceIdxFromUUID(activity->_device_uuid); trace_activity->resource = activity->_sycl_queue_id; - trace_activity->flow.start = 0; if constexpr (handleKernelActivities) { kernelActivities_[activity->_kernel_id].emplace( diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp index 7645219ce..67077de6b 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp @@ -23,27 +23,6 @@ namespace KINETO_NAMESPACE { uint32_t XpuptiActivityProfilerSession::iterationCount_ = 0; std::vector XpuptiActivityProfilerSession::deviceUUIDs_ = {}; -bool XpuptiActivityProfilerSession::startsFlow(ActivityType activityType) { - // Only host runtime records start the CPU->GPU flow. The runtime view is - // already filtered to work-submitting APIs via - // ptiViewEnableRuntimeApiClass(PTI_API_CLASS_GPU_OPERATION_CORE). Driver - // (XPU_DRIVER) records share the same correlation id as the runtime record - // and must not also start a flow, or the trace gets a duplicate flow start. - return activityType == ActivityType::XPU_RUNTIME; -} - -bool XpuptiActivityProfilerSession::carriesFlow(ActivityType activityType) { - switch (activityType) { - case ActivityType::XPU_RUNTIME: - case ActivityType::CONCURRENT_KERNEL: - case ActivityType::GPU_MEMCPY: - case ActivityType::GPU_MEMSET: - return true; - default: - return false; - } -} - // =========== Session Constructor ============= // XpuptiActivityProfilerSession::XpuptiActivityProfilerSession( XpuptiActivityApi& xpti, diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h index 66a44bf03..1fe542349 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h @@ -67,16 +67,6 @@ class XpuptiActivityProfilerSession void pushUserCorrelationId(uint64_t id) override; void popUserCorrelationId() override; - // Whether a runtime/driver record starts a CPU->GPU flow arrow. Only host - // runtime (XPU_RUNTIME) records do; driver (XPU_DRIVER) records share the - // same correlation id and would otherwise create a duplicate flow start. - // Static so it can be unit-tested without real hardware. - static bool startsFlow(ActivityType activityType); - - // Whether the record is a CPU->GPU flow endpoint (runtime source or device - // destination); XPU_DRIVER subspans are not. Static for unit testing. - static bool carriesFlow(ActivityType activityType); - private: void checkTimestampOrder(const ITraceActivity* act1); void removeCorrelatedPtiActivities(const ITraceActivity* act1); diff --git a/libkineto/test/xpupti/CMakeLists.txt b/libkineto/test/xpupti/CMakeLists.txt index 94285cf49..05b4f3e42 100644 --- a/libkineto/test/xpupti/CMakeLists.txt +++ b/libkineto/test/xpupti/CMakeLists.txt @@ -24,11 +24,6 @@ add_executable(XpuptiActivityHandlersTest XpuptiActivityHandlersTest.cpp) target_link_libraries(XpuptiActivityHandlersTest PRIVATE ${LINK_LIBRARIES}) gtest_discover_tests(XpuptiActivityHandlersTest) -# Hardware-free test for the CPU->GPU flow-link allowlist. -add_executable(XpuptiFlowCorrelationTest XpuptiFlowCorrelationTest.cpp) -target_link_libraries(XpuptiFlowCorrelationTest PRIVATE ${LINK_LIBRARIES}) -gtest_discover_tests(XpuptiFlowCorrelationTest) - include(ExternalProject) # The compute translation unit contains SYCL device code and must be built by diff --git a/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp b/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp index 0e2f045a1..f343e882e 100644 --- a/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp +++ b/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp @@ -31,6 +31,12 @@ static_assert( static_assert( offsetof(pti_view_record_kernel, _view_kind) == 0, "base record must be first member"); +static_assert( + offsetof(pti_view_record_memory_copy, _view_kind) == 0, + "base record must be first member"); +static_assert( + offsetof(pti_view_record_memory_fill, _view_kind) == 0, + "base record must be first member"); // Mock XpuptiActivityApi that delivers hand-crafted PTI records // through the virtual processActivities without needing PTI runtime. @@ -344,7 +350,7 @@ TEST_F(XpuptiActivityHandlersTest, SynchronizationActivityOutOfRange) { EXPECT_EQ(traceBuffer->activities.size(), 0); } -// --- CPU->GPU flow endpoint tests --- +// --- ac2g flow role tests --- // A SYCL "submit" (XPU_RUNTIME), its nested Level Zero append (XPU_DRIVER) and // the resulting device kernel all share one correlation id. Only the runtime @@ -407,6 +413,9 @@ TEST_F( // output_json's `flowId() > 0` guard emits no link -> no redundant arrow). EXPECT_EQ(driver_activity.flowId(), 0); EXPECT_FALSE(driver_activity.flowStart()); + // Id and type must be set together: an id with type 0 reaches + // handleGenericLink(), which logs "Unknown flow type" per record. + EXPECT_EQ(driver_activity.flowType(), 0); auto& kernel_activity = *traceBuffer->activities[2]; EXPECT_EQ(kernel_activity.type(), ActivityType::CONCURRENT_KERNEL); @@ -415,6 +424,56 @@ TEST_F( EXPECT_FALSE(kernel_activity.flowStart()); } +// Memcpy and memset are device-side work like kernels, so they are flow +// destinations too. Each carries its own correlation id, matching one submit. +TEST_F(XpuptiActivityHandlersTest, MemcpyAndMemsetRecordsAreFlowDestinations) { + constexpr uint32_t kMemcpyCorrelationId = 51; + constexpr uint32_t kMemsetCorrelationId = 52; + + pti_view_record_memory_copy memcpy_record{}; + memcpy_record._view_kind._view_kind = PTI_VIEW_DEVICE_GPU_MEM_COPY; + memcpy_record._name = "zeCommandListAppendMemoryCopy"; + memcpy_record._start_timestamp = 200; + memcpy_record._end_timestamp = 240; + memcpy_record._thread_id = 7; + memcpy_record._correlation_id = kMemcpyCorrelationId; + memcpy_record._sycl_queue_id = 3; + memcpy_record._bytes = 4096; + memcpy_record._memcpy_type = PTI_VIEW_MEMCPY_TYPE_H2D; + memcpy_record._mem_src = PTI_VIEW_MEMORY_TYPE_HOST; + memcpy_record._mem_dst = PTI_VIEW_MEMORY_TYPE_DEVICE; + + pti_view_record_memory_fill memset_record{}; + memset_record._view_kind._view_kind = PTI_VIEW_DEVICE_GPU_MEM_FILL; + memset_record._name = "zeCommandListAppendMemoryFill"; + memset_record._start_timestamp = 300; + memset_record._end_timestamp = 330; + memset_record._thread_id = 7; + memset_record._correlation_id = kMemsetCorrelationId; + memset_record._sycl_queue_id = 3; + memset_record._bytes = 1024; + memset_record._mem_type = PTI_VIEW_MEMORY_TYPE_DEVICE; + memset_record._value_for_set = 0; + + mockApi_.records.push_back(&memcpy_record._view_kind); + mockApi_.records.push_back(&memset_record._view_kind); + + auto traceBuffer = processAndGetTrace(); + ASSERT_EQ(traceBuffer->activities.size(), 2); + + auto& memcpy_activity = *traceBuffer->activities[0]; + EXPECT_EQ(memcpy_activity.type(), ActivityType::GPU_MEMCPY); + EXPECT_EQ(memcpy_activity.flowId(), kMemcpyCorrelationId); + EXPECT_EQ(memcpy_activity.flowType(), kLinkAsyncCpuGpu); + EXPECT_FALSE(memcpy_activity.flowStart()); + + auto& memset_activity = *traceBuffer->activities[1]; + EXPECT_EQ(memset_activity.type(), ActivityType::GPU_MEMSET); + EXPECT_EQ(memset_activity.flowId(), kMemsetCorrelationId); + EXPECT_EQ(memset_activity.flowType(), kLinkAsyncCpuGpu); + EXPECT_FALSE(memset_activity.flowStart()); +} + // --- Mixed dispatch test --- TEST_F(XpuptiActivityHandlersTest, MixedCommunicationAndSynchronization) { diff --git a/libkineto/test/xpupti/XpuptiFlowCorrelationTest.cpp b/libkineto/test/xpupti/XpuptiFlowCorrelationTest.cpp deleted file mode 100644 index 6d1a7a1ff..000000000 --- a/libkineto/test/xpupti/XpuptiFlowCorrelationTest.cpp +++ /dev/null @@ -1,68 +0,0 @@ -//============================================================== -// Copyright (C) Intel Corporation -// -// SPDX-License-Identifier: MIT -// ============================================================= - -#include "src/plugin/xpupti/XpuptiActivityProfilerSession.h" - -#include - -namespace KN = KINETO_NAMESPACE; - -// Exercises the predicate that decides which records start a CPU->GPU ("ac2g") -// flow arrow. Runs without a GPU: only the static predicate is queried, no PTI -// collection is performed. - -TEST(XpuptiFlowCorrelationTest, RuntimeRecordsStartFlow) { - // Host runtime records (kernel launches, memcpy/fill enqueues) are the source - // of the CPU->GPU arrow. The runtime view is filtered to work-submitting APIs - // by ptiViewEnableRuntimeApiClass(PTI_API_CLASS_GPU_OPERATION_CORE). - EXPECT_TRUE(KN::XpuptiActivityProfilerSession::startsFlow( - KN::ActivityType::XPU_RUNTIME)); -} - -TEST(XpuptiFlowCorrelationTest, DriverRecordsDoNotStartFlow) { - // Driver (ze*) records share the runtime record's correlation id; if they - // also started a flow the trace would have a duplicate flow start for that - // id (Perfetto flow_duplicate_id). They must only be flow ends. - EXPECT_FALSE(KN::XpuptiActivityProfilerSession::startsFlow( - KN::ActivityType::XPU_DRIVER)); -} - -TEST(XpuptiFlowCorrelationTest, DeviceRecordsDoNotStartFlow) { - // GPU-side activities are flow destinations, never sources. - EXPECT_FALSE(KN::XpuptiActivityProfilerSession::startsFlow( - KN::ActivityType::CONCURRENT_KERNEL)); - EXPECT_FALSE(KN::XpuptiActivityProfilerSession::startsFlow( - KN::ActivityType::GPU_MEMCPY)); - EXPECT_FALSE(KN::XpuptiActivityProfilerSession::startsFlow( - KN::ActivityType::GPU_MEMSET)); -} - -// startsFlow() only picks the flow *source*. carriesFlow() decides whether a -// record is a flow endpoint at all -- the bug was that driver (ze*) records -// were still flow *ends* (sharing the runtime record's id), which draws a -// redundant host->host arrow. They must carry no flow. - -TEST(XpuptiFlowCorrelationTest, RuntimeAndDeviceRecordsCarryFlow) { - // The runtime record is the flow source; device activities are its - // destinations. All are genuine ac2g endpoints. - EXPECT_TRUE(KN::XpuptiActivityProfilerSession::carriesFlow( - KN::ActivityType::XPU_RUNTIME)); - EXPECT_TRUE(KN::XpuptiActivityProfilerSession::carriesFlow( - KN::ActivityType::CONCURRENT_KERNEL)); - EXPECT_TRUE(KN::XpuptiActivityProfilerSession::carriesFlow( - KN::ActivityType::GPU_MEMCPY)); - EXPECT_TRUE(KN::XpuptiActivityProfilerSession::carriesFlow( - KN::ActivityType::GPU_MEMSET)); -} - -TEST(XpuptiFlowCorrelationTest, DriverRecordsCarryNoFlow) { - // Driver (ze*) records share the runtime record's correlation id and are - // nested under the runtime "submit" slice on the same host track. A flow - // endpoint on them only produces a redundant host->host arrow, so they must - // carry no flow (neither start nor end). - EXPECT_FALSE(KN::XpuptiActivityProfilerSession::carriesFlow( - KN::ActivityType::XPU_DRIVER)); -} From 1af54a0b7c4014da3353b0c66f2d40481fa0336a Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski <81568391+aostrowski-hbn@users.noreply.github.com> Date: Tue, 1 Sep 2026 01:06:12 -0700 Subject: [PATCH 03/11] Fix review comment --- libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp index 11a2321f2..085ca649e 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp @@ -226,8 +226,8 @@ void XpuptiActivityProfilerSession::handleRuntimeKernelMemcpyMemsetActivities( trace_activity->threadId = activity->_thread_id; // Records with no role keep flow id 0, which output_json's `flowId() > 0` // guard skips -- that is what suppresses the arrow. - if (const auto role = ac2gFlowRole(activityType); - role != Ac2gFlowRole::None) { + const auto role = ac2gFlowRole(activityType); + if (role != Ac2gFlowRole::None) { trace_activity->flow.id = activity->_correlation_id; trace_activity->flow.type = libkineto::kLinkAsyncCpuGpu; trace_activity->flow.start = (role == Ac2gFlowRole::Source); From f188869cdef672e844255c0af9bec32d23dbe58c Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Wed, 2 Sep 2026 17:03:04 +0200 Subject: [PATCH 04/11] [xpupti] Keep ac2g flows without the runtime view An activity selection that keeps XPU_DRIVER but drops XPU_RUNTIME lost every CPU->GPU arrow, as only a runtime record could start a flow. Let the driver record take that role when the runtime view is absent; it shares the device work's correlation id. While both views are collected the driver record stays out of the flow: an arrow to a span nested under the submit would run host->host. Co-Authored-By: Claude Opus 5 (1M context) --- .../plugin/xpupti/XpuptiActivityHandlers.cpp | 18 +++-- .../xpupti/XpuptiActivityProfilerSession.cpp | 1 + .../xpupti/XpuptiActivityProfilerSession.h | 3 + .../plugin/xpupti/XpuptiActivityTypeMask.h | 43 ++++++++++ libkineto/test/xpupti/CMakeLists.txt | 4 + .../xpupti/XpuptiActivityHandlersTest.cpp | 74 +++++++++++++++-- .../xpupti/XpuptiActivityTypeMaskTest.cpp | 81 +++++++++++++++++++ 7 files changed, 212 insertions(+), 12 deletions(-) create mode 100644 libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h create mode 100644 libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp index 11a2321f2..964fac4b7 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp @@ -165,13 +165,18 @@ namespace { // to the device operation it enqueued. enum class Ac2gFlowRole : uint8_t { None, Source, Destination }; -// XPU_DRIVER (ze*) subspans share the runtime record's correlation id but play -// no part: they are nested under the submit on the same host track, so an arrow -// to them would run host->host. -Ac2gFlowRole ac2gFlowRole(ActivityType activityType) { +// The host end is normally the XPU_RUNTIME (ur*) submit. An XPU_DRIVER (ze*) +// subspan shares its correlation id, so while both are collected the driver +// record plays no part -- it is nested under the submit on the same host track, +// and an arrow to it would run host->host. When XPU_RUNTIME is filtered out the +// driver record is the only host record left for that correlation id, so it +// takes over as the source instead of the trace losing every arrow. +Ac2gFlowRole ac2gFlowRole(ActivityType activityType, bool runtimeTraced) { switch (activityType) { case ActivityType::XPU_RUNTIME: return Ac2gFlowRole::Source; + case ActivityType::XPU_DRIVER: + return runtimeTraced ? Ac2gFlowRole::None : Ac2gFlowRole::Source; case ActivityType::CONCURRENT_KERNEL: case ActivityType::GPU_MEMCPY: case ActivityType::GPU_MEMSET: @@ -226,7 +231,8 @@ void XpuptiActivityProfilerSession::handleRuntimeKernelMemcpyMemsetActivities( trace_activity->threadId = activity->_thread_id; // Records with no role keep flow id 0, which output_json's `flowId() > 0` // guard skips -- that is what suppresses the arrow. - if (const auto role = ac2gFlowRole(activityType); + if (const auto role = ac2gFlowRole( + activityType, tracedTypes_.contains(ActivityType::XPU_RUNTIME)); role != Ac2gFlowRole::None) { trace_activity->flow.id = activity->_correlation_id; trace_activity->flow.type = libkineto::kLinkAsyncCpuGpu; @@ -342,7 +348,7 @@ void XpuptiActivityProfilerSession::handleRuntimeKernelMemcpyMemsetActivities( // fresh GenericTraceActivity linked back to the CPU op. The annotations // are flushed to the logger at the end of processTrace(). if constexpr (!handleRuntimeActivities) { - if (activity_types_.count(ActivityType::GPU_USER_ANNOTATION)) { + if (tracedTypes_.contains(ActivityType::GPU_USER_ANNOTATION)) { auto userIt = userCorrelationMap_.find(activity->_correlation_id); if (userIt != userCorrelationMap_.end() && cpuActivity_) { const int64_t user_external_id = userIt->second; diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp index 67077de6b..6cffff852 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp @@ -32,6 +32,7 @@ XpuptiActivityProfilerSession::XpuptiActivityProfilerSession( : xpti_(xpti), config_(config.clone()), activity_types_(activity_types), + tracedTypes_(activity_types), name_(name) { enumDeviceUUIDs(); xpti_.enableXpuptiActivities(activity_types_); diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h index 1fe542349..24be6a7d8 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h @@ -8,6 +8,7 @@ #pragma once +#include "XpuptiActivityTypeMask.h" #include "XpuptiProfilerMacros.h" #include "IActivityProfiler.h" @@ -140,6 +141,8 @@ class XpuptiActivityProfilerSession std::vector> resourceInfo_; std::unique_ptr config_{nullptr}; const std::set& activity_types_; + // The same selection as activity_types_, for the per-record queries. + ActivityTypeMask tracedTypes_; std::string name_; struct KernelActivity { diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h new file mode 100644 index 000000000..a8842f39d --- /dev/null +++ b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) Intel Corporation + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include "ActivityType.h" + +#include +#include +#include + +namespace KINETO_NAMESPACE { + +// A set of activity types held as a bitset: built once, queried per record. +// Sized from the enum, so activity types can be added without outgrowing it, +// and a value outside the enum throws instead of shifting out of range. +class ActivityTypeMask { + public: + ActivityTypeMask() = default; + + explicit ActivityTypeMask(const std::set& types) { + for (const auto type : types) { + bits_.set(index(type)); + } + } + + bool contains(ActivityType type) const { + return bits_.test(index(type)); + } + + private: + static constexpr size_t index(ActivityType type) { + return static_cast(type); + } + + std::bitset bits_; +}; + +} // namespace KINETO_NAMESPACE diff --git a/libkineto/test/xpupti/CMakeLists.txt b/libkineto/test/xpupti/CMakeLists.txt index 05b4f3e42..758c97892 100644 --- a/libkineto/test/xpupti/CMakeLists.txt +++ b/libkineto/test/xpupti/CMakeLists.txt @@ -24,6 +24,10 @@ add_executable(XpuptiActivityHandlersTest XpuptiActivityHandlersTest.cpp) target_link_libraries(XpuptiActivityHandlersTest PRIVATE ${LINK_LIBRARIES}) gtest_discover_tests(XpuptiActivityHandlersTest) +add_executable(XpuptiActivityTypeMaskTest XpuptiActivityTypeMaskTest.cpp) +target_link_libraries(XpuptiActivityTypeMaskTest PRIVATE ${LINK_LIBRARIES}) +gtest_discover_tests(XpuptiActivityTypeMaskTest) + include(ExternalProject) # The compute translation unit contains SYCL device code and must be built by diff --git a/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp b/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp index f343e882e..7ea75fa74 100644 --- a/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp +++ b/libkineto/test/xpupti/XpuptiActivityHandlersTest.cpp @@ -92,14 +92,26 @@ class XpuptiActivityHandlersTest : public ::testing::Test { MockXpuptiActivityApi mockApi_; MockActivityLogger logger_; + // The activity types a full XPU session collects: both host views plus + // device work. Tests that filter a view out pass their own set. + static std::set allActivityTypes() { + return { + ActivityType::COLLECTIVE_COMM, + ActivityType::XPU_SYNC, + ActivityType::XPU_RUNTIME, + ActivityType::XPU_DRIVER, + ActivityType::CONCURRENT_KERNEL, + ActivityType::GPU_MEMCPY, + ActivityType::GPU_MEMSET}; + } + // Processes all records in mockApi_ through the handler pipeline // and returns the resulting trace buffer. std::unique_ptr processAndGetTrace( int64_t windowStart = 0, - int64_t windowEnd = 1000) { + int64_t windowEnd = 1000, + const std::set& activity_types = allActivityTypes()) { Config config; - std::set activity_types = { - ActivityType::COLLECTIVE_COMM, ActivityType::XPU_SYNC}; auto session = std::make_unique( mockApi_, "__test_profiler__", config, activity_types); session->processTrace( @@ -353,9 +365,10 @@ TEST_F(XpuptiActivityHandlersTest, SynchronizationActivityOutOfRange) { // --- ac2g flow role tests --- // A SYCL "submit" (XPU_RUNTIME), its nested Level Zero append (XPU_DRIVER) and -// the resulting device kernel all share one correlation id. Only the runtime -// record (source) and the kernel record (destination) may be ac2g flow -// endpoints. The driver record must carry no flow, otherwise Perfetto draws a +// the resulting device kernel all share one correlation id. While both host +// views are collected, only the runtime record (source) and the kernel record +// (destination) may be ac2g flow endpoints. The driver record must then carry +// no flow, otherwise Perfetto draws a // redundant host->host arrow from the runtime "submit" slice to its nested ze* // child. Uses _api_id/_api_group 84/LEVELZERO for the api records so // ptiViewGetApiIdName() resolves a name (same as the synchronization tests). @@ -424,6 +437,55 @@ TEST_F( EXPECT_FALSE(kernel_activity.flowStart()); } +// With the runtime view filtered out, the ze* record is the only host record +// left for that correlation id, so it takes over as the flow source -- the +// device work keeps its CPU->GPU arrow instead of losing it to the filter. +TEST_F( + XpuptiActivityHandlersTest, + DriverRecordIsFlowSourceWhenRuntimeNotTraced) { + constexpr uint32_t kCorrelationId = 43; + + pti_view_record_api driver_record{}; + driver_record._view_kind._view_kind = PTI_VIEW_DRIVER_API; + driver_record._start_timestamp = 110; + driver_record._end_timestamp = 140; + driver_record._process_id = 1; + driver_record._thread_id = 7; + driver_record._correlation_id = kCorrelationId; + driver_record._api_id = 84; + driver_record._api_group = static_cast(1); + + pti_view_record_kernel kernel_record{}; + kernel_record._view_kind._view_kind = PTI_VIEW_DEVICE_GPU_KERNEL; + kernel_record._name = "gemm_kernel"; + kernel_record._start_timestamp = 200; + kernel_record._end_timestamp = 260; + kernel_record._thread_id = 7; + kernel_record._correlation_id = kCorrelationId; + kernel_record._sycl_queue_id = 3; + kernel_record._kernel_id = 9; + + mockApi_.records.push_back(&driver_record._view_kind); + mockApi_.records.push_back(&kernel_record._view_kind); + + auto activity_types = allActivityTypes(); + activity_types.erase(ActivityType::XPU_RUNTIME); + auto traceBuffer = processAndGetTrace(0, 1000, activity_types); + ASSERT_EQ(traceBuffer->activities.size(), 2); + + auto& driver_activity = *traceBuffer->activities[0]; + EXPECT_EQ(driver_activity.type(), ActivityType::XPU_DRIVER); + EXPECT_EQ(driver_activity.flowId(), kCorrelationId); + EXPECT_EQ(driver_activity.flowType(), kLinkAsyncCpuGpu); + EXPECT_TRUE(driver_activity.flowStart()); + + auto& kernel_activity = *traceBuffer->activities[1]; + EXPECT_EQ(kernel_activity.type(), ActivityType::CONCURRENT_KERNEL); + EXPECT_EQ(kernel_activity.flowId(), kCorrelationId); + EXPECT_EQ(kernel_activity.flowType(), kLinkAsyncCpuGpu); + EXPECT_FALSE(kernel_activity.flowStart()); +} + // Memcpy and memset are device-side work like kernels, so they are flow // destinations too. Each carries its own correlation id, matching one submit. TEST_F(XpuptiActivityHandlersTest, MemcpyAndMemsetRecordsAreFlowDestinations) { diff --git a/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp b/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp new file mode 100644 index 000000000..8f2b7dccb --- /dev/null +++ b/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) Intel Corporation + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "src/plugin/xpupti/XpuptiActivityTypeMask.h" + +#include + +#include +#include + +namespace KN = KINETO_NAMESPACE; +using libkineto::ActivityType; + +TEST(ActivityTypeMaskTest, DefaultConstructedContainsNothing) { + const KN::ActivityTypeMask mask; + + for (int type = 0; type < libkineto::activityTypeCount; ++type) { + EXPECT_FALSE(mask.contains(static_cast(type))) + << "type " << type; + } +} + +TEST(ActivityTypeMaskTest, ContainsExactlyTheSelectedTypes) { + const std::set selected = { + ActivityType::XPU_DRIVER, + ActivityType::CONCURRENT_KERNEL, + ActivityType::GPU_MEMCPY}; + const KN::ActivityTypeMask mask(selected); + + for (int type = 0; type < libkineto::activityTypeCount; ++type) { + const auto activityType = static_cast(type); + EXPECT_EQ(mask.contains(activityType), selected.contains(activityType)) + << "type " << type; + } +} + +// The bitset is sized from the enum, so the last enumerator is the case that +// would fall off a mask sized by hand. +TEST(ActivityTypeMaskTest, HoldsTheHighestActivityType) { + constexpr auto highest = + static_cast(libkineto::activityTypeCount - 1); + const KN::ActivityTypeMask mask({highest}); + + EXPECT_TRUE(mask.contains(highest)); + EXPECT_FALSE(mask.contains(static_cast(0))); +} + +TEST(ActivityTypeMaskTest, HoldsEveryActivityTypeAtOnce) { + std::set all; + for (int type = 0; type < libkineto::activityTypeCount; ++type) { + all.insert(static_cast(type)); + } + const KN::ActivityTypeMask mask(all); + + for (const auto activityType : all) { + EXPECT_TRUE(mask.contains(activityType)) + << "type " << static_cast(activityType); + } +} + +TEST(ActivityTypeMaskTest, EmptySelectionContainsNothing) { + const KN::ActivityTypeMask mask(std::set{}); + + EXPECT_FALSE(mask.contains(ActivityType::XPU_RUNTIME)); + EXPECT_FALSE(mask.contains(ActivityType::XPU_DRIVER)); +} + +// A value the enum does not define is a caller bug, not a silent false: the +// bitset reports it instead of shifting past its own width. +TEST(ActivityTypeMaskTest, RejectsAValueOutsideTheEnum) { + const KN::ActivityTypeMask mask({ActivityType::XPU_DRIVER}); + const auto beyondEnum = + static_cast(libkineto::activityTypeCount); + + EXPECT_THROW(mask.contains(beyondEnum), std::out_of_range); + EXPECT_THROW(KN::ActivityTypeMask({beyondEnum}), std::out_of_range); +} From 4db6d0fcf15c573b95860932d60c53fbdfd906b7 Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Mon, 7 Sep 2026 17:39:00 +0200 Subject: [PATCH 05/11] [xpupti] Own the session's activity selection The session borrowed a reference into a ConfigDerivedState that kineto rebuilds on every configure(), and it now also derives a bitmask from that set. Copying it removes both the dangling-reference window and the second representation that could drift from the first. Co-Authored-By: Claude Opus 5 (1M context) --- libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h index 05b97df39..b5049dcb5 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h @@ -153,8 +153,10 @@ class XpuptiActivityProfilerSession libkineto::CpuTraceBuffer traceBuffer_; std::vector> resourceInfo_; std::unique_ptr config_; - const std::set& activity_types_; - // The same selection as activity_types_, for the per-record queries. + // Owned, not borrowed: the caller's set lives in a ConfigDerivedState that is + // rebuilt on every configure(), and tracedTypes_ is derived from this copy + // once, so a single owner keeps the two representations from drifting apart. + const std::set activity_types_; ActivityTypeMask tracedTypes_; std::string name_; From 307a100693ab57506aa9d02603343dcffbe38506 Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Wed, 9 Sep 2026 14:13:43 +0200 Subject: [PATCH 06/11] [xpupti] Drop unused mask ctor, reword flow role The ac2g comment now says what the function decides instead of how the records nest, and stays with the XPU_RUNTIME/XPU_DRIVER names the rest of Kineto uses. The mask's default constructor had no caller, and the local enum has no reason to fix its underlying type. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/plugin/xpupti/XpuptiActivityHandlers.cpp | 16 ++++++---------- .../src/plugin/xpupti/XpuptiActivityTypeMask.h | 2 -- .../test/xpupti/XpuptiActivityTypeMaskTest.cpp | 9 --------- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp index 4048905f2..72f8e25d1 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp @@ -178,16 +178,12 @@ static void addTimestampMetadata( namespace { -// Part a record plays in the async CPU->GPU ("ac2g") flow linking a host submit -// to the device operation it enqueued. -enum class Ac2gFlowRole : uint8_t { None, Source, Destination }; - -// The host end is normally the XPU_RUNTIME (ur*) submit. An XPU_DRIVER (ze*) -// subspan shares its correlation id, so while both are collected the driver -// record plays no part -- it is nested under the submit on the same host track, -// and an arrow to it would run host->host. When XPU_RUNTIME is filtered out the -// driver record is the only host record left for that correlation id, so it -// takes over as the source instead of the trace losing every arrow. +enum class Ac2gFlowRole { None, Source, Destination }; + +// Denotes the role an activity plays for Async CPU to GPU flow arrows. Both +// XPU_RUNTIME and XPU_DRIVER events have the same correlation IDs and thus can +// be sources, but exactly one must be chosen to avoid superfluous host->host +// arrows. Prefer XPU_RUNTIME unless it is not being traced. Ac2gFlowRole ac2gFlowRole(ActivityType activityType, bool runtimeTraced) { switch (activityType) { case ActivityType::XPU_RUNTIME: diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h index a8842f39d..14443c124 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h @@ -20,8 +20,6 @@ namespace KINETO_NAMESPACE { // and a value outside the enum throws instead of shifting out of range. class ActivityTypeMask { public: - ActivityTypeMask() = default; - explicit ActivityTypeMask(const std::set& types) { for (const auto type : types) { bits_.set(index(type)); diff --git a/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp b/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp index 8f2b7dccb..b7c1f6a6b 100644 --- a/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp +++ b/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp @@ -15,15 +15,6 @@ namespace KN = KINETO_NAMESPACE; using libkineto::ActivityType; -TEST(ActivityTypeMaskTest, DefaultConstructedContainsNothing) { - const KN::ActivityTypeMask mask; - - for (int type = 0; type < libkineto::activityTypeCount; ++type) { - EXPECT_FALSE(mask.contains(static_cast(type))) - << "type " << type; - } -} - TEST(ActivityTypeMaskTest, ContainsExactlyTheSelectedTypes) { const std::set selected = { ActivityType::XPU_DRIVER, From c61bb808fe4ace9d6355182588f681c3fa84e25e Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Wed, 9 Sep 2026 14:22:55 +0200 Subject: [PATCH 07/11] [xpupti] Keep the activity selection in one place The session held the selection twice: the caller's set and a bitmask derived from it, which could drift apart. Our own enable/disable API now takes the mask, so the session keeps only that. The selection is fixed for a session's lifetime, since kineto clears its sessions before it rebuilds the config state on the next configure(). Co-Authored-By: Claude Opus 5 (1M context) --- libkineto/src/plugin/xpupti/XpuptiActivityApi.cpp | 12 ++++++------ libkineto/src/plugin/xpupti/XpuptiActivityApi.h | 6 +++--- .../plugin/xpupti/XpuptiActivityProfilerSession.cpp | 9 ++++----- .../plugin/xpupti/XpuptiActivityProfilerSession.h | 7 +++---- libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h | 10 ++++++++++ 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityApi.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityApi.cpp index f9ab52f05..0fd9837ce 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityApi.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityApi.cpp @@ -204,12 +204,12 @@ void warnIfIttNotifyLibInvalid() noexcept { } // namespace void XpuptiActivityApi::enableXpuptiActivities( - const std::set& selected_activities) { + const ActivityTypeMask& selected_activities) { XPUPTI_CALL(ptiViewSetCallbacks( bufferRequestedTrampoline, bufferCompletedTrampoline)); externalCorrelationEnabled_ = false; - for (const auto& activity : selected_activities) { + selected_activities.forEach([this](ActivityType activity) { switch (activity) { case ActivityType::GPU_MEMCPY: XPUPTI_CALL(ptiViewEnable(PTI_VIEW_DEVICE_GPU_MEM_COPY)); @@ -259,12 +259,12 @@ void XpuptiActivityApi::enableXpuptiActivities( default: break; } - } + }); } void XpuptiActivityApi::disablePtiActivities( - const std::set& selected_activities) { - for (const auto& activity : selected_activities) { + const ActivityTypeMask& selected_activities) { + selected_activities.forEach([](ActivityType activity) { switch (activity) { case ActivityType::GPU_MEMCPY: XPUPTI_CALL(ptiViewDisable(PTI_VIEW_DEVICE_GPU_MEM_COPY)); @@ -305,7 +305,7 @@ void XpuptiActivityApi::disablePtiActivities( default: break; } - } + }); externalCorrelationEnabled_ = false; } diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityApi.h b/libkineto/src/plugin/xpupti/XpuptiActivityApi.h index 2062b42d3..122b3c8ed 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityApi.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityApi.h @@ -10,6 +10,7 @@ #include "ActivityType.h" #include "XpuptiActivityBuffer.h" +#include "XpuptiActivityTypeMask.h" #include #include @@ -43,9 +44,8 @@ class XpuptiActivityApi { static void pushCorrelationID(int id, CorrelationFlowType type); static void popCorrelationID(CorrelationFlowType type); - void enableXpuptiActivities( - const std::set& selected_activities); - void disablePtiActivities(const std::set& selected_activities); + void enableXpuptiActivities(const ActivityTypeMask& selected_activities); + void disablePtiActivities(const ActivityTypeMask& selected_activities); void clearActivities(); void flushActivities(); diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp index 0772bc584..bde298ac6 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.cpp @@ -39,11 +39,10 @@ XpuptiActivityProfilerSession::XpuptiActivityProfilerSession( const std::set& activity_types) : xpti_(xpti), config_(config.clone()), - activity_types_(activity_types), tracedTypes_(activity_types), name_(name) { enumDeviceUUIDs(); - xpti_.enableXpuptiActivities(activity_types_); + xpti_.enableXpuptiActivities(tracedTypes_); } XpuptiActivityProfilerSession::~XpuptiActivityProfilerSession() { @@ -57,15 +56,15 @@ void XpuptiActivityProfilerSession::start() { } void XpuptiActivityProfilerSession::stop() { - xpti_.disablePtiActivities(activity_types_); + xpti_.disablePtiActivities(tracedTypes_); profilerEndTs_ = libkineto::timeSinceEpoch(std::chrono::system_clock::now()); } void XpuptiActivityProfilerSession::toggleCollectionDynamic(const bool enable) { if (enable) { - xpti_.enableXpuptiActivities(activity_types_); + xpti_.enableXpuptiActivities(tracedTypes_); } else { - xpti_.disablePtiActivities(activity_types_); + xpti_.disablePtiActivities(tracedTypes_); } } diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h index 5ce27b69b..91d4fa4ee 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h @@ -163,10 +163,9 @@ class XpuptiActivityProfilerSession libkineto::CpuTraceBuffer traceBuffer_; std::vector> resourceInfo_; std::unique_ptr config_; - // Owned, not borrowed: the caller's set lives in a ConfigDerivedState that is - // rebuilt on every configure(), and tracedTypes_ is derived from this copy - // once, so a single owner keeps the two representations from drifting apart. - const std::set activity_types_; + // The session's activity selection, kept only in this form so there is no + // second representation to drift from. Fixed for the session's lifetime: + // kineto builds a fresh session per configure(). ActivityTypeMask tracedTypes_; std::string name_; diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h index 14443c124..c7fbc590d 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h @@ -30,6 +30,16 @@ class ActivityTypeMask { return bits_.test(index(type)); } + // Calls visit() for each activity type in the set. + template + void forEach(Visitor&& visit) const { + for (size_t type = 0; type < bits_.size(); ++type) { + if (bits_.test(type)) { + visit(static_cast(type)); + } + } + } + private: static constexpr size_t index(ActivityType type) { return static_cast(type); From a532806689a9c4d6653f1511cbc81e2392c322a7 Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Wed, 9 Sep 2026 14:40:24 +0200 Subject: [PATCH 08/11] [xpupti] Constrain the mask visitor with a concept An unconstrained template parameter accepts anything and reports the mismatch from deep inside the body; std::invocable states the expected signature at the boundary, where the caller sees it. Kineto already uses this form in TypedMetadata.h. The visiting order is now part of the contract, so tests cover it. Co-Authored-By: Claude Opus 5 (1M context) --- .../plugin/xpupti/XpuptiActivityTypeMask.h | 6 ++--- .../xpupti/XpuptiActivityTypeMaskTest.cpp | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h index c7fbc590d..98b144608 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h @@ -10,6 +10,7 @@ #include "ActivityType.h" #include +#include #include #include @@ -30,9 +31,8 @@ class ActivityTypeMask { return bits_.test(index(type)); } - // Calls visit() for each activity type in the set. - template - void forEach(Visitor&& visit) const { + // Calls visit() for each activity type in the set, in ascending order. + void forEach(std::invocable auto&& visit) const { for (size_t type = 0; type < bits_.size(); ++type) { if (bits_.test(type)) { visit(static_cast(type)); diff --git a/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp b/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp index b7c1f6a6b..9dd9d374e 100644 --- a/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp +++ b/libkineto/test/xpupti/XpuptiActivityTypeMaskTest.cpp @@ -11,6 +11,7 @@ #include #include +#include namespace KN = KINETO_NAMESPACE; using libkineto::ActivityType; @@ -53,6 +54,31 @@ TEST(ActivityTypeMaskTest, HoldsEveryActivityTypeAtOnce) { } } +TEST(ActivityTypeMaskTest, ForEachVisitsTheSelectedTypesInOrder) { + const std::set selected = { + ActivityType::GPU_MEMCPY, + ActivityType::XPU_RUNTIME, + ActivityType::CONCURRENT_KERNEL}; + const KN::ActivityTypeMask mask(selected); + + std::vector visited; + mask.forEach([&visited](ActivityType type) { visited.push_back(type); }); + + // std::set already iterates in ascending order, so it doubles as the + // expected sequence. + const std::vector expected(selected.begin(), selected.end()); + EXPECT_EQ(visited, expected); +} + +TEST(ActivityTypeMaskTest, ForEachVisitsNothingWhenTheSelectionIsEmpty) { + const KN::ActivityTypeMask mask(std::set{}); + + int visits = 0; + mask.forEach([&visits](ActivityType) { ++visits; }); + + EXPECT_EQ(visits, 0); +} + TEST(ActivityTypeMaskTest, EmptySelectionContainsNothing) { const KN::ActivityTypeMask mask(std::set{}); From fb82b7779fd8db6fbee4af1e187779e54651af95 Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Tue, 22 Sep 2026 12:17:20 +0200 Subject: [PATCH 09/11] [xpupti] Make the ac2g flow role a session method The driver record's role depends on whether the runtime view is traced, which a free function could only learn through a bool argument set at the call site -- far from the one case that reads it. As a member of the session that owns the activity selection, it consults that selection in the XPU_DRIVER branch itself. Co-Authored-By: Claude Opus 5 (1M context) --- .../plugin/xpupti/XpuptiActivityHandlers.cpp | 26 +++++++------------ .../xpupti/XpuptiActivityProfilerSession.h | 8 ++++++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp index 72f8e25d1..19c75a7fb 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityHandlers.cpp @@ -176,20 +176,19 @@ static void addTimestampMetadata( label, formatTimeLikeOutputJson(signedFromUnsignedDiff(time, time_ref))); } -namespace { - -enum class Ac2gFlowRole { None, Source, Destination }; - -// Denotes the role an activity plays for Async CPU to GPU flow arrows. Both -// XPU_RUNTIME and XPU_DRIVER events have the same correlation IDs and thus can -// be sources, but exactly one must be chosen to avoid superfluous host->host -// arrows. Prefer XPU_RUNTIME unless it is not being traced. -Ac2gFlowRole ac2gFlowRole(ActivityType activityType, bool runtimeTraced) { +auto XpuptiActivityProfilerSession::ac2gFlowRole( + ActivityType activityType) const -> Ac2gFlowRole { switch (activityType) { case ActivityType::XPU_RUNTIME: return Ac2gFlowRole::Source; case ActivityType::XPU_DRIVER: - return runtimeTraced ? Ac2gFlowRole::None : Ac2gFlowRole::Source; + // Runtime and driver records carry the same correlation id, so only one + // of them may source the flow or the trace gains a host->host arrow. + // The runtime record wins; the driver record takes over when the runtime + // view is not traced. + return tracedTypes_.contains(ActivityType::XPU_RUNTIME) + ? Ac2gFlowRole::None + : Ac2gFlowRole::Source; case ActivityType::CONCURRENT_KERNEL: case ActivityType::GPU_MEMCPY: case ActivityType::GPU_MEMSET: @@ -199,8 +198,6 @@ Ac2gFlowRole ac2gFlowRole(ActivityType activityType, bool runtimeTraced) { } } -} // namespace - template void XpuptiActivityProfilerSession::handleRuntimeKernelMemcpyMemsetActivities( ActivityType activityType, @@ -242,10 +239,7 @@ void XpuptiActivityProfilerSession::handleRuntimeKernelMemcpyMemsetActivities( trace_activity->startTime = activity->_start_timestamp; trace_activity->endTime = activity->_end_timestamp; trace_activity->threadId = activity->_thread_id; - // Records with no role keep flow id 0, which output_json's `flowId() > 0` - // guard skips -- that is what suppresses the arrow. - const auto role = ac2gFlowRole( - activityType, tracedTypes_.contains(ActivityType::XPU_RUNTIME)); + const auto role = ac2gFlowRole(activityType); if (role != Ac2gFlowRole::None) { trace_activity->flow.id = activity->_correlation_id; trace_activity->flow.type = libkineto::kLinkAsyncCpuGpu; diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h index 91d4fa4ee..23973cdfa 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityProfilerSession.h @@ -112,6 +112,14 @@ class XpuptiActivityProfilerSession return std::string(api_name); } + // Which end of an Async CPU->GPU (ac2g) flow arrow a record is, if any. + enum class Ac2gFlowRole { None, Source, Destination }; + + // The role this session gives a record of the given activity type. Records + // with no role keep flow id 0, which output_json's `flowId() > 0` guard + // skips, so they get no arrow. + Ac2gFlowRole ac2gFlowRole(ActivityType activityType) const; + template void handleRuntimeKernelMemcpyMemsetActivities( ActivityType activityType, From 2c0c69105c7b95ed215d5e83fed7f196c72ddf5f Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Tue, 22 Sep 2026 12:18:05 +0200 Subject: [PATCH 10/11] [xpupti] Rename the mask index helper to asIndex Co-Authored-By: Claude Opus 5 (1M context) --- libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h index 98b144608..272e46582 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h +++ b/libkineto/src/plugin/xpupti/XpuptiActivityTypeMask.h @@ -23,12 +23,12 @@ class ActivityTypeMask { public: explicit ActivityTypeMask(const std::set& types) { for (const auto type : types) { - bits_.set(index(type)); + bits_.set(asIndex(type)); } } bool contains(ActivityType type) const { - return bits_.test(index(type)); + return bits_.test(asIndex(type)); } // Calls visit() for each activity type in the set, in ascending order. @@ -41,7 +41,7 @@ class ActivityTypeMask { } private: - static constexpr size_t index(ActivityType type) { + static constexpr size_t asIndex(ActivityType type) { return static_cast(type); } From f3cfa27b95144cf8fbbd9743ee6ce5f6e5fe4468 Mon Sep 17 00:00:00 2001 From: Adrian Ostrowski Date: Tue, 22 Sep 2026 12:18:05 +0200 Subject: [PATCH 11/11] [xpupti] Map an activity to its PTI view once Enabling and disabling the views repeated the same list of activity types, so a type added to one could be missed in the other. A single mapping now answers which view a type is collected through, leaving enable with just the extras a view needs on top. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/plugin/xpupti/XpuptiActivityApi.cpp | 114 +++++++----------- 1 file changed, 41 insertions(+), 73 deletions(-) diff --git a/libkineto/src/plugin/xpupti/XpuptiActivityApi.cpp b/libkineto/src/plugin/xpupti/XpuptiActivityApi.cpp index 0fd9837ce..540384c45 100644 --- a/libkineto/src/plugin/xpupti/XpuptiActivityApi.cpp +++ b/libkineto/src/plugin/xpupti/XpuptiActivityApi.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -201,6 +202,35 @@ void warnIfIttNotifyLibInvalid() noexcept { << "XCCL host calls will not be collected."; } } + +// The PTI view an activity type is collected through, if it has one of its own. +// Shared by enable and disable so the two cannot drift apart. +constexpr std::optional findPtiViewKind(ActivityType activity) { + switch (activity) { + case ActivityType::GPU_MEMCPY: + return PTI_VIEW_DEVICE_GPU_MEM_COPY; + case ActivityType::GPU_MEMSET: + return PTI_VIEW_DEVICE_GPU_MEM_FILL; + case ActivityType::CONCURRENT_KERNEL: + return PTI_VIEW_DEVICE_GPU_KERNEL; + case ActivityType::EXTERNAL_CORRELATION: + return PTI_VIEW_EXTERNAL_CORRELATION; + case ActivityType::XPU_RUNTIME: + return PTI_VIEW_RUNTIME_API; + case ActivityType::XPU_DRIVER: + return PTI_VIEW_DRIVER_API; + case ActivityType::OVERHEAD: + return PTI_VIEW_COLLECTION_OVERHEAD; + case ActivityType::XPU_SYNC: + return PTI_VIEW_DEVICE_SYNCHRONIZATION; + case ActivityType::COLLECTIVE_COMM: + return PTI_VIEW_COMMUNICATION; + default: + // XPU_SCOPE_PROFILER among others: enabled by + // XpuptiScopeProfilerSession's constructor, not by a view. + return std::nullopt; + } +} } // namespace void XpuptiActivityApi::enableXpuptiActivities( @@ -210,50 +240,25 @@ void XpuptiActivityApi::enableXpuptiActivities( externalCorrelationEnabled_ = false; selected_activities.forEach([this](ActivityType activity) { - switch (activity) { - case ActivityType::GPU_MEMCPY: - XPUPTI_CALL(ptiViewEnable(PTI_VIEW_DEVICE_GPU_MEM_COPY)); - break; - - case ActivityType::GPU_MEMSET: - XPUPTI_CALL(ptiViewEnable(PTI_VIEW_DEVICE_GPU_MEM_FILL)); - break; - - case ActivityType::CONCURRENT_KERNEL: - XPUPTI_CALL(ptiViewEnable(PTI_VIEW_DEVICE_GPU_KERNEL)); - break; - - case ActivityType::EXTERNAL_CORRELATION: - XPUPTI_CALL(ptiViewEnable(PTI_VIEW_EXTERNAL_CORRELATION)); - externalCorrelationEnabled_ = true; - break; + const auto view = findPtiViewKind(activity); + if (not view) { + return; + } + XPUPTI_CALL(ptiViewEnable(*view)); + // What enabling a view takes on top of the view itself. + switch (activity) { case ActivityType::XPU_RUNTIME: - XPUPTI_CALL(ptiViewEnable(PTI_VIEW_RUNTIME_API)); XPUPTI_CALL(ptiViewEnableRuntimeApiClass( 1, PTI_API_CLASS_GPU_OPERATION_CORE, PTI_API_GROUP_ALL)); break; - case ActivityType::XPU_DRIVER: - XPUPTI_CALL(ptiViewEnable(PTI_VIEW_DRIVER_API)); - break; - - case ActivityType::XPU_SCOPE_PROFILER: - // This case is handled in constructor of - // XpuptiScopeProfilerSession - break; - - case ActivityType::OVERHEAD: - XPUPTI_CALL(ptiViewEnable(PTI_VIEW_COLLECTION_OVERHEAD)); - break; - - case ActivityType::XPU_SYNC: - XPUPTI_CALL(ptiViewEnable(PTI_VIEW_DEVICE_SYNCHRONIZATION)); + case ActivityType::EXTERNAL_CORRELATION: + externalCorrelationEnabled_ = true; break; case ActivityType::COLLECTIVE_COMM: warnIfIttNotifyLibInvalid(); - XPUPTI_CALL(ptiViewEnable(PTI_VIEW_COMMUNICATION)); break; default: @@ -265,45 +270,8 @@ void XpuptiActivityApi::enableXpuptiActivities( void XpuptiActivityApi::disablePtiActivities( const ActivityTypeMask& selected_activities) { selected_activities.forEach([](ActivityType activity) { - switch (activity) { - case ActivityType::GPU_MEMCPY: - XPUPTI_CALL(ptiViewDisable(PTI_VIEW_DEVICE_GPU_MEM_COPY)); - break; - - case ActivityType::GPU_MEMSET: - XPUPTI_CALL(ptiViewDisable(PTI_VIEW_DEVICE_GPU_MEM_FILL)); - break; - - case ActivityType::CONCURRENT_KERNEL: - XPUPTI_CALL(ptiViewDisable(PTI_VIEW_DEVICE_GPU_KERNEL)); - break; - - case ActivityType::EXTERNAL_CORRELATION: - XPUPTI_CALL(ptiViewDisable(PTI_VIEW_EXTERNAL_CORRELATION)); - break; - - case ActivityType::XPU_RUNTIME: - XPUPTI_CALL(ptiViewDisable(PTI_VIEW_RUNTIME_API)); - break; - - case ActivityType::XPU_DRIVER: - XPUPTI_CALL(ptiViewDisable(PTI_VIEW_DRIVER_API)); - break; - - case ActivityType::OVERHEAD: - XPUPTI_CALL(ptiViewDisable(PTI_VIEW_COLLECTION_OVERHEAD)); - break; - - case ActivityType::XPU_SYNC: - XPUPTI_CALL(ptiViewDisable(PTI_VIEW_DEVICE_SYNCHRONIZATION)); - break; - - case ActivityType::COLLECTIVE_COMM: - XPUPTI_CALL(ptiViewDisable(PTI_VIEW_COMMUNICATION)); - break; - - default: - break; + if (const auto view = findPtiViewKind(activity)) { + XPUPTI_CALL(ptiViewDisable(*view)); } }); externalCorrelationEnabled_ = false;