Skip to content

Commit

Permalink
Review comments handling
Browse files Browse the repository at this point in the history
Signed-off-by: Akshay Tondak <[email protected]>
  • Loading branch information
Akshay Tondak authored and Akshay Tondak committed Sep 17, 2024
1 parent 2574b5b commit cd11ea3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/common/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ TestRunner::get_test_header()
// - mut: Mutex to lock the critical section
// - cond_var: Condition variable to wait on
// - thread_ready: Counter to track the number of ready threads
void TestRunner::wait_for_threads_ready(uint32_t thread_num, std::mutex& mut, std::condition_variable& cond_var, uint32_t& thread_ready) {
void TestRunner::wait_for_threads_ready(const int thread_num, std::mutex& mut, std::condition_variable& cond_var, int& thread_ready) {
std::unique_lock<std::mutex> lock(mut);
while (thread_ready != thread_num) {
lock.unlock();
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/common/TestRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestRunner : public JSONConfigurable {
const std::string & getConfigName() const { return get_name(); };
virtual const std::string& getConfigDescription() const { return m_description; };
boost::property_tree::ptree get_test_header();
void wait_for_threads_ready(uint32_t thread_num, std::mutex& mut, std::condition_variable& cond_var, uint32_t& thread_ready);
void wait_for_threads_ready(const int thread_num, std::mutex& mut, std::condition_variable& cond_var, int& thread_ready);

// Child class helper methods
protected:
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/core/tools/common/tests/TestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void BO_set::set_kernel_args(xrt::run& run) {
// - cond_var: Condition variable to wait on
// - thread_ready: Counter to track the number of ready threads
void
TestCase::run(std::mutex& mut, std::condition_variable& cond_var, uint32_t& thread_ready)
TestCase::run(std::mutex& mut, std::condition_variable& cond_var, int& thread_ready)
{
std::vector<xrt::kernel> kernels;
std::vector<BO_set> bo_set_list;
Expand Down Expand Up @@ -92,7 +92,7 @@ TestCase::run(std::mutex& mut, std::condition_variable& cond_var, uint32_t& thre
}

// Method to signal that a thread is ready to run
void TestCase::thread_ready_to_run(std::mutex& mut, std::condition_variable& cond_var, uint32_t& thread_ready) {
void TestCase::thread_ready_to_run(std::mutex& mut, std::condition_variable& cond_var, int& thread_ready) {
std::unique_lock<std::mutex> lock(mut);
thread_ready++;
cond_var.wait(lock);
Expand Down
14 changes: 8 additions & 6 deletions src/runtime_src/core/tools/common/tests/TestHelper.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved.

#ifndef __TestHelper_h_
#define __TestHelper_h_

// ------ I N C L U D E F I L E S -------------------------------------------
// Local - Include Files
#include "tools/common/TestRunner.h"
Expand Down Expand Up @@ -39,17 +42,16 @@ class TestCase {
int itr_count; // Number of iterations

// Method to signal that a thread is ready to run
void thread_ready_to_run(std::mutex&, std::condition_variable&, uint32_t&);
void thread_ready_to_run(std::mutex&, std::condition_variable&, int&);

public:
// Constructor to initialize the test case with xclbin and kernel name with hardware context creation
TestCase(xrt::xclbin& xclbin, std::string& kernel, size_t buffer_size = 1024)
: device(xrt::device(0)), xclbin(xclbin), kernel_name(kernel), buffer_size(buffer_size), itr_count(1000)
TestCase(xrt::xclbin& xclbin, std::string& kernel, xrt::device& device)
: device(device), xclbin(xclbin), kernel_name(kernel), buffer_size(1024), itr_count(1000)
{
device.register_xclbin(xclbin);
hw_ctx = xrt::hw_context(device, xclbin.get_uuid());
}

void run(std::mutex&, std::condition_variable&, uint32_t&);
void run(std::mutex&, std::condition_variable&, int&);
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ boost::property_tree::ptree TestSpatialSharingOvd::run(std::shared_ptr<xrt_core:

std::mutex mut;
std::condition_variable cond_var;
uint32_t thread_ready = 0;
int thread_ready = 0;

/* Run 1 */
std::vector<std::thread> threads;
std::vector<TestCase> testcases;

// Create two test cases and add them to the vector
testcases.emplace_back(xclbin, kernelName);
testcases.emplace_back(xclbin, kernelName);
testcases.emplace_back(xclbin, kernelName, working_dev);
testcases.emplace_back(xclbin, kernelName, working_dev);

// Lambda function to run a test case. This will be sent to individual thread to be run.
auto runTestcase = [&](TestCase& test) {
Expand All @@ -109,7 +109,7 @@ boost::property_tree::ptree TestSpatialSharingOvd::run(std::shared_ptr<xrt_core:
threads.emplace_back(runTestcase, std::ref(testcases[1]));

// Wait for both threads to be ready to begin clocking
wait_for_threads_ready((uint32_t)threads.size(), mut, cond_var, thread_ready);
wait_for_threads_ready((int)threads.size(), mut, cond_var, thread_ready);

// Measure the latency for running the test cases in parallel
auto start = std::chrono::high_resolution_clock::now();
Expand All @@ -124,7 +124,7 @@ boost::property_tree::ptree TestSpatialSharingOvd::run(std::shared_ptr<xrt_core:

/* Run 2 */
// Create a single test case and run it in a single thread
TestCase t(xclbin, kernelName);
TestCase t(xclbin, kernelName, working_dev);
std::thread thr(runTestcase, std::ref(t));

// Wait for the thread to be ready
Expand All @@ -139,8 +139,8 @@ boost::property_tree::ptree TestSpatialSharingOvd::run(std::shared_ptr<xrt_core:

// Log the latencies and the overhead
if(XBU::getVerbose()){
logger(ptree, "Details", boost::str(boost::format("LatencySingle: '%.1f' ms") % (latencySingle * 1000)));
logger(ptree, "Details", boost::str(boost::format("LatencyShared: '%.1f' ms") % (latencyShared * 1000)));
logger(ptree, "Details", boost::str(boost::format("Single context latency: '%.1f' ms") % (latencySingle * 1000)));
logger(ptree, "Details", boost::str(boost::format("Spatially shared multiple context latency: '%.1f' ms") % (latencyShared * 1000)));
}
logger(ptree, "Details", boost::str(boost::format("Overhead: '%.1f' ms") % ((latencyShared - latencySingle) * 1000)));

Expand Down

0 comments on commit cd11ea3

Please sign in to comment.