Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion hsatimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#define NANOSECONDS_PER_SECOND 1000000000

PerfTimer::PerfTimer() {
freq_in_100mhz = MeasureTSCFreqHz();
}

PerfTimer::~PerfTimer() {
Expand All @@ -56,6 +55,10 @@ PerfTimer::~PerfTimer() {
}
}

void PerfTimer::InitTimer() {
freq_in_100mhz = MeasureTSCFreqHz();
}

// Create a new timer instance and return its index
int PerfTimer::CreateTimer() {

Expand Down
1 change: 1 addition & 0 deletions hsatimer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class PerfTimer {

PerfTimer();
~PerfTimer();
void InitTimer();

private:

Expand Down
52 changes: 40 additions & 12 deletions rocm_bandwidth_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include <cmath>
#include <sstream>
#include <limits>
#include <chrono>
#include <thread>

// Initialize the variable used to capture validation failure
const double RocmBandwidthTest::VALIDATE_COPY_OP_FAILURE = std::numeric_limits<double>::max();
Expand Down Expand Up @@ -587,12 +589,21 @@ void RocmBandwidthTest::RunCopyBenchmark(async_trans_t& trans) {
hsa_signal_store_relaxed(signal_start_bidir, 1);
}

// Create a timer object and reset signals
// Temporary code for testing
if (sleep_time_ > 0) {
std::this_thread::sleep_for(sleep_usecs_);
}

// Create a timer object and start it
PerfTimer timer;
uint32_t index = timer.CreateTimer();
uint32_t cpuTimerIdx = 0;
if (print_cpu_time_) {
timer.InitTimer();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW - Please take a look at #60 on using how to compute TSCFreq just once instead of every time inside a huge triple-nested loop.
Code review could catch such issues.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changelist is the first part. The plan is to completely remove calls to RDTSCP and instead use Chrono library service from C++

cpuTimerIdx = timer.CreateTimer();
timer.StartTimer(cpuTimerIdx);
}

// Start the timer and launch forward copy operation
timer.StartTimer(index);
// Launch the copy operation
if (bidir == false) {
err_ = hsa_amd_memory_async_copy(buf_dst_fwd, dst_agent_fwd,
buf_src_fwd, src_agent_fwd,
Expand Down Expand Up @@ -621,11 +632,11 @@ void RocmBandwidthTest::RunCopyBenchmark(async_trans_t& trans) {

WaitForCopyCompletion(signal_list);

// Stop the timer object
timer.StopTimer(index);

// Push the time taken for copy into a vector of copy times
cpu_time.push_back(timer.ReadTimer(index));
// Stop the timer object and extract time taken
if (print_cpu_time_) {
timer.StopTimer(cpuTimerIdx);
cpu_time.push_back(timer.ReadTimer(cpuTimerIdx));
}

// Collect time from the signal(s)
if (print_cpu_time_ == false) {
Expand Down Expand Up @@ -667,7 +678,9 @@ void RocmBandwidthTest::RunCopyBenchmark(async_trans_t& trans) {
verify = true;

// Clear the stack of cpu times
cpu_time.clear();
if (print_cpu_time_) {
cpu_time.clear();
}
gpu_time.clear();
}

Expand Down Expand Up @@ -803,10 +816,24 @@ RocmBandwidthTest::RocmBandwidthTest(int argc, char** argv) : BaseTest() {

// Initialize version of the test
version_.major_id = 2;
version_.minor_id = 3;
version_.step_id = 11;
version_.minor_id = 4;
version_.step_id = 0;
version_.reserved = 0;

// Test impact of sleep, temp code
sleep_time_ = 0;
bw_sleep_time_ = getenv("ROCM_BW_SLEEP_TIME");
if (bw_sleep_time_ != NULL) {
sleep_time_ = atoi(bw_sleep_time_);
if ((sleep_time_ < 0) || (sleep_time_ > 60000)) {
std::cout << "Value of ROCM_BW_SLEEP_TIME must be between [1, 60000)" << sleep_time_ << std::endl;
exit(1);
}
sleep_time_ *= 100;
std::chrono::duration<uint32_t, std::micro> temp(sleep_time_);
sleep_usecs_ = temp;
}

bw_iter_cnt_ = getenv("ROCM_BW_ITER_CNT");
bw_default_run_ = getenv("ROCM_BW_DEFAULT_RUN");
bw_blocking_run_ = getenv("ROCR_BW_RUN_BLOCKING");
Expand All @@ -817,6 +844,7 @@ RocmBandwidthTest::RocmBandwidthTest(int argc, char** argv) : BaseTest() {
int32_t num = atoi(bw_iter_cnt_);
if (num < 0) {
std::cout << "Value of ROCM_BW_ITER_CNT can't be negative: " << num << std::endl;
exit(1);
}
set_num_iteration(num);
}
Expand Down
4 changes: 4 additions & 0 deletions rocm_bandwidth_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "common.hpp"

#include <vector>
#include <chrono>

using namespace std;

Expand Down Expand Up @@ -505,6 +506,9 @@ class RocmBandwidthTest : public BaseTest {

// Env key to specify iteration count
char* bw_iter_cnt_;
char* bw_sleep_time_;
uint32_t sleep_time_;
std::chrono::duration<uint32_t, std::micro> sleep_usecs_;

// Variable to store argument number

Expand Down