From 40ed4323b66884bc0efbba0be291366d6e91a841 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Thu, 10 Oct 2024 17:07:51 -0700 Subject: [PATCH] Spatial Sharing test update for low variance (#8506) * Spatial Sharing test update for low variance Signed-off-by: Akshay Tondak * Header correction Signed-off-by: Akshay Tondak * Update TestValidateUtilities.h * Fix for XRT build fail Signed-off-by: Akshay Tondak * Review comment changes Signed-off-by: Akshay Tondak --------- Signed-off-by: Akshay Tondak Co-authored-by: Akshay Tondak --- .../core/tools/common/TestRunner.cpp | 40 ---- .../core/tools/common/TestRunner.h | 2 - .../common/tests/TestAIEReconfigOverhead.cpp | 5 +- .../tools/common/tests/TestDF_bandwidth.cpp | 5 +- .../core/tools/common/tests/TestGemm.cpp | 40 +--- .../core/tools/common/tests/TestHelper.cpp | 82 --------- .../common/tests/TestSpatialSharingOvd.cpp | 24 ++- .../tools/common/tests/TestTCTAllColumn.cpp | 5 +- .../tools/common/tests/TestTCTOneColumn.cpp | 5 +- .../common/tests/TestValidateUtilities.cpp | 171 ++++++++++++++++++ .../{TestHelper.h => TestValidateUtilities.h} | 42 +++-- 11 files changed, 232 insertions(+), 189 deletions(-) delete mode 100644 src/runtime_src/core/tools/common/tests/TestHelper.cpp create mode 100644 src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp rename src/runtime_src/core/tools/common/tests/{TestHelper.h => TestValidateUtilities.h} (59%) diff --git a/src/runtime_src/core/tools/common/TestRunner.cpp b/src/runtime_src/core/tools/common/TestRunner.cpp index e8414b304d0..1abe09787e7 100644 --- a/src/runtime_src/core/tools/common/TestRunner.cpp +++ b/src/runtime_src/core/tools/common/TestRunner.cpp @@ -360,46 +360,6 @@ TestRunner::validate_binary_file(const std::string& binaryfile) else return EXIT_SUCCESS; } - -// Copy values from text files into buff, expecting values are ascii encoded hex -void -TestRunner::init_instr_buf(xrt::bo &bo_instr, const std::string& dpu_file) { - std::ifstream dpu_stream(dpu_file); - if (!dpu_stream.is_open()) { - throw std::runtime_error(boost::str(boost::format("Failed to open %s for reading") % dpu_file)); - } - - auto instr = bo_instr.map(); - std::string line; - while (std::getline(dpu_stream, line)) { - if (line.at(0) == '#') { - continue; - } - std::stringstream ss(line); - unsigned int word = 0; - ss >> std::hex >> word; - *(instr++) = word; - } -} - -size_t -TestRunner::get_instr_size(const std::string& dpu_file) { - std::ifstream file(dpu_file); - if (!file.is_open()) { - throw std::runtime_error(boost::str(boost::format("Failed to open %s for reading") % dpu_file)); - } - size_t size = 0; - std::string line; - while (std::getline(file, line)) { - if (line.at(0) != '#') { - size++; - } - } - if (size == 0) { - throw std::runtime_error("Invalid DPU instruction length"); - } - return size; -} bool TestRunner::search_and_program_xclbin(const std::shared_ptr& dev, boost::property_tree::ptree& ptTest) { diff --git a/src/runtime_src/core/tools/common/TestRunner.h b/src/runtime_src/core/tools/common/TestRunner.h index ce6bf61dfd1..85f422896da 100644 --- a/src/runtime_src/core/tools/common/TestRunner.h +++ b/src/runtime_src/core/tools/common/TestRunner.h @@ -46,8 +46,6 @@ class TestRunner : public JSONConfigurable { std::vector findDependencies( const std::string& test_path, const std::string& ps_kernel_name); int validate_binary_file(const std::string& binaryfile); - void init_instr_buf(xrt::bo &bo_instr, const std::string& dpu_file); - size_t get_instr_size(const std::string& dpu_file); void result_in_range(double value, double threshold, boost::property_tree::ptree& ptTest); void set_threshold(const std::shared_ptr& dev, boost::property_tree::ptree& ptTest); double get_threshold(){return m_threshold;}; diff --git a/src/runtime_src/core/tools/common/tests/TestAIEReconfigOverhead.cpp b/src/runtime_src/core/tools/common/tests/TestAIEReconfigOverhead.cpp index 714247e87a3..4e8a8e4a6f0 100644 --- a/src/runtime_src/core/tools/common/tests/TestAIEReconfigOverhead.cpp +++ b/src/runtime_src/core/tools/common/tests/TestAIEReconfigOverhead.cpp @@ -2,6 +2,7 @@ // Local - Include Files #include "TestAIEReconfigOverhead.h" +#include "TestValidateUtilities.h" #include "tools/common/XBUtilities.h" #include "xrt/xrt_bo.h" #include "xrt/xrt_device.h" @@ -104,7 +105,7 @@ TestAIEReconfigOverhead::run(std::shared_ptr dev) size_t instr_size = 0; try { - instr_size = get_instr_size(dpu_instr); + instr_size = XBValidateUtils::get_instr_size(dpu_instr); } catch(const std::exception& ex) { logger(ptree, "Error", ex.what()); @@ -123,7 +124,7 @@ TestAIEReconfigOverhead::run(std::shared_ptr dev) argno++; xrt::bo bo_mc(working_dev, 16, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(argno++)); - init_instr_buf(bo_instr, dpu_instr); + XBValidateUtils::init_instr_buf(bo_instr, dpu_instr); //Create ctrlcode with NOPs std::memset(bo_instr_no_op.map(), 0, instr_size); diff --git a/src/runtime_src/core/tools/common/tests/TestDF_bandwidth.cpp b/src/runtime_src/core/tools/common/tests/TestDF_bandwidth.cpp index e243068519e..6b6461c4a98 100644 --- a/src/runtime_src/core/tools/common/tests/TestDF_bandwidth.cpp +++ b/src/runtime_src/core/tools/common/tests/TestDF_bandwidth.cpp @@ -4,6 +4,7 @@ // ------ I N C L U D E F I L E S ------------------------------------------- // Local - Include Files #include "TestDF_bandwidth.h" +#include "TestValidateUtilities.h" #include "tools/common/XBUtilities.h" #include "xrt/xrt_bo.h" #include "xrt/xrt_device.h" @@ -108,7 +109,7 @@ TestDF_bandwidth::run(std::shared_ptr dev) size_t instr_size = 0; try { - instr_size = get_instr_size(dpu_instr); + instr_size = XBValidateUtils::get_instr_size(dpu_instr); } catch(const std::exception& ex) { logger(ptree, "Error", ex.what()); @@ -121,7 +122,7 @@ TestDF_bandwidth::run(std::shared_ptr dev) xrt::bo bo_ofm(working_dev, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(3)); xrt::bo bo_instr(working_dev, instr_size*sizeof(int), XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5)); - init_instr_buf(bo_instr, dpu_instr); + XBValidateUtils::init_instr_buf(bo_instr, dpu_instr); // map input buffer auto ifm_mapped = bo_ifm.map(); diff --git a/src/runtime_src/core/tools/common/tests/TestGemm.cpp b/src/runtime_src/core/tools/common/tests/TestGemm.cpp index ab8bcc6b3b0..b20ef52b9e9 100644 --- a/src/runtime_src/core/tools/common/tests/TestGemm.cpp +++ b/src/runtime_src/core/tools/common/tests/TestGemm.cpp @@ -4,6 +4,7 @@ // ------ I N C L U D E F I L E S ------------------------------------------- // Local - Include Files #include "TestGemm.h" +#include "TestValidateUtilities.h" #include "tools/common/XBUtilities.h" #include "xrt/xrt_bo.h" #include "xrt/xrt_device.h" @@ -112,7 +113,7 @@ TestGemm::run(std::shared_ptr dev) size_t instr_size = 0; try { - instr_size = get_instr_size(dpu_instr); + instr_size = XBValidateUtils::get_instr_size(dpu_instr); } catch(const std::exception& ex) { logger(ptree, "Error", ex.what()); @@ -122,7 +123,7 @@ TestGemm::run(std::shared_ptr dev) //Create Instruction BO xrt::bo bo_instr(working_dev, instr_size*sizeof(int), XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5)); - init_instr_buf(bo_instr, dpu_instr); + XBValidateUtils::init_instr_buf(bo_instr, dpu_instr); //Sync Instruction BO bo_instr.sync(XCL_BO_SYNC_BO_TO_DEVICE); @@ -130,41 +131,8 @@ TestGemm::run(std::shared_ptr dev) xrt::bo bo_result = xrt_core::bo_int::create_debug_bo(hwctx, 0x20000); // wait until clock reaches the max frequency - int ipu_hclock_pre = 0; int ipu_hclock = 0; - auto hclock_steady_counter = 0; - auto first_steady_state = -1, second_steady_state = -1;; - - for(int i=0; i<100;i++){ - auto raw = xrt_core::device_query(dev); - auto clock_topology = reinterpret_cast(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 <= 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 - - } + XBValidateUtils::wait_for_max_clock(ipu_hclock, dev); try { //run kernel diff --git a/src/runtime_src/core/tools/common/tests/TestHelper.cpp b/src/runtime_src/core/tools/common/tests/TestHelper.cpp deleted file mode 100644 index 0539fe944c1..00000000000 --- a/src/runtime_src/core/tools/common/tests/TestHelper.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved. - -// ------ I N C L U D E F I L E S ------------------------------------------- -// Local - Include Files -#include "TestHelper.h" - -// Constructor for BO_set -// BO_set is a collection of all the buffer objects so that the operations on all buffers can be done from a single object -// Parameters: -// - device: Reference to the xrt::device object -// - kernel: Reference to the xrt::kernel object -BO_set::BO_set(const xrt::device& device, const xrt::kernel& kernel, size_t buffer_size) - : buffer_size(buffer_size), - bo_instr (device, buffer_size, XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5)), - bo_ifm (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(1)), - bo_param (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(2)), - bo_ofm (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(3)), - bo_inter (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(4)), - bo_mc (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(7)) -{ - // no-op instruction buffer - std::memset(bo_instr.map(), (uint8_t)0, buffer_size); -} - -// Method to synchronize buffer objects to the device -void BO_set::sync_bos_to_device() { - bo_instr.sync(XCL_BO_SYNC_BO_TO_DEVICE); - bo_ifm.sync(XCL_BO_SYNC_BO_TO_DEVICE); - bo_param.sync(XCL_BO_SYNC_BO_TO_DEVICE); - bo_mc.sync(XCL_BO_SYNC_BO_TO_DEVICE); -} - -// Method to set kernel arguments -// Parameters: -// - run: Reference to the xrt::run object -void BO_set::set_kernel_args(xrt::run& run) const { - uint64_t opcode = 1; - run.set_arg(0, opcode); - run.set_arg(1, bo_ifm); - run.set_arg(2, bo_param); - run.set_arg(3, bo_ofm); - run.set_arg(4, bo_inter); - run.set_arg(5, bo_instr); - run.set_arg(6, buffer_size/sizeof(int)); - run.set_arg(7, bo_mc); -} - -void -TestCase::initialize() -{ - // Initialize kernels, buffer objects, and runs - for (int j = 0; j < queue_len; j++) { - auto kernel = xrt::kernel(hw_ctx, kernel_name); - auto bos = BO_set(device, kernel, buffer_size); - bos.sync_bos_to_device(); - auto run = xrt::run(kernel); - bos.set_kernel_args(run); - run.start(); - run.wait2(); - - kernels.push_back(kernel); - bo_set_list.push_back(bos); - run_list.push_back(run); - } -} - -// Method to run the test case -void -TestCase::run() -{ - for (int i = 0; i < itr_count; i++) { - // Start all runs in the queue so that they run in parallel - for (int cnt = 0; cnt < queue_len; cnt++) { - run_list[cnt].start(); - } - // Wait for all runs in the queue to complete - for (int cnt = 0; cnt < queue_len; cnt++) { - run_list[cnt].wait2(); - } - } -} diff --git a/src/runtime_src/core/tools/common/tests/TestSpatialSharingOvd.cpp b/src/runtime_src/core/tools/common/tests/TestSpatialSharingOvd.cpp index ef03adb814d..8ae8ca11ca4 100644 --- a/src/runtime_src/core/tools/common/tests/TestSpatialSharingOvd.cpp +++ b/src/runtime_src/core/tools/common/tests/TestSpatialSharingOvd.cpp @@ -4,7 +4,7 @@ // ------ I N C L U D E F I L E S ------------------------------------------- // Local - Include Files #include "TestSpatialSharingOvd.h" -#include "TestHelper.h" +#include "TestValidateUtilities.h" #include "tools/common/XBUtilities.h" #include "xrt/xrt_bo.h" #include "xrt/xrt_device.h" @@ -15,6 +15,7 @@ namespace XBU = XBUtilities; static constexpr size_t host_app = 1; //opcode +static constexpr size_t buffer_size = 1024; //1 KB // Method to run the test // Parameters: @@ -103,13 +104,20 @@ boost::property_tree::ptree TestSpatialSharingOvd::run(std::shared_ptr(dev, xrt_core::query::sequence_name::type::df_bandwidth); + auto dpu_instr = findPlatformFile(seq_name, ptree); + if (!std::filesystem::exists(dpu_instr)) + return ptree; + + logger(ptree, "DPU-Sequence", dpu_instr); /* Run 1 */ std::vector threads; std::vector testcases; // Create two test cases and add them to the vector - testcases.emplace_back(xclbin, kernelName, working_dev); - testcases.emplace_back(xclbin, kernelName, working_dev); + TestParams params(xclbin, working_dev, kernelName, dpu_instr, 8, buffer_size, 10000); + testcases.emplace_back(params); + testcases.emplace_back(params); for (uint32_t i = 0; i < testcases.size(); i++) { try{ @@ -140,7 +148,7 @@ boost::property_tree::ptree TestSpatialSharingOvd::run(std::shared_ptr dev) size_t instr_size = 0; try { - instr_size = get_instr_size(dpu_instr); + instr_size = XBValidateUtils::get_instr_size(dpu_instr); } catch(const std::exception& ex) { logger(ptree, "Error", ex.what()); @@ -118,7 +119,7 @@ TestTCTAllColumn::run(std::shared_ptr dev) xrt::bo bo_ofm(working_dev, 4*buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(3)); xrt::bo bo_instr(working_dev, instr_size*sizeof(int), XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5)); - init_instr_buf(bo_instr, dpu_instr); + XBValidateUtils::init_instr_buf(bo_instr, dpu_instr); // map input buffer auto ifm_mapped = bo_ifm.map(); diff --git a/src/runtime_src/core/tools/common/tests/TestTCTOneColumn.cpp b/src/runtime_src/core/tools/common/tests/TestTCTOneColumn.cpp index 0b18d4e024e..1706ff8feb1 100644 --- a/src/runtime_src/core/tools/common/tests/TestTCTOneColumn.cpp +++ b/src/runtime_src/core/tools/common/tests/TestTCTOneColumn.cpp @@ -4,6 +4,7 @@ // ------ I N C L U D E F I L E S ------------------------------------------- // Local - Include Files #include "TestTCTOneColumn.h" +#include "TestValidateUtilities.h" #include "tools/common/XBUtilities.h" #include "xrt/xrt_bo.h" #include "xrt/xrt_device.h" @@ -105,7 +106,7 @@ TestTCTOneColumn::run(std::shared_ptr dev) size_t instr_size = 0; try { - instr_size = get_instr_size(dpu_instr); + instr_size = XBValidateUtils::get_instr_size(dpu_instr); } catch(const std::exception& ex) { logger(ptree, "Error", ex.what()); @@ -118,7 +119,7 @@ TestTCTOneColumn::run(std::shared_ptr dev) xrt::bo bo_ofm(working_dev, 4*buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(3)); xrt::bo bo_instr(working_dev, instr_size*sizeof(int), XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5)); - init_instr_buf(bo_instr, dpu_instr); + XBValidateUtils::init_instr_buf(bo_instr, dpu_instr); // map input buffer auto ifm_mapped = bo_ifm.map(); diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp new file mode 100644 index 00000000000..c6edfae8ad1 --- /dev/null +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp @@ -0,0 +1,171 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. + +// ------ I N C L U D E F I L E S ------------------------------------------- +// Local - Include Files +#include +#include +#include "TestValidateUtilities.h" + +// Constructor for BO_set +// BO_set is a collection of all the buffer objects so that the operations on all buffers can be done from a single object +// Parameters: +// - device: Reference to the xrt::device object +// - kernel: Reference to the xrt::kernel object +BO_set::BO_set(const xrt::device& device, const xrt::kernel& kernel, const std::string& dpu_instr, size_t buffer_size) + : buffer_size(buffer_size), + bo_ifm (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(1)), + bo_param (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(2)), + bo_ofm (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(3)), + bo_inter (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(4)), + bo_mc (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(7)) +{ + if (dpu_instr.empty()) { + // Create a no-op instruction if no instruction file is provided + std::memset(bo_instr.map(), (uint8_t)0, buffer_size); + } else { + size_t instr_size = XBValidateUtils::get_instr_size(dpu_instr); + bo_instr = xrt::bo(device, instr_size, XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5)); + } +} + +// Method to synchronize buffer objects to the device +void BO_set::sync_bos_to_device() { + bo_instr.sync(XCL_BO_SYNC_BO_TO_DEVICE); + bo_ifm.sync(XCL_BO_SYNC_BO_TO_DEVICE); + bo_param.sync(XCL_BO_SYNC_BO_TO_DEVICE); + bo_mc.sync(XCL_BO_SYNC_BO_TO_DEVICE); +} + +// Method to set kernel arguments +// Parameters: +// - run: Reference to the xrt::run object +void BO_set::set_kernel_args(xrt::run& run) const { + uint64_t opcode = 1; + run.set_arg(0, opcode); + run.set_arg(1, bo_ifm); + run.set_arg(2, bo_param); + run.set_arg(3, bo_ofm); + run.set_arg(4, bo_inter); + run.set_arg(5, bo_instr); + run.set_arg(6, buffer_size/sizeof(int)); + run.set_arg(7, bo_mc); +} + +void +TestCase::initialize() +{ + hw_ctx = xrt::hw_context(params.device, params.xclbin.get_uuid()); + // Initialize kernels, buffer objects, and runs + for (int j = 0; j < params.queue_len; j++) { + auto kernel = xrt::kernel(hw_ctx, params.kernel_name); + auto bos = BO_set(params.device, kernel, params.dpu_file, params.buffer_size); + bos.sync_bos_to_device(); + auto run = xrt::run(kernel); + bos.set_kernel_args(run); + run.start(); + run.wait2(); + + kernels.push_back(kernel); + bo_set_list.push_back(bos); + run_list.push_back(run); + } +} + +// Method to run the test case +void +TestCase::run() +{ + for (int i = 0; i < params.itr_count; i++) { + // Start all runs in the queue so that they run in parallel + for (int cnt = 0; cnt < params.queue_len; cnt++) { + run_list[cnt].start(); + } + // Wait for all runs in the queue to complete + for (int cnt = 0; cnt < params.queue_len; cnt++) { + run_list[cnt].wait2(); + } + } +} + +namespace XBValidateUtils{ + +// Copy values from text files into buff, expecting values are ascii encoded hex +void +init_instr_buf(xrt::bo &bo_instr, const std::string& dpu_file) { + std::ifstream dpu_stream(dpu_file); + if (!dpu_stream.is_open()) { + throw std::runtime_error(boost::str(boost::format("Failed to open %s for reading") % dpu_file)); + } + + auto instr = bo_instr.map(); + std::string line; + while (std::getline(dpu_stream, line)) { + if (line.at(0) == '#') { + continue; + } + std::stringstream ss(line); + unsigned int word = 0; + ss >> std::hex >> word; + *(instr++) = word; + } +} + +size_t +get_instr_size(const std::string& dpu_file) { + std::ifstream file(dpu_file); + if (!file.is_open()) { + throw std::runtime_error(boost::str(boost::format("Failed to open %s for reading") % dpu_file)); + } + size_t size = 0; + std::string line; + while (std::getline(file, line)) { + if (line.at(0) != '#') { + size++; + } + } + if (size == 0) { + throw std::runtime_error("Invalid DPU instruction length"); + } + 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++){ + auto raw = xrt_core::device_query(dev); + auto clock_topology = reinterpret_cast(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 <= 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 + + } +} + +}// end of namespace XBValidateUtils diff --git a/src/runtime_src/core/tools/common/tests/TestHelper.h b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h similarity index 59% rename from src/runtime_src/core/tools/common/tests/TestHelper.h rename to src/runtime_src/core/tools/common/tests/TestValidateUtilities.h index 39e5db7c116..072bf70185c 100644 --- a/src/runtime_src/core/tools/common/tests/TestHelper.h +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h @@ -1,13 +1,27 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. -#ifndef __TestHelper_h_ -#define __TestHelper_h_ +#ifndef __TestValidateUtilities_h_ +#define __TestValidateUtilities_h_ // ------ I N C L U D E F I L E S ------------------------------------------- // Local - Include Files #include "tools/common/TestRunner.h" +class TestParams { +public: + xrt::xclbin xclbin; // Xclbin object + xrt::device device; + std::string kernel_name; + std::string dpu_file; + int queue_len; + size_t buffer_size; + int itr_count; + + TestParams(const xrt::xclbin& xclbin, xrt::device device, const std::string& kernel_name, const std::string& dpu_file, int queue_len, size_t buffer_size, int itr_count) + : xclbin(xclbin), device(device), kernel_name(kernel_name), dpu_file(dpu_file), queue_len(queue_len), buffer_size(buffer_size), itr_count(itr_count) {} +}; + // Class representing a set of buffer objects (BOs) class BO_set { size_t buffer_size; // Size of the buffer @@ -20,7 +34,7 @@ class BO_set { public: // Constructor to initialize buffer objects - BO_set(const xrt::device&, const xrt::kernel&, size_t); + BO_set(const xrt::device&, const xrt::kernel&, const std::string&, size_t); // Method to set kernel arguments void set_kernel_args(xrt::run&) const; @@ -32,23 +46,27 @@ class BO_set { // Class representing a test case, which is created for a single run on a single thread// class TestCase { - xrt::device device; // Device object - xrt::xclbin xclbin; // Xclbin object - std::string kernel_name; // Name of the kernel + TestParams params; // Test parameters xrt::hw_context hw_ctx; // Hardware context - int queue_len; // Queue length - size_t buffer_size; // Size of the buffer - int itr_count; // Number of iterations std::vector run_list; // Collection of run objects std::vector kernels; // Collection of kernel objects std::vector bo_set_list; // Collection of buffer object sets public: // Constructor to initialize the test case with xclbin and kernel name with hardware context creation - TestCase(const xrt::xclbin& xclbin, const std::string& kernel, const xrt::device& device) - : device(device), xclbin(xclbin), kernel_name(kernel), hw_ctx(device, xclbin.get_uuid()), queue_len(4), buffer_size(1024), itr_count(1000) {} + TestCase(const TestParams& params) + : params(params) {} void initialize(); void run(); -};;; +}; + + +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); + +} //End of namespace XBValidateUtils #endif