Skip to content

Commit

Permalink
unconditionally compile opname mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrady-tt committed Mar 4, 2025
1 parent e56eda8 commit bd1dd4d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion ttnn/cpp/pybind11/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace py = pybind11;

namespace {
inline void DumpDeviceProfiler(IDevice* device) {
ProfilerOptionalMetadata prof_metadata(tt::tt_metal::op_profiler::getRuntimeToOpnameMap());
ProfilerOptionalMetadata prof_metadata(tt::tt_metal::op_profiler::runtime_id_to_opname.exportMap());
tt::tt_metal::detail::DumpDeviceProfileResults(device, ProfilerDumpState::NORMAL, prof_metadata);
}
} // namespace
Expand Down
49 changes: 24 additions & 25 deletions ttnn/tools/profiler/op_profiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ class thread_safe_call_stack {
std::stack<TracyCZoneCtx> call_stack;
};

inline thread_safe_cached_ops_map cached_ops{};
inline thread_safe_call_stack call_stack;

template <typename device_operation_t>
inline auto compute_program_hash(
const typename device_operation_t::operation_attributes_t& operation_attributes,
const typename device_operation_t::tensor_args_t& tensor_args) {
if constexpr (requires(
const typename device_operation_t::operation_attributes_t& operation_attributes,
const typename device_operation_t::tensor_args_t& tensor_args) {
{
device_operation_t::compute_program_hash(operation_attributes, tensor_args)
} -> std::convertible_to<tt::stl::hash::hash_t>;
}) {
ZoneScopedN("Op profiler Compute custom program hash");
return device_operation_t::compute_program_hash(operation_attributes, tensor_args);
} else {
ZoneScopedN("Op profiler Compute default program hash");
return tt::stl::hash::hash_objects_with_default_seed(
tt::stl::hash::type_hash<device_operation_t>, operation_attributes, tensor_args);
}
}
#endif

class thread_safe_runtime_id_to_ops_map {
using DEVICE_ID = uint32_t;
using RUNTIME_ID = uint32_t;
Expand Down Expand Up @@ -123,31 +147,6 @@ class thread_safe_runtime_id_to_ops_map {
};

inline thread_safe_runtime_id_to_ops_map runtime_id_to_opname{};
inline thread_safe_cached_ops_map cached_ops{};
inline thread_safe_call_stack call_stack;

static auto getRuntimeToOpnameMap() { return runtime_id_to_opname.exportMap(); }

template <typename device_operation_t>
inline auto compute_program_hash(
const typename device_operation_t::operation_attributes_t& operation_attributes,
const typename device_operation_t::tensor_args_t& tensor_args) {
if constexpr (requires(
const typename device_operation_t::operation_attributes_t& operation_attributes,
const typename device_operation_t::tensor_args_t& tensor_args) {
{
device_operation_t::compute_program_hash(operation_attributes, tensor_args)
} -> std::convertible_to<tt::stl::hash::hash_t>;
}) {
ZoneScopedN("Op profiler Compute custom program hash");
return device_operation_t::compute_program_hash(operation_attributes, tensor_args);
} else {
ZoneScopedN("Op profiler Compute default program hash");
return tt::stl::hash::hash_objects_with_default_seed(
tt::stl::hash::type_hash<device_operation_t>, operation_attributes, tensor_args);
}
}
#endif

static void start_tracy_zone(const string& source, const string& functName, uint32_t lineNum, uint32_t color = 0) {
#if defined(TRACY_ENABLE)
Expand Down

0 comments on commit bd1dd4d

Please sign in to comment.