Skip to content

Commit

Permalink
Merge pull request #42 from wimrijnders/evolve-rot3dlib-1
Browse files Browse the repository at this point in the history
Add command line parameter for selecting kernel to Rot3DLib
  • Loading branch information
mn416 authored Jul 5, 2018
2 parents b07c1a0 + c49a285 commit e5e585b
Showing 1 changed file with 72 additions and 20 deletions.
92 changes: 72 additions & 20 deletions Examples/Rot3DLib/Rot3DLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,62 @@

using namespace Rot3DLib;

// #define USE_SCALAR_VERSION

// ============================================================================
// Main
// ============================================================================
using Generator = decltype(rot3D_1); // All kernel functions except scalar have same prototype

int main()
{
// Timestamps
timeval tvStart, tvEnd, tvDiff;

// Number of vertices and angle of rotation
const int N = 19200; // 192000
const float THETA = (float) 3.14159;
// Number of vertices and angle of rotation
const int N = 19200; // 192000
const float THETA = (float) 3.14159;


timeval runScalar() {
printf("Running scalar\n");

#ifdef USE_SCALAR_VERSION
// Allocate and initialise
float* x = new float [N];
float* y = new float [N];
for (int i = 0; i < N; i++) {
x[i] = (float) i;
y[i] = (float) i;
}
#else

timeval tvStart, tvEnd, tvDiff;
gettimeofday(&tvStart, NULL);

rot3D(N, cosf(THETA), sinf(THETA), x, y);

gettimeofday(&tvEnd, NULL);
timersub(&tvEnd, &tvStart, &tvDiff);

// Display results
//for (int i = 0; i < N; i++)
// printf("%f %f\n", x[i], y[i]);

delete x;
delete y;

return tvDiff;
}


timeval runKernel(int index) {
printf("Running kernel %d\n", index);

Generator *kGenerator = nullptr;

switch (index) {
case 1: kGenerator = rot3D_1; break;
case 2: kGenerator = rot3D_2; break;
case 3: kGenerator = rot3D_3; break;
default:
printf("ERROR: No kernel with index %d\n", index);
exit(-1);
};


// Construct kernel
auto k = compile(rot3D_3);
auto k = compile(kGenerator);

// Use 12 QPUs
k.setNumQPUs(12);
Expand All @@ -40,21 +70,43 @@ int main()
x[i] = (float) i;
y[i] = (float) i;
}
#endif

timeval tvStart, tvEnd, tvDiff;
gettimeofday(&tvStart, NULL);
#ifdef USE_SCALAR_VERSION
rot3D(N, cosf(THETA), sinf(THETA), x, y);
#else

k(N, cosf(THETA), sinf(THETA), &x, &y);
#endif

gettimeofday(&tvEnd, NULL);
timersub(&tvEnd, &tvStart, &tvDiff);

// Display results
//for (int i = 0; i < N; i++)
// printf("%f %f\n", x[i], y[i]);


return tvDiff;
}


// ============================================================================
// Main
// ============================================================================

int main(int argc, char *argv[])
{
timeval tvDiff;

int index = 3;

if (argc > 1) {
index = atoi(argv[1]);
}

if (index == 0) {
tvDiff = runScalar();
} else {
tvDiff = runKernel(index);
}

printf("%ld.%06lds\n", tvDiff.tv_sec, tvDiff.tv_usec);

return 0;
Expand Down

0 comments on commit e5e585b

Please sign in to comment.