Skip to content

Commit

Permalink
#0: start and stop times for op-profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
muthutt committed Dec 7, 2023
1 parent bed7516 commit 9d1d9c2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tt_metal/tools/profiler/op_profiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <filesystem>
#include <type_traits>
#include <chrono>

#include "third_party/magic_enum/magic_enum.hpp"

Expand Down Expand Up @@ -102,7 +103,8 @@ namespace op_profiler {
string name;
Profiler profiler = Profiler();
vector<string> metaDataVector = {};

std::chrono::time_point<std::chrono::steady_clock> start_time; //in seconds
std::chrono::time_point<std::chrono::steady_clock> end_time; //in seconds
int opCallCount;
int globalCallCount;
int stackSize;
Expand All @@ -112,7 +114,7 @@ namespace op_profiler {
vector<string> mathFidelities = {};
string parlStrategy = "";
string preferredName = "";

OpType type;

OpData (string opName, int opCount, int globalCount, int stackSizeArg, OpType typeArg):
Expand All @@ -122,6 +124,11 @@ namespace op_profiler {
stackSize(stackSizeArg),
type(typeArg)
{}

const std::chrono::duration<double> get_runtime() {
const auto diff = end_time - start_time;
return diff;
}
};

class OpProfiler {
Expand Down Expand Up @@ -205,7 +212,8 @@ namespace op_profiler {
additionalFields.push_back({"Preferred Name", opData.preferredName});
additionalFields.push_back({"Meta Data", join_vector(opData.metaDataVector)});
additionalFields.push_back({"Type", fmt::format("{}",magic_enum::enum_name(opData.type))});

additionalFields.push_back({"Runtime", fmt::format("{}",opData.get_runtime().count)});

return additionalFields;
}

Expand Down Expand Up @@ -258,6 +266,7 @@ namespace op_profiler {

setup_profiling_folders (opNameNoComma, callCount, opData.profiler);
opStack.push(opData);
opData.start_time = std::chrono::steady_clock::now();
#endif
}

Expand All @@ -270,6 +279,7 @@ namespace op_profiler {
TT_ASSERT (opNameNoComma == opData.name, "Something is wrong, op name mismatch");

auto additionalFields = generate_additional_data();
opData.end_time = std::chrono::steady_clock::now();
opData.profiler.markStop(opNameNoComma, additionalFields);
clear_profiler();
#endif
Expand Down

0 comments on commit 9d1d9c2

Please sign in to comment.