new files

This commit is contained in:
Michael Boulton 2015-07-28 11:37:50 +01:00
parent b43eb9cf16
commit 0a89282d57
4 changed files with 13055 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
gpu-stream-cuda
gpu-stream-ocl
*.o

12906
CL/cl.hpp Normal file

File diff suppressed because it is too large Load Diff

75
common.cpp Normal file
View File

@ -0,0 +1,75 @@
#include "common.h"
int ARRAY_SIZE = 50000000;
int NTIMES = 10;
bool useFloat = false;
int deviceIndex = 0;
int parseInt(const char *str, int *output)
{
char *next;
*output = strtol(str, &next, 10);
return !strlen(next);
}
void parseArguments(int argc, char *argv[])
{
for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "--list"))
{
listDevices();
exit(0);
}
else if (!strcmp(argv[i], "--device"))
{
if (++i >= argc || !parseInt(argv[i], &deviceIndex))
{
std::cout << "Invalid device index" << std::endl;
exit(1);
}
}
else if (!strcmp(argv[i], "--arraysize") || !strcmp(argv[i], "-s"))
{
if (++i >= argc || !parseInt(argv[i], &ARRAY_SIZE))
{
std::cout << "Invalid array size" << std::endl;
exit(1);
}
}
else if (!strcmp(argv[i], "--numtimes") || !strcmp(argv[i], "-n"))
{
if (++i >= argc || !parseInt(argv[i], &NTIMES))
{
std::cout << "Invalid number of times" << std::endl;
exit(1);
}
}
else if (!strcmp(argv[i], "--float"))
{
useFloat = true;
}
else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
{
std::cout << std::endl;
std::cout << "Usage: ./gpu-stream-cuda [OPTIONS]" << std::endl << std::endl;
std::cout << "Options:" << std::endl;
std::cout << " -h --help Print the message" << std::endl;
std::cout << " --list List available devices" << std::endl;
std::cout << " --device INDEX Select device at INDEX" << std::endl;
std::cout << " -s --arraysize SIZE Use SIZE elements in the array" << std::endl;
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 << std::endl;
exit(0);
}
else
{
std::cout << "Unrecognized argument '" << argv[i] << "' (try '--help')"
<< std::endl;
exit(1);
}
}
}

73
common.h Normal file
View File

@ -0,0 +1,73 @@
#include <iomanip>
#include <iostream>
#include <cstring>
#include <limits>
extern void parseArguments(int argc, char *argv[]);
extern void listDevices(void);
extern int ARRAY_SIZE;
extern int NTIMES;
extern bool useFloat;
extern int deviceIndex;
template < typename T >
void check_solution(void* a_in, void* b_in, void* c_in)
{
// Generate correct solution
T golda = 1.0;
T goldb = 2.0;
T goldc = 0.0;
T * a = static_cast<T*>(a_in);
T * b = static_cast<T*>(b_in);
T * c = static_cast<T*>(c_in);
const T scalar = 3.0;
for (unsigned int i = 0; i < NTIMES; i++)
{
// Double
goldc = golda;
goldb = scalar * goldc;
goldc = golda + goldb;
golda = goldb + scalar * goldc;
}
// Calculate average error
double erra = 0.0;
double errb = 0.0;
double errc = 0.0;
for (unsigned int i = 0; i < ARRAY_SIZE; i++)
{
erra += fabs(a[i] - golda);
errb += fabs(b[i] - goldb);
errc += fabs(c[i] - goldc);
}
erra /= ARRAY_SIZE;
errb /= ARRAY_SIZE;
errc /= ARRAY_SIZE;
double epsi = std::numeric_limits<T>::epsilon() * 100;
if (erra > epsi)
std::cout
<< "Validation failed on a[]. Average error " << erra
<< std::endl;
if (errb > epsi)
std::cout
<< "Validation failed on b[]. Average error " << errb
<< std::endl;
if (errc > epsi)
std::cout
<< "Validation failed on c[]. Average error " << errc
<< std::endl;
}
#define VERSION_STRING "0.0"