Skip to content

Commit

Permalink
Fix for inconsistent use of timers in C++ code
Browse files Browse the repository at this point in the history
This is a fix for bug #42, where we used a mix of C and C++ timers in
the C++ examples. Fixed to always use the C++ method in C++ code.
  • Loading branch information
simonmcs committed Oct 24, 2013
1 parent 5426e0e commit 2bbe81f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ Solutions/ExerciseA/Cpp/pi_vocl

Exercises/Exercise01/C/DeviceInfo.dSYM/Contents/Resources/DWARF/DeviceInfo


Solutions/Exercise06/Cpp/Makefile.tmp

Solutions/ExerciseA/C/pi_vocl.dSYM/Contents/Resources/DWARF/pi_vocl
18 changes: 12 additions & 6 deletions Solutions/Exercise06/Cpp/matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "matmul.hpp"
#include "matrix_lib.hpp"
#include "util.hpp"


std::string kernelsource = "__kernel void mmul( \n" \
" const int Mdim, \n" \
Expand Down Expand Up @@ -49,11 +51,12 @@ int main(void)
{

int Mdim, Ndim, Pdim; // A[N][P], B[P][M], C[N][M]
int szA, szB, szC; // number of elements in each matrix
int szA, szB, szC; // Number of elements in each matrix


double start_time; // Starting time
double run_time; // timing data
double run_time; // Timing
util::Timer timer; // Timing

Ndim = ORDER;
Pdim = ORDER;
Expand All @@ -71,15 +74,18 @@ int main(void)

initmat(Mdim, Ndim, Pdim, h_A, h_B, h_C);

timer.reset();

printf("\n===== Sequential, matrix mult (dot prod), order %d on host CPU ======\n",ORDER);
for(int i = 0; i < COUNT; i++)
{
zero_mat(Ndim, Mdim, h_C);
start_time = wtime();

start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

seq_mat_mul_sdot(Mdim, Ndim, Pdim, h_A, h_B, h_C);

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;
results(Mdim, Ndim, Pdim, h_C, run_time);
}

Expand Down Expand Up @@ -123,7 +129,7 @@ int main(void)
{
zero_mat(Ndim, Mdim, h_C);

start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

// Execute the kernel over the entire range of C matrix elements ... computing
// a dot product for each element of the product matrix. The local work
Expand All @@ -135,7 +141,7 @@ int main(void)

queue.finish();

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;

cl::copy(queue, d_c, begin(h_C), end(h_C));

Expand Down
23 changes: 13 additions & 10 deletions Solutions/Exercise07/Cpp/matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ int main(void)
{

int Mdim, Ndim, Pdim; // A[N][P], B[P][M], C[N][M]
int szA, szB, szC; // number of elements in each matrix
int szA, szB, szC; // Number of elements in each matrix


double start_time; // Starting time
double run_time; // timing data
double run_time; // Timing data
util::Timer timer; // Timer


Ndim = ORDER;
Pdim = ORDER;
Expand All @@ -53,11 +55,11 @@ int main(void)
for(int i = 0; i < COUNT; i++)
{
zero_mat(Ndim, Mdim, h_C);
start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

seq_mat_mul_sdot(Mdim, Ndim, Pdim, h_A, h_B, h_C);

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;
results(Mdim, Ndim, Pdim, h_C, run_time);
}

Expand Down Expand Up @@ -101,7 +103,7 @@ int main(void)
{
zero_mat(Ndim, Mdim, h_C);

start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

// Execute the kernel over the entire range of C matrix elements ... computing
// a dot product for each element of the product matrix. The local work
Expand All @@ -113,7 +115,7 @@ int main(void)

queue.finish();

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;

cl::copy(queue, d_c, begin(h_C), end(h_C));

Expand All @@ -138,15 +140,15 @@ int main(void)
{
zero_mat(Ndim, Mdim, h_C);

start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

cl::NDRange global(Ndim);
crow_mmul(cl::EnqueueArgs(queue, global),
Mdim, Ndim, Pdim, d_a, d_b, d_c);

queue.finish();

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;

cl::copy(queue, d_c, begin(h_C), end(h_C));

Expand All @@ -171,7 +173,8 @@ int main(void)
{
zero_mat(Ndim, Mdim, h_C);

start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;


cl::NDRange global(Ndim);
cl::NDRange local(ORDER / 16);
Expand All @@ -180,7 +183,7 @@ int main(void)

queue.finish();

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;

cl::copy(queue, d_c, begin(h_C), end(h_C));

Expand Down
30 changes: 16 additions & 14 deletions Solutions/Exercise08/Cpp/matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@

#include "matmul.hpp"
#include "matrix_lib.hpp"
#include "util.hpp"

int main(void)
{

int Mdim, Ndim, Pdim; // A[N][P], B[P][M], C[N][M]
int szA, szB, szC; // number of elements in each matrix
int szA, szB, szC; // Number of elements in each matrix


double start_time; // Starting time
double run_time; // timing data
double run_time; // Timing data
util::Timer timer; // timing

Ndim = ORDER;
Pdim = ORDER;
Expand All @@ -53,11 +55,11 @@ int main(void)
for(int i = 0; i < COUNT; i++)
{
zero_mat(Ndim, Mdim, h_C);
start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

seq_mat_mul_sdot(Mdim, Ndim, Pdim, h_A, h_B, h_C);

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;
results(Mdim, Ndim, Pdim, h_C, run_time);
}

Expand Down Expand Up @@ -101,7 +103,7 @@ int main(void)
{
zero_mat(Ndim, Mdim, h_C);

start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

// Execute the kernel over the entire range of C matrix elements ... computing
// a dot product for each element of the product matrix. The local work
Expand All @@ -113,7 +115,7 @@ int main(void)

queue.finish();

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;

cl::copy(queue, d_c, begin(h_C), end(h_C));

Expand All @@ -138,15 +140,15 @@ int main(void)
{
zero_mat(Ndim, Mdim, h_C);

start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

cl::NDRange global(Ndim);
crow_mmul(cl::EnqueueArgs(queue, global),
Mdim, Ndim, Pdim, d_a, d_b, d_c);

queue.finish();

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;

cl::copy(queue, d_c, begin(h_C), end(h_C));

Expand All @@ -171,7 +173,7 @@ int main(void)
{
zero_mat(Ndim, Mdim, h_C);

start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

cl::NDRange global(Ndim);
cl::NDRange local(ORDER / 16);
Expand All @@ -180,7 +182,7 @@ int main(void)

queue.finish();

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;

cl::copy(queue, d_c, begin(h_C), end(h_C));

Expand All @@ -205,7 +207,7 @@ int main(void)
{
zero_mat(Ndim, Mdim, h_C);

start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

cl::NDRange global(Ndim);
cl::NDRange local(ORDER / 16);
Expand All @@ -217,7 +219,7 @@ int main(void)

queue.finish();

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;

cl::copy(queue, d_c, begin(h_C), end(h_C));

Expand All @@ -242,7 +244,7 @@ int main(void)
{
zero_mat(Ndim, Mdim, h_C);

start_time = wtime();
start_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0;

int blocksize = 16;
cl::NDRange global(Ndim, Mdim);
Expand All @@ -256,7 +258,7 @@ int main(void)

queue.finish();

run_time = wtime() - start_time;
run_time = static_cast<double>(timer.getTimeMilliseconds()) / 1000.0 - start_time;

cl::copy(queue, d_c, begin(h_C), end(h_C));

Expand Down

0 comments on commit 2bbe81f

Please sign in to comment.