Skip to content

Commit

Permalink
Merge branch 'main' into zejun/add_unified_runtime_op_for_flow_in_jso…
Browse files Browse the repository at this point in the history
…n_trace_file
  • Loading branch information
zejun-chen authored Jan 10, 2025
2 parents 6ff5f1b + 7ae1ce8 commit 539879c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
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 {
XPU_RUNTIME, // host side xpu runtime events
COLLECTIVE_COMM, // collective communication
MTIA_WORKLOADD, // MTIA workloadd events
MTIA_COLLECTIVE_COMM, // MTIA collective communication events

// PRIVATEUSE1 Activity types are used for custom backends.
// The corresponding device type is `DeviceType::PrivateUse1` in PyTorch.
Expand Down
1 change: 1 addition & 0 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{
{"xpu_runtime", ActivityType::XPU_RUNTIME},
{"collective_comm", ActivityType::COLLECTIVE_COMM},
{"mtia_workloadd", ActivityType::MTIA_WORKLOADD},
{"mtia_collective_comm", ActivityType::MTIA_COLLECTIVE_COMM},
{"privateuse1_runtime", ActivityType::PRIVATEUSE1_RUNTIME},
{"privateuse1_driver", ActivityType::PRIVATEUSE1_DRIVER},
{"ENUM_COUNT", ActivityType::ENUM_COUNT}}};
Expand Down
12 changes: 12 additions & 0 deletions libkineto/src/output_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ void ChromeTraceLogger::sanitizeStrForJSON(std::string& value) {
value.erase(std::remove(value.begin(), value.end(), '\n'), value.end());
}

static void sanitizeForNonReadableChars(std::string& value) {
for (auto& c : value) {
if (!std::isprint(c)) {
LOG(WARNING) << "Non JSON compliant character found in string: " << value
<< " Replacing with 'unknown'";
value = "unknown";
break;
}
}
}

static inline int32_t sanitizeTid(int32_t tid) {
// Convert all negative tids to its positive value. Create a specific case
// for INT_MIN so it is obvious how it is being handled.
Expand Down Expand Up @@ -521,6 +532,7 @@ void ChromeTraceLogger::handleActivity(const libkineto::ITraceActivity& op) {
// TODO: Remove this once legacy tools are updated.
std::string op_name = op.name() == "kernel" ? "Kernel" : op.name();
sanitizeStrForJSON(op_name);
sanitizeForNonReadableChars(op_name);

// clang-format off
ts = transToRelativeTime(ts);
Expand Down

0 comments on commit 539879c

Please sign in to comment.