Skip to content

Commit

Permalink
Vitis 13612 : Allow for gemm test to wait for the clock ramp up to it…
Browse files Browse the repository at this point in the history
…s maximum value (#8538)

* VITIS-13612 V1 changes

Signed-off-by: Akshay Tondak <[email protected]>

* IPU clock wait addition to individual tests

Signed-off-by: Akshay Tondak <[email protected]>

* Review comment updates

Signed-off-by: Akshay Tondak <[email protected]>

* Using device_query_default

Signed-off-by: Akshay Tondak <[email protected]>

---------

Signed-off-by: Akshay Tondak <[email protected]>
Co-authored-by: Akshay Tondak <[email protected]>
  • Loading branch information
aktondak and Akshay Tondak authored Oct 16, 2024
1 parent c4ac4b8 commit ecb336b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/runtime_src/core/tools/common/tests/TestGemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ TestGemm::run(std::shared_ptr<xrt_core::device> dev)
// Create 128KB Debug BO to capture TOPS data
xrt::bo bo_result = xrt_core::bo_int::create_debug_bo(hwctx, 0x20000);

// wait until clock reaches the max frequency
int ipu_hclock = 0;
XBValidateUtils::wait_for_max_clock(ipu_hclock, dev);
// wait until clock reaches the max frequency. The performance metrics for a test
// are valid only when the clock reaches the max frequency.
uint64_t ipu_hclock = XBValidateUtils::wait_for_max_clock(dev);

try {
//run kernel
Expand Down
55 changes: 26 additions & 29 deletions src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,42 +135,39 @@ get_instr_size(const std::string& dpu_file) {
return size;
}

void
wait_for_max_clock(int& ipu_hclock, std::shared_ptr<xrt_core::device> dev) {
int ipu_hclock_pre = 0;
auto hclock_steady_counter = 0;
auto first_steady_state = -1, second_steady_state = -1;;

for(int i=0; i<100;i++){
/**
* @brief Waits for the IPU clock frequency to reach the target maximum clock frequency.
*
* This function queries the device for the target maximum clock frequency and then
* continuously checks the current IPU clock frequency until it reaches the target.
*
* @param dev A shared pointer to the xrt_core::device.
* @return The IPU clock frequency when it reaches the target maximum clock frequency.
*/
uint64_t
wait_for_max_clock(std::shared_ptr<xrt_core::device> dev) {
uint64_t target_h_clock_freq = 0;
uint64_t ipu_hclock = 0;
auto res_info = xrt_core::device_query_default<xrt_core::query::xrt_resource_raw>(dev, {});
if (res_info.empty())
return ipu_hclock;

for (auto &res : res_info)
{
if (res.type != xrt_core::query::xrt_resource_raw::resource_type::ipu_clk_max)
continue;
target_h_clock_freq = res.data_uint64;
}
while (ipu_hclock < target_h_clock_freq) {
//get h-clock
auto raw = xrt_core::device_query<xrt_core::query::clock_freq_topology_raw>(dev);
auto clock_topology = reinterpret_cast<const clock_freq_topology*>(raw.data());
for (int c = 0; c < clock_topology->m_count; c++) {
if(boost::iequals(clock_topology->m_clock_freq[c].m_name, "H CLock"))
ipu_hclock = clock_topology->m_clock_freq[c].m_freq_Mhz;
}
std::this_thread::sleep_for(std::chrono::milliseconds(50));
//std::cout << "NPU clock: " << ipu_hclock <<std::endl;

hclock_steady_counter = (ipu_hclock == ipu_hclock_pre) ? hclock_steady_counter + 1 : 0;
if(hclock_steady_counter == 8 && first_steady_state == -1 && ipu_hclock >= 1810) {
//break;
first_steady_state = ipu_hclock_pre;
hclock_steady_counter = 0;
}

if(hclock_steady_counter == 8 && first_steady_state != -1 && second_steady_state == -1 && ipu_hclock > first_steady_state) {
//break;
second_steady_state = ipu_hclock;
hclock_steady_counter = 0;
}

if (hclock_steady_counter == 8 && second_steady_state != -1 && ipu_hclock > second_steady_state) {
break;
}

ipu_hclock_pre = ipu_hclock; // Update hclk with hclk_pre

}
return ipu_hclock;
}

}// end of namespace XBValidateUtils
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace XBValidateUtils{

void init_instr_buf(xrt::bo &bo_instr, const std::string& dpu_file);
size_t get_instr_size(const std::string& dpu_file);
void wait_for_max_clock(int&, std::shared_ptr<xrt_core::device>);
uint64_t wait_for_max_clock(std::shared_ptr<xrt_core::device>);

} //End of namespace XBValidateUtils
#endif

0 comments on commit ecb336b

Please sign in to comment.