1#ifndef __GRAPH_UTILS_H__
2#define __GRAPH_UTILS_H__
7#define TILE_BYTES 32768
8#define MAX_PARAM_BYTES 16384
9#define MAX_FLOAT_PARAMS MAX_PARAM_BYTES / sizeof(float)
12#define PLIO64_ARG(TXT_PATH) adf::plio_64_bits
14#define PLIO64_ARG(TXT_PATH) adf::plio_64_bits, TXT_PATH
17#define adfCheck(stmt, log_name) \
19 adf::return_code ret = stmt; \
21 printf("ERROR [%s]: failed\n", log_name); \
26void get_graph_throughput_by_port(
28 const std::string& log_name,
29 adf::IoAttr& plio_port,
30 const size_t window_len,
31 const size_t sample_bytesize,
34 adf::event::handle ehdl = adf::event::start_profiling(plio_port, adf::event::io_stream_start_to_bytes_transferred_cycles, window_len * iter_cnt * sample_bytesize);
36 adfCheck(graph.run(iter_cnt),
"run graph");
37 adfCheck(graph.wait(),
"wait graph");
39 if (ehdl != adf::event::invalid_handle) {
40 long long cycles = adf::event::read_profiling(ehdl);
41 adf::event::stop_profiling(ehdl);
42 printf(
"%s: Cycles %lld Throughput %f samples/s\n", log_name.c_str(), cycles, (
double) window_len * iter_cnt / (cycles * 1e-9));
44 printf(
"%s: ERROR: Invalid handle. Only two performance counter in a AIE-PL interface tile. Event profile is not supported for x86sim.\n", log_name.c_str());
49void get_graph_latency(
51 const std::string& log_name,
52 adf::IoAttr& plio_input_port,
53 adf::IoAttr& plio_output_port,
56 adf::event::handle ehdl = adf::event::start_profiling(plio_input_port, plio_output_port, adf::event::io_stream_start_difference_cycles);
58 adfCheck(graph.run(iter_cnt),
"run graph");
59 adfCheck(graph.wait(),
"wait graph");
61 if (ehdl != adf::event::invalid_handle) {
62 long long cycles = adf::event::read_profiling(ehdl);
63 adf::event::stop_profiling(ehdl);
64 printf(
"[%s]: AIE Latency: %lld cycles, %fs (@1Ghz)\n", log_name.c_str(), cycles, (
double) cycles * 1e-9);
66 printf(
"%s: ERROR: Invalid handle. Only two performance counter in a AIE-PL interface tile. Event profile is not supported for x86sim.\n", log_name.c_str());
71void get_graph_bandwidth_by_port(
73 const std::string& log_name,
74 adf::IoAttr& plio_input_port,
75 adf::IoAttr& plio_output_port,
76 const size_t input_window_len,
77 const size_t output_window_len,
80 adf::event::handle in_ehdl = adf::event::start_profiling(plio_input_port, adf::event::io_total_stream_running_to_idle_cycles);
81 adf::event::handle out_ehdl = adf::event::start_profiling(plio_output_port, adf::event::io_total_stream_running_to_idle_cycles);
83 adfCheck(graph.run(iter_cnt),
"run graph");
84 adfCheck(graph.wait(),
"wait graph");
87 if (in_ehdl != adf::event::invalid_handle) {
88 cycles = adf::event::read_profiling(in_ehdl);
89 adf::event::stop_profiling(in_ehdl);
90 printf(
"%s: Cycles %lld Bandwidth %f, ==1: graph faster than PLIO, < 1: input port stalled\n", log_name.c_str(), cycles, (
double) input_window_len * iter_cnt / cycles);
92 printf(
"%s: ERROR: Invalid handle. Only two performance counter in a AIE-PL interface tile. Event profile is not supported for x86sim.\n", log_name.c_str());
95 if (out_ehdl != adf::event::invalid_handle) {
96 cycles = adf::event::read_profiling(out_ehdl);
97 adf::event::stop_profiling(out_ehdl);
98 printf(
"%s: Cycles %lld Bandwidth %f, ==1: graph faster than PLIO, < 1: output port stalled\n", log_name.c_str(), cycles, (
double) output_window_len * iter_cnt / cycles);
100 printf(
"%s: ERROR: Invalid handle. Only two performance counter in a AIE-PL interface tile. Event profile is not supported for x86sim.\n", log_name.c_str());