diff --git a/src/runtime_src/core/tools/common/tests/TestGemm.cpp b/src/runtime_src/core/tools/common/tests/TestGemm.cpp index 0540c36713..3557c044b1 100644 --- a/src/runtime_src/core/tools/common/tests/TestGemm.cpp +++ b/src/runtime_src/core/tools/common/tests/TestGemm.cpp @@ -119,9 +119,9 @@ TestGemm::run(std::shared_ptr 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 diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp index 37f2ddeb52..3e77e360ab 100644 --- a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp @@ -135,13 +135,31 @@ get_instr_size(const std::string& dpu_file) { return size; } -void -wait_for_max_clock(int& ipu_hclock, std::shared_ptr 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 dev) { + uint64_t target_h_clock_freq = 0; + uint64_t ipu_hclock = 0; + auto res_info = xrt_core::device_query_default(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(dev); auto clock_topology = reinterpret_cast(raw.data()); for (int c = 0; c < clock_topology->m_count; c++) { @@ -149,28 +167,7 @@ wait_for_max_clock(int& ipu_hclock, std::shared_ptr dev) { 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 <= 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 diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h index 072bf70185..11761c66ae 100644 --- a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h @@ -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); +uint64_t wait_for_max_clock(std::shared_ptr); } //End of namespace XBValidateUtils #endif