Skip to content

Commit

Permalink
Noc Analyzer Prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesousa-TT committed Oct 16, 2024
1 parent 998c81a commit 3736a5f
Show file tree
Hide file tree
Showing 6 changed files with 616 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(ttmlir-opt)
add_subdirectory(ttmlir-translate)
add_subdirectory(ttmlir-noc-analyzer)
16 changes: 16 additions & 0 deletions tools/ttmlir-noc-analyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
find_package(jsoncpp REQUIRED)
set(LIBS ${dialect_libs} ${conversion_libs} MLIROptLib MLIRTargetCpp TTMLIRStatic jsoncpp_lib)

set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ttmlir-noc-analyzer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/noc-analytical-model.cpp)
set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/noc-analytical-model.hpp)

add_executable(ttmlir-noc-analyzer ${HEADERS} ${SOURCES})

llvm_update_compile_flags(ttmlir-noc-analyzer)
target_link_libraries(ttmlir-noc-analyzer PRIVATE ${LIBS})

mlir_check_all_link_libraries(ttmlir-noc-analyzer)

install(TARGETS ttmlir-noc-analyzer DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Test EXCLUDE_FROM_ALL)
75 changes: 75 additions & 0 deletions tools/ttmlir-noc-analyzer/noc-analytical-model.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "noc-analytical-model.hpp"

namespace analyzer::model {
// Returns (total_issue_latency (no overhead), round_trip_latency, flit_latency)
std::tuple<float, float, float>
get_read_latency(std::map<std::string, int> noc_params, int buffer_size) {
int transfer_size = buffer_size <= NOC_MAX_BURST_SIZE ? buffer_size : NOC_MAX_BURST_SIZE;
// float num_flits_per_transfer = transfer_size /
// noc_params["noc_data_width"];
float num_transfer = buffer_size / transfer_size;
int round_trip_latency = noc_params["round_trip_latency"];
float issue_latency =
noc_params["niu_programming"] + noc_params["non_niu_programming"];

float total_issue_latency = issue_latency * num_transfer;
float total_flit_latency =
noc_params["head_flit_latency"] + noc_params["flit_latency"] * buffer_size / noc_params["noc_data_width"];

// float barrier_latency;
// if (num_flits_per_transfer >= issue_latency) {
// barrier_latency =
// noc_params["pre_issue_overhead"] + issue_latency + round_trip_latency +
// noc_params["head_flit_latency"] +
// noc_params["flit_latency"] * num_flits_per_transfer * num_transfer -
// total_issue_latency;
// } else {
// barrier_latency = round_trip_latency + noc_params["head_flit_latency"] +
// noc_params["flit_latency"] * num_flits_per_transfer;
// }

return std::tuple<float, float, float>{total_issue_latency, round_trip_latency,
total_flit_latency};
}

std::tuple<float, float, float>
get_write_latency(std::map<std::string, int> noc_params, int buffer_size) {
auto transfer_size = buffer_size <= NOC_MAX_BURST_SIZE ? buffer_size : NOC_MAX_BURST_SIZE;
float num_flits_per_transfer = transfer_size / noc_params["noc_data_width"];
float num_transfer = buffer_size / transfer_size;
int round_trip_latency = noc_params["round_trip_latency"];

float issue_latency =
noc_params["niu_programming"] + noc_params["non_niu_programming"];

float total_flit_latency =
noc_params["flit_latency"] * buffer_size / noc_params["noc_data_width"];

float total_issue_latency;
float barrier_latency;

if (num_flits_per_transfer >= issue_latency) {
if (num_transfer < 3) {
total_issue_latency = issue_latency * num_transfer;
} else {
total_issue_latency = issue_latency +
noc_params["flit_latency"] *
num_flits_per_transfer * (num_transfer - 2) +
15;
}
barrier_latency =
issue_latency + round_trip_latency + noc_params["head_flit_latency"] +
noc_params["flit_latency"] * num_flits_per_transfer * num_transfer -
total_issue_latency;
} else {
total_issue_latency =
noc_params["pre_issue_overhead"] + issue_latency * num_transfer;
barrier_latency = noc_params["round_trip_latency"] +
noc_params["head_flit_latency"] +
noc_params["flit_latency"] * num_flits_per_transfer;
}

return std::tuple<float, float, float>{total_issue_latency, barrier_latency,
total_flit_latency};
}
} // namespace analyzer::model
19 changes: 19 additions & 0 deletions tools/ttmlir-noc-analyzer/noc-analytical-model.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <string>
#include <map>

#define NOC_MAX_BURST_SIZE 8192

namespace analyzer::model {

const std::map<std::string, int> noc_params = {
{"pre_issue_overhead", 17},
{"niu_programming", 6},
{"non_niu_programming", 43},
{"round_trip_latency", 96},
{"head_flit_latency", 1},
{"flit_latency", 1},
{"noc_data_width", 32}};

std::tuple<float, float, float> get_read_latency(std::map<std::string, int> noc_params, int buffer_size);
std::tuple<float, float, float> get_write_latency(std::map<std::string, int> noc_params, int buffer_size);
}
191 changes: 191 additions & 0 deletions tools/ttmlir-noc-analyzer/timeline_visualizer.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 3736a5f

Please sign in to comment.