Skip to content

Commit

Permalink
Add event timing for HC
Browse files Browse the repository at this point in the history
  • Loading branch information
jlgreathouse committed Feb 14, 2020
1 parent 9476baf commit 7d63c40
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
36 changes: 28 additions & 8 deletions HCStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ void listDevices(void)


template <class T>
HCStream<T>::HCStream(const unsigned int ARRAY_SIZE, const int device_index):
HCStream<T>::HCStream(const unsigned int ARRAY_SIZE, const bool event_timing,
const int device_index):
array_size(ARRAY_SIZE),
d_a(ARRAY_SIZE),
d_b(ARRAY_SIZE),
d_c(ARRAY_SIZE),
evt_timing(event_timing),
lane_cnt(ARRAY_SIZE / elts_per_lane)
{

Expand Down Expand Up @@ -127,6 +129,7 @@ void HCStream<T>::read_arrays(std::vector<T>& a, std::vector<T>& b, std::vector<
template <class T>
float HCStream<T>::read()
{
float evt_time = 0.;

hc::array_view<T,1> view_a = this->d_a;
hc::array_view<T,1> view_c = this->d_c;
Expand All @@ -145,18 +148,21 @@ float HCStream<T>::read()
view_c[index] = temp;
});
future_kernel.wait();
if (evt_timing)
evt_time = (future_kernel.get_end_tick() - future_kernel.get_begin_tick()) / 1000000.;
}
catch(std::exception& e){
std::cerr << __FILE__ << ":" << __LINE__ << "\t HCStream<T>::read " << e.what() << std::endl;
throw;
}

return 0.;
return evt_time;
}

template <class T>
float HCStream<T>::write()
{
float evt_time = 0.;

hc::array_view<T,1> view_c = this->d_c;

Expand All @@ -171,18 +177,22 @@ float HCStream<T>::write()
}
});
future_kernel.wait();
if (evt_timing)
evt_time = (future_kernel.get_end_tick() - future_kernel.get_begin_tick()) / 1000000.;
}

catch(std::exception& e){
std::cerr << __FILE__ << ":" << __LINE__ << "\t HCStream<T>::write " << e.what() << std::endl;
throw;
}

return 0.;
return evt_time;
}

template <class T>
float HCStream<T>::copy()
{
float evt_time = 0.;

hc::array_view<T,1> view_a = this->d_a;
hc::array_view<T,1> view_c = this->d_c;
Expand All @@ -202,18 +212,21 @@ float HCStream<T>::copy()
}
});
future_kernel.wait();
if (evt_timing)
evt_time = (future_kernel.get_end_tick() - future_kernel.get_begin_tick()) / 1000000.;
}
catch(std::exception& e){
std::cerr << __FILE__ << ":" << __LINE__ << "\t HCStream<T>::copy " << e.what() << std::endl;
throw;
}

return 0.;
return evt_time;
}

template <class T>
float HCStream<T>::mul()
{
float evt_time = 0.;

const T scalar = startScalar;
hc::array_view<T,1> view_b = this->d_b;
Expand All @@ -234,19 +247,21 @@ float HCStream<T>::mul()
}
});
future_kernel.wait();
if (evt_timing)
evt_time = (future_kernel.get_end_tick() - future_kernel.get_begin_tick()) / 1000000.;
}
catch(std::exception& e){
std::cerr << __FILE__ << ":" << __LINE__ << "\t HCStream<T>::mul " << e.what() << std::endl;
throw;
}

return 0.;
return evt_time;
}

template <class T>
float HCStream<T>::add()
{

float evt_time = 0.;

hc::array_view<T,1> view_a(this->d_a);
hc::array_view<T,1> view_b(this->d_b);
Expand All @@ -267,18 +282,21 @@ float HCStream<T>::add()
}
});
future_kernel.wait();
if (evt_timing)
evt_time = (future_kernel.get_end_tick() - future_kernel.get_begin_tick()) / 1000000.;
}
catch(std::exception& e){
std::cerr << __FILE__ << ":" << __LINE__ << "\t HCStream<T>::add " << e.what() << std::endl;
throw;
}

return 0.;
return evt_time;
}

template <class T>
float HCStream<T>::triad()
{
float evt_time = 0.;

const T scalar = startScalar;
hc::array_view<T,1> view_a(this->d_a);
Expand All @@ -300,13 +318,15 @@ float HCStream<T>::triad()
}
});
future_kernel.wait();
if (evt_timing)
evt_time = (future_kernel.get_end_tick() - future_kernel.get_begin_tick()) / 1000000.;
}
catch(std::exception& e){
std::cerr << __FILE__ << ":" << __LINE__ << "\t HCStream<T>::triad " << e.what() << std::endl;
throw;
}

return 0.;
return evt_time;
}

template <class T>
Expand Down
9 changes: 6 additions & 3 deletions HCStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ class HCStream : public Stream<T>
static constexpr unsigned int elts_per_lane{sizeof_best_size / sizeof(T)};
protected:
// Size of arrays
unsigned int array_size;
unsigned int lane_cnt;
const unsigned int array_size;
const unsigned int lane_cnt;

const bool evt_timing;

// Device side pointers to arrays
hc::array<T,1> d_a;
hc::array<T,1> d_b;
hc::array<T,1> d_c;

public:
HCStream(const unsigned int, const int);
HCStream(const unsigned int, const bool, const int);
~HCStream();

virtual float read() override;
Expand Down
8 changes: 4 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static double calculate_time_s(const bool evt_timing,
const std::chrono::high_resolution_clock::time_point t2,
const float kernel_time)
{
#if defined(HIP) || defined(OCL) || defined(CUDA)
#if defined(HIP) || defined(OCL) || defined(CUDA) || defined(HC)
if (!event_timing)
return std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();
else
Expand Down Expand Up @@ -164,7 +164,7 @@ void run()

#elif defined(HC)
// Use the HC implementation
stream = new HCStream<T>(ARRAY_SIZE, deviceIndex);
stream = new HCStream<T>(ARRAY_SIZE, event_timing, deviceIndex);

#elif defined(OCL)
// Use the OpenCL implementation
Expand Down Expand Up @@ -579,7 +579,7 @@ void parseArguments(int argc, char *argv[])
{
triad_only = true;
}
#if defined(HIP) || defined(CUDA) || defined(OCL)
#if defined(HIP) || defined(CUDA) || defined(OCL) || defined(HC)
else if (!std::string("--event-timing").compare(argv[i]) ||
!std::string("-e").compare(argv[i]))
{
Expand Down Expand Up @@ -607,7 +607,7 @@ void parseArguments(int argc, char *argv[])
std::cout << " -n --numtimes NUM Run the test NUM times (NUM >= 2)" << std::endl;
std::cout << " --float Use floats (rather than doubles)" << std::endl;
std::cout << " --triad-only Only run triad" << std::endl;
#if defined(HIP) || defined(CUDA) || defined(OCL)
#if defined(HIP) || defined(CUDA) || defined(OCL) || defined(HC)
std::cout << " -e --event-timing Use event timing instead of host-side timing" << std::endl;
#endif
std::cout << " --csv Output as csv table" << std::endl;
Expand Down

0 comments on commit 7d63c40

Please sign in to comment.