Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
52c714a
scope profiler squashed
moksiuc Oct 31, 2025
0cbe479
Type fix
moksiuc Nov 13, 2025
7c98f84
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Nov 17, 2025
8438227
Fixes
moksiuc Nov 17, 2025
fd2a6e1
Code review fixes
moksiuc Nov 18, 2025
88082d5
Fix clang build on PT level
moksiuc Nov 18, 2025
04f305c
Fix clang build on PT level 2nd approach
moksiuc Nov 18, 2025
dbc709f
lintrunner
moksiuc Nov 19, 2025
ad4b1dd
Improve json for presentation in perfetto
moksiuc Nov 20, 2025
e050a30
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Nov 21, 2025
37eafea
Fix gtest after json update
moksiuc Nov 21, 2025
a266b04
Put correct oneapi version in error msg
moksiuc Nov 21, 2025
4a70122
Fix correct PTI and OneApi version
moksiuc Nov 24, 2025
535b19e
lint
sraikund16 Dec 15, 2025
b639a8c
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Dec 17, 2025
e85fd26
Fix merge error
moksiuc Dec 17, 2025
115ae6c
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Dec 18, 2025
02b8684
Move device gathering to enableScopeProfiler
moksiuc Dec 18, 2025
371c860
lint
sraikund16 Dec 16, 2025
9e3f9fd
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Dec 19, 2025
0d46ae9
Resolve exception from desctuctor
moksiuc Dec 19, 2025
906085b
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Dec 22, 2025
898ce26
Fix Win build: error C2039: 'back_inserter': is not a member of 'std'
moksiuc Dec 22, 2025
a014058
Update min PTI version error msg
moksiuc Dec 23, 2025
3fe5339
Remove unnecesary includes
moksiuc Dec 23, 2025
75cd8f4
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Jan 15, 2026
b2c9521
Avoid adding getMetadata method to the interface
moksiuc Jan 15, 2026
d5c79dd
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Jan 20, 2026
0ebfe7b
Split classes to avoid excessive #ifdef macro usage
moksiuc Jan 16, 2026
aeec1ca
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Feb 2, 2026
2bfb1c0
resolve merge commit issues
moksiuc Feb 2, 2026
703ce04
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Feb 3, 2026
830cc33
Fix win build
moksiuc Feb 3, 2026
1b1a031
Fix win build
moksiuc Feb 3, 2026
d04260a
Revert conflicting files
moksiuc Feb 13, 2026
156a7a7
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Feb 13, 2026
6be856a
Rename files 0->V2, V1->0
moksiuc Feb 13, 2026
d519f89
Rename 0->V2, V1->0 inside files
moksiuc Feb 13, 2026
05330ab
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Feb 27, 2026
613de06
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 3, 2026
332c15a
Resolve merge conflict
moksiuc Mar 3, 2026
35aeeb0
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 6, 2026
2748bcc
Apply review comments
moksiuc Mar 6, 2026
52bb30a
unformat
moksiuc Mar 6, 2026
749ede2
Revert "unformat"
moksiuc Mar 9, 2026
8af4584
Apply review comments - SELECT_VERSION macro
moksiuc Mar 9, 2026
7b7bea9
unformat
moksiuc Mar 6, 2026
acda410
Revert "unformat"
moksiuc Mar 10, 2026
48a1ea9
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 10, 2026
fa11b87
No ApiT type alias
moksiuc Mar 10, 2026
71d22cd
unformat
moksiuc Mar 10, 2026
d7b330f
unfix compilation errors
moksiuc Mar 10, 2026
493b565
Revert "unfix compilation errors"
moksiuc Mar 11, 2026
a139c29
Revert "unformat"
moksiuc Mar 11, 2026
910eb4c
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 11, 2026
2bfab82
Apply review comments
moksiuc Mar 11, 2026
e2b0bf7
Reapply "unformat"
moksiuc Mar 11, 2026
86d3759
Reapply "unfix compilation errors"
moksiuc Mar 11, 2026
446f253
Revert "unfix compilation errors"
moksiuc Mar 13, 2026
da9b441
Revert "unformat"
moksiuc Mar 13, 2026
4c850e7
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 13, 2026
827141d
Clean up Api singleton usage
moksiuc Mar 13, 2026
f420f82
Reapply "unformat"
moksiuc Mar 13, 2026
fcd3223
Reapply "unfix compilation errors"
moksiuc Mar 13, 2026
3ae459c
Revert "unfix compilation errors"
moksiuc Mar 16, 2026
6e0717a
Revert "unformat"
moksiuc Mar 16, 2026
c271025
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 16, 2026
ee0a469
Separate Api and ApiV2 classes and their singletons
moksiuc Mar 16, 2026
1f195d4
Reapply "unformat"
moksiuc Mar 16, 2026
c2f9aed
Reapply "unfix compilation errors"
moksiuc Mar 16, 2026
4483c75
Revert "Reapply "unfix compilation errors""
moksiuc Mar 18, 2026
dc6c1f0
Revert "Reapply "unformat""
moksiuc Mar 18, 2026
9923983
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 18, 2026
b76c500
Rename XpuptiActivityApiV2 to XpuptiScopeProfilerApi
moksiuc Mar 18, 2026
d38f49f
Reapply "unformat"
moksiuc Mar 18, 2026
481ea86
Reapply "unfix compilation errors"
moksiuc Mar 18, 2026
1e02e75
Revert "unfix compilation errors"
moksiuc Mar 18, 2026
267b4c0
Revert "unformat"
moksiuc Mar 18, 2026
fc4417b
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 18, 2026
eb6495a
Fix merge conflict
moksiuc Mar 18, 2026
75cdaa0
Reapply "unformat"
moksiuc Mar 18, 2026
d2d99de
Reapply "unfix compilation errors"
moksiuc Mar 18, 2026
2b8f065
Revert "unfix compilation errors"
moksiuc Mar 19, 2026
f87ef7a
Revert "unformat"
moksiuc Mar 19, 2026
99494fe
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 19, 2026
6ce6652
Reapply "unformat"
moksiuc Mar 19, 2026
f55b81c
Revert "unformat"
moksiuc Mar 20, 2026
6c996e6
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 20, 2026
96dc87e
Make ApiV2 a member of SessionV2 instead singleton
moksiuc Mar 20, 2026
4943d72
Reapply "unformat"
moksiuc Mar 20, 2026
2a594f0
Revert "unformat"
moksiuc Mar 24, 2026
7291dd7
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 24, 2026
379d077
format
moksiuc Mar 24, 2026
2fe719a
Reapply "unformat"
moksiuc Mar 24, 2026
60751c0
Revert "unformat"
moksiuc Mar 27, 2026
82f2c9d
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 27, 2026
d4bdc85
address review comments
moksiuc Mar 27, 2026
bda80d4
Reapply "unformat"
moksiuc Mar 27, 2026
8d9b899
Revert "unformat"
moksiuc Mar 30, 2026
400805c
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Mar 30, 2026
a312ef6
Rename V2 -> Scope according to review comments
moksiuc Mar 30, 2026
d0a82c1
Reapply "unformat"
moksiuc Mar 30, 2026
5230042
Revert "Reapply "unformat""
moksiuc Apr 9, 2026
dfbd801
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Apr 9, 2026
ef7102f
Align to new kineto code in output_json.cpp
moksiuc Apr 9, 2026
f329732
Reapply "unformat"
moksiuc Apr 9, 2026
3b2cb5a
Revert "unformat"
moksiuc Apr 16, 2026
c27b580
Merge branch 'refs/heads/main' into moksiuci_6674_scope_profiler
moksiuc Apr 16, 2026
840675e
Reapply "unformat"
moksiuc Apr 16, 2026
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
7 changes: 7 additions & 0 deletions libkineto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ if(NOT LIBKINETO_NOCUPTI)
endif()
if(DEFINED LIBKINETO_NOXPUPTI AND NOT LIBKINETO_NOXPUPTI)
list(APPEND KINETO_COMPILE_OPTIONS ${XPUPTI_BUILD_FLAG})
if(KINETO_BUILD_TESTS)
set_target_properties(kineto_base PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(kineto_api PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
endif()
if (DEFINED LIBKINETO_NOAIUPTI AND NOT LIBKINETO_NOAIUPTI)
list(APPEND KINETO_COMPILE_OPTIONS ${AIUPTI_BUILD_FLAGS})
Expand Down Expand Up @@ -258,6 +262,9 @@ if(KINETO_BUILD_TESTS)
set(BUILD_SHARED_LIBS OFF)
add_subdirectory("${LIBKINETO_THIRDPARTY_DIR}/googletest")
set(BUILD_SHARED_LIBS "${TMP_BUILD_SHARED_LIBS}")
if(DEFINED LIBKINETO_NOXPUPTI AND NOT LIBKINETO_NOXPUPTI)
set_property(TARGET gtest PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
endif()
enable_testing()
add_subdirectory(test)
Expand Down
1 change: 1 addition & 0 deletions libkineto/include/ActivityType.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum class ActivityType {
CUDA_PROFILER_RANGE, // CUPTI Profiler range for performance metrics
HPU_OP, // HPU host side runtime event
XPU_RUNTIME, // host side xpu runtime events
XPU_SCOPE_PROFILER, // XPUPTI Profiler scope for performance metrics
COLLECTIVE_COMM, // collective communication

// PRIVATEUSE1 Activity types are used for custom backends.
Expand Down
9 changes: 9 additions & 0 deletions libkineto/include/GenericTraceActivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ class GenericTraceActivity : public ITraceActivity {
return json.str();
}

const std::vector<std::pair<std::string, std::string>> getMetadata()
const override {
std::vector<std::pair<std::string, std::string>> result;
for (const auto& [key, val] : metadataMap_) {
result.emplace_back(key, val.first);
}
return result;
}

virtual ~GenericTraceActivity() override {}

int64_t startTime{0};
Expand Down
4 changes: 4 additions & 0 deletions libkineto/include/ITraceActivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ struct ITraceActivity {
virtual const std::string getMetadataValue(const std::string& key) const {
return "";
}
virtual const std::vector<std::pair<std::string, std::string>> getMetadata()
const {
return {};
}
Comment thread
moksiuc marked this conversation as resolved.
Outdated

static int64_t nsToUs(int64_t ns) {
// It's important that this conversion is the same everywhere.
Expand Down
1 change: 1 addition & 0 deletions libkineto/libkineto_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def get_libkineto_xpupti_srcs(with_api = True):
"src/plugin/xpupti/XpuptiActivityApi.cpp",
"src/plugin/xpupti/XpuptiActivityProfiler.cpp",
"src/plugin/xpupti/XpuptiActivityHandlers.cpp",
"src/plugin/xpupti/XpuptiScopeProfilerConfig.cpp",
] + (get_libkineto_cpu_only_srcs(with_api))

def get_libkineto_aiupti_srcs(with_api = True):
Expand Down
4 changes: 2 additions & 2 deletions libkineto/src/ActivityType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static constexpr std::array<ActivityTypeName, activityTypeCount + 1> map{
{"cuda_profiler_range", ActivityType::CUDA_PROFILER_RANGE},
{"hpu_op", ActivityType::HPU_OP},
{"xpu_runtime", ActivityType::XPU_RUNTIME},
{"xpu_scope_profiler", ActivityType::XPU_SCOPE_PROFILER},
{"collective_comm", ActivityType::COLLECTIVE_COMM},
{"privateuse1_runtime", ActivityType::PRIVATEUSE1_RUNTIME},
{"privateuse1_driver", ActivityType::PRIVATEUSE1_DRIVER},
Expand Down Expand Up @@ -71,8 +72,7 @@ const std::array<ActivityType, activityTypeCount> activityTypes() {
return res;
}

const std::array<ActivityType, defaultActivityTypeCount>
defaultActivityTypes() {
const std::array<ActivityType, defaultActivityTypeCount> defaultActivityTypes() {
std::array<ActivityType, defaultActivityTypeCount> res;
for (int i = 0; i < defaultActivityTypeCount; i++) {
res[i] = map[i].type;
Expand Down
5 changes: 4 additions & 1 deletion libkineto/src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#ifdef HAS_XPUPTI
#include "plugin/xpupti/XpuptiActivityApi.h"
#include "plugin/xpupti/XpuptiActivityProfiler.h"
#include "plugin/xpupti/XpuptiScopeProfilerConfig.h"
#endif
#ifdef HAS_AIUPTI
#include "plugin/aiupti/AiuptiActivityApi.h"
Expand Down Expand Up @@ -176,6 +177,8 @@ void libkineto_init(bool cpuOnly, bool logOnError) {
std::make_unique<ActivityProfilerProxy>(cpuOnly, config_loader));

#ifdef HAS_XPUPTI
XpuptiScopeProfilerConfig::registerFactory();

// register xpu pti profiler
libkineto::api().registerProfilerFactory(
[]() -> std::unique_ptr<IActivityProfiler> {
Expand All @@ -184,7 +187,7 @@ void libkineto_init(bool cpuOnly, bool logOnError) {
std::string errPrefixMsg(
"Fail to enable Kineto Profiler on XPU due to error code: ");
errPrefixMsg = errPrefixMsg + std::to_string(returnCode);
#if PTI_VERSION_MAJOR > 0 || PTI_VERSION_MINOR > 9
#if PTI_VERSION_AT_LEAST(0, 10)
std::string errMsg(ptiResultTypeToString(returnCode));
throw std::runtime_error(
errPrefixMsg + std::string(". The detailed error message is: ") +
Expand Down
39 changes: 39 additions & 0 deletions libkineto/src/output_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,45 @@ void ChromeTraceLogger::handleActivity(const libkineto::ITraceActivity& op) {
toString(op.type()), op_name, device, sanitizeTid(resource),
ts/1000, ts %1000, duration/1000, duration %1000, args);
// clang-format on

if (op.type() == ActivityType::XPU_SCOPE_PROFILER) {
constexpr const std::string_view prefix = "metrics: ";
if (std::string_view(op_name).substr(0, prefix.size()) == prefix) {
for (const auto& [key, val] : op.getMetadata()) {
constexpr std::array<std::string_view, 2> keysExcluded = {
"queue", "kernel_id"};
if (std::none_of(
keysExcluded.begin(),
keysExcluded.end(),
[&key](std::string_view keyExcluded) {
return keyExcluded == key;
})) {
auto timePoint = ts + duration / 2;
fmt::print(
traceOf_,
// clang-format off
R"JSON(
{{
"name": "{}",
"cat": "metric",
"ph": "C",
"ts": {}.{:03},
"pid": {},
"tid": {},
"args": {{ "value": {} }}
}},)JSON",
// clang-format on
key,
timePoint / 1000,
timePoint % 1000,
device,
sanitizeTid(resource),
val);
}
}
}
}

if (op.flowId() > 0) {
handleGenericLink(op);
}
Expand Down
4 changes: 2 additions & 2 deletions libkineto/src/plugin/xpupti/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ if(TARGET Pti::pti_view)
foreach(ver_major RANGE 0 1)
foreach(ver_minor RANGE 0 19)
list(APPEND pti_view_names pti_view-${ver_major}-${ver_minor})
endforeach()
endforeach()
endforeach()
endforeach()

get_target_property(PTI_INCLUDE_DIR Pti::pti_view INTERFACE_INCLUDE_DIRECTORIES)
find_library(PTI_VIEW_LIBRARY NAMES ${pti_view_names} PATHS "${PTI_INCLUDE_DIR}/../lib")
Expand Down
1 change: 0 additions & 1 deletion libkineto/src/plugin/xpupti/FindSYCLToolkit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,5 @@ if((NOT SYCL_INCLUDE_DIR) OR (NOT SYCL_LIBRARY_DIR) OR (NOT SYCL_LIBRARY))
endif()

message(DEBUG "The SYCL compiler is ${SYCL_COMPILER}")
message(DEBUG "The SYCL Flags are ${SYCL_FLAGS}")
Comment thread
moksiuc marked this conversation as resolved.
Outdated

set(SYCLTOOLKIT_FOUND True)
Loading