-
Notifications
You must be signed in to change notification settings - Fork 251
Add XCCL collective communication activity tracing to XPU plugin #1396
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
Open
tsocha
wants to merge
3
commits into
pytorch:main
Choose a base branch
from
intel-staging:dev/tsocha/oneccl-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * 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/XpuptiActivityApi.h" | ||
| #include "src/plugin/xpupti/XpuptiActivityProfilerSession.h" | ||
| #include "src/ActivityBuffers.h" | ||
| #include "include/output_base.h" | ||
|
|
||
| #include "src/plugin/xpupti/XpuptiProfilerMacros.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| namespace KN = KINETO_NAMESPACE; | ||
| using namespace libkineto; | ||
|
|
||
| // Mock XpuptiActivityApi that delivers hand-crafted PTI records | ||
| // through the virtual processActivities without needing PTI runtime. | ||
| class MockXpuptiActivityApi : public KN::XpuptiActivityApi { | ||
| public: | ||
| std::vector<const pti_view_record_base*> records; | ||
|
|
||
| std::unique_ptr<KN::XpuptiActivityBufferMap> activityBuffers() override { | ||
| // Return a non-null map so processTrace enters the processing path. | ||
| return std::make_unique<KN::XpuptiActivityBufferMap>(); | ||
| } | ||
|
|
||
| const std::pair<int, int> processActivities( | ||
| KN::XpuptiActivityBufferMap&, | ||
| std::function<void(const pti_view_record_base*)> handler) override { | ||
| for (auto* record : records) { | ||
| handler(record); | ||
| } | ||
| return {static_cast<int>(records.size()), 0}; | ||
| } | ||
| }; | ||
|
|
||
| // Minimal ActivityLogger that captures logged GenericTraceActivity objects. | ||
| class MockActivityLogger : public ActivityLogger { | ||
| public: | ||
| std::vector<const GenericTraceActivity*> logged_activities; | ||
|
|
||
| void handleDeviceInfo(const DeviceInfo&, uint64_t) override {} | ||
| void handleResourceInfo(const ResourceInfo&, int64_t) override {} | ||
| void handleOverheadInfo(const OverheadInfo&, int64_t) override {} | ||
| void handleTraceSpan(const TraceSpan&) override {} | ||
|
|
||
| void handleActivity(const ITraceActivity&) override {} | ||
|
|
||
| void handleGenericActivity(const GenericTraceActivity& activity) override { | ||
| logged_activities.push_back(&activity); | ||
| } | ||
|
|
||
| void handleTraceStart( | ||
| const std::unordered_map<std::string, std::string>&, | ||
| const std::string&) override {} | ||
|
|
||
| void finalizeMemoryTrace(const std::string&, const Config&) override {} | ||
|
|
||
| void finalizeTrace( | ||
| const Config&, | ||
| std::unique_ptr<KINETO_NAMESPACE::ActivityBuffers>, | ||
| int64_t, | ||
| std::unordered_map<std::string, std::vector<std::string>>&) override {} | ||
| }; | ||
|
|
||
| class XpuptiActivityHandlersTest : public ::testing::Test { | ||
| protected: | ||
| MockXpuptiActivityApi mockApi_; | ||
| MockActivityLogger logger_; | ||
|
|
||
| // Processes all records in mockApi_ through the handler pipeline | ||
| // and returns the resulting trace buffer. | ||
| std::unique_ptr<CpuTraceBuffer> processAndGetTrace( | ||
| int64_t windowStart = 0, | ||
| int64_t windowEnd = 1000) { | ||
| Config config; | ||
| std::set<ActivityType> activity_types = {ActivityType::COLLECTIVE_COMM, ActivityType::XPU_SYNC}; | ||
| auto session = std::make_unique<KN::XpuptiActivityProfilerSession>( | ||
| mockApi_, "__test_profiler__", config, activity_types); | ||
| session->processTrace( | ||
| logger_, | ||
| [](int64_t) -> const ITraceActivity* { return nullptr; }, | ||
| windowStart, | ||
| windowEnd); | ||
| return session->getTraceBuffer(); | ||
| } | ||
| }; | ||
|
|
||
| // --- Communication Activity Tests --- | ||
|
|
||
| #if PTI_VERSION_AT_LEAST(0, 17) | ||
| TEST_F(XpuptiActivityHandlersTest, CommunicationActivityHasXcclPrefix) { | ||
| pti_view_record_comms comms_record{}; | ||
| comms_record._view_kind._view_kind = PTI_VIEW_COMMUNICATION; | ||
| comms_record._name = "allreduce"; | ||
| comms_record._start_timestamp = 100; | ||
| comms_record._end_timestamp = 200; | ||
| comms_record._process_id = 1; | ||
| comms_record._thread_id = 42; | ||
| comms_record._communicator_id = 7; | ||
|
|
||
| mockApi_.records.push_back( | ||
| reinterpret_cast<const pti_view_record_base*>(&comms_record)); | ||
|
|
||
| auto traceBuffer = processAndGetTrace(); | ||
| ASSERT_EQ(traceBuffer->activities.size(), 1); | ||
|
|
||
| auto& activity = *traceBuffer->activities[0]; | ||
| EXPECT_EQ(activity.name(), "xccl::allreduce"); | ||
| EXPECT_EQ(activity.type(), ActivityType::COLLECTIVE_COMM); | ||
| } | ||
|
|
||
| TEST_F(XpuptiActivityHandlersTest, CommunicationActivityFields) { | ||
| pti_view_record_comms comms_record{}; | ||
| comms_record._view_kind._view_kind = PTI_VIEW_COMMUNICATION; | ||
| comms_record._name = "broadcast"; | ||
| comms_record._start_timestamp = 300; | ||
| comms_record._end_timestamp = 500; | ||
| comms_record._process_id = 10; | ||
| comms_record._thread_id = 77; | ||
| comms_record._communicator_id = 99; | ||
|
|
||
| mockApi_.records.push_back( | ||
| reinterpret_cast<const pti_view_record_base*>(&comms_record)); | ||
|
|
||
| auto traceBuffer = processAndGetTrace(); | ||
| ASSERT_EQ(traceBuffer->activities.size(), 1); | ||
|
|
||
| auto& activity = *traceBuffer->activities[0]; | ||
| EXPECT_EQ(activity.timestamp(), 300); | ||
| EXPECT_EQ(activity.duration(), 200); | ||
| EXPECT_EQ(activity.deviceId(), 10); | ||
| EXPECT_EQ(activity.resourceId(), 77); | ||
| EXPECT_EQ(activity.getThreadId(), 77); | ||
| EXPECT_EQ(activity.getMetadataValue("Communicator_id"), "99"); | ||
| } | ||
|
|
||
| TEST_F(XpuptiActivityHandlersTest, CommunicationActivityOutOfRange) { | ||
| pti_view_record_comms comms_record{}; | ||
| comms_record._view_kind._view_kind = PTI_VIEW_COMMUNICATION; | ||
| comms_record._name = "allgather"; | ||
| comms_record._start_timestamp = 2000; | ||
| comms_record._end_timestamp = 3000; | ||
| comms_record._process_id = 1; | ||
| comms_record._thread_id = 1; | ||
| comms_record._communicator_id = 1; | ||
|
|
||
| mockApi_.records.push_back( | ||
| reinterpret_cast<const pti_view_record_base*>(&comms_record)); | ||
|
|
||
| auto traceBuffer = processAndGetTrace(100, 500); | ||
| EXPECT_EQ(traceBuffer->activities.size(), 0); | ||
| } | ||
| #endif // PTI_VERSION_AT_LEAST(0, 17) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be in the general instructions? Is this something that's covered in Intel's other docs? I'd like to keep this file short and general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This env variable is required by ITT which is used by PTI to collect these events.
Without this variable user won't see oneCCL events in his trace.
I wanted to expose this information to avoid confusion of the Kineto user.
We are working to remove this requirement in the future but due to performance requirements of PTI integration it's not ready yet.
I could create a new README file inside
xpuptiplugin directory but I'm afraid that it will be hidden.What do you think?