Browse Source

Measurements

master
Daniel Gyulai 3 years ago
parent
commit
2cc11eff4a
  1. 17
      Common/OpenCLHandler.cpp
  2. 11
      Linear/Jacobi.cpp
  3. 7
      Linear/Large.cpp
  4. 20
      Linear/Linear.cpp
  5. 16
      Linear/LinearTests.h
  6. 7
      Linear/Reduce.cpp
  7. 8
      Linear/Simple.cpp

17
Common/OpenCLHandler.cpp

@ -7,23 +7,32 @@ void OpenCLHandler::printTimeStats(cl::Event& event)
cl_int err = CL_SUCCESS;
event.wait();
cl_ulong execStart, execEnd;
bool success = true;
execStart = event.getProfilingInfo<CL_PROFILING_COMMAND_START>(&err);
if (err != CL_SUCCESS)
{
std::cerr << "Error during profile query: CL_PROFILING_COMMAND_START ["
<< err << "]." << std::endl;
//std::cerr << "Error during profile query: CL_PROFILING_COMMAND_START ["
//<< err << "]." << std::endl;
success = false;
}
execEnd = event.getProfilingInfo<CL_PROFILING_COMMAND_END>(&err);
if (err != CL_SUCCESS)
{
std::cerr << "Error during profile query: CL_PROFILING_COMMAND_END ["
<< err << "]." << std::endl;
//std::cerr << "Error during profile query: CL_PROFILING_COMMAND_END ["
//<< err << "]." << std::endl;
success = false;
}
//std::cout << "[start] " << execStart << " [end] " << execEnd
// << " [time] " << (execEnd - execStart) / 1e+06 << "ms." << std::endl;
if (success){
std::cout << "GPU [time] " << (execEnd - execStart) / 1e+06 << " ms" <<
std::endl;
}
else {
std::cout << "GPU [time] Unavailable" << std::endl;
}
}
OpenCLHandler::OpenCLHandler(std::string kernelcode)
{

11
Linear/Jacobi.cpp

@ -74,9 +74,10 @@ MatrixVectorMultiplier* Jacobi::MethodFactory(MVType type, cl::Context* context,
}
}
Jacobi::Jacobi(MVType _type)
Jacobi::Jacobi(int n, MVType _type)
{
type = _type;
Jn = n;
generateLinEq();
}
@ -88,22 +89,22 @@ void Jacobi::gpu_compute(cl::Context* context, cl::CommandQueue* queue, cl::Prog
{
MatrixVectorMultiplier* MVMultiplier = MethodFactory(type, context, queue, program);
cl_ulong time = 0;
if (MVMultiplier != NULL) {
int inputBuffer = 0;
const int iterations = 20;
for (int i = 0; i < iterations; ++i) {
MVMultiplier->dewIt(Jn, Jn, Jx_g[(inputBuffer + 1) % 2], JA_g, Jx_g[inputBuffer], Jb_g);
printMatrix(1, Jn, Jx_g[inputBuffer]);
time += MVMultiplier->dewIt(Jn, Jn, Jx_g[(inputBuffer + 1) % 2], JA_g, Jx_g[inputBuffer], Jb_g);
inputBuffer = (inputBuffer + 1) % 2;
//printMatrix(1, Jn, Jx_g[inputBuffer]);
}
}
else {
std::cout << "Invalid factory parameter" << std::endl;
exit(-1);
}
std::cout << "Jacobi>" << MVMultiplier->getName() << "@" << Jn << ": " << time / 1e+06 << " ms" << std::endl;
}

7
Linear/Large.cpp

@ -6,9 +6,10 @@ Large::Large(cl::Context* _context, cl::CommandQueue* _queue, cl::Program* _prog
context = _context;
queue = _queue;
program = _program;
name = "Large";
}
void Large::dewIt(int n, int m, float* y, const float* A, const float* x, const float* b)
cl_ulong Large::dewIt(int n, int m, float* y, const float* A, const float* x, const float* b)
{
cl_int err = CL_SUCCESS;
cl::Event _event;
@ -49,6 +50,10 @@ void Large::dewIt(int n, int m, float* y, const float* A, const float* x, const
queue->enqueueNDRangeKernel(kernel, cl::NullRange, cl::NDRange(Z*T, 1), cl::NDRange(T * Z, 1), NULL, &_event);
_event.wait();
cl_ulong execStart, execEnd;
execStart = _event.getProfilingInfo<CL_PROFILING_COMMAND_START>(&err);
execEnd = _event.getProfilingInfo<CL_PROFILING_COMMAND_END>(&err);
queue->enqueueReadBuffer(YBuffer, true, 0, sizeof(float) * n, y);
return (execEnd - execStart);
}

20
Linear/Linear.cpp

@ -60,10 +60,15 @@ int main()
capi();
//cppapi();
OpenCLHandler handler("../kernels/linear.cl");
//Jacobi j(MVType::ReduceMV);
//Jacobi j(MVType::SimpleMV);
//Jacobi j(MVType::LargeMV);
//handler.run_test(&j);
handler.run_test(new Jacobi(64, MVType::SimpleMV));
//handler.run_test(new Jacobi(64, MVType::ReduceMV));
//handler.run_test(new Jacobi(64, MVType::LargeMV));
//for (int n = 256; n <= 1024; n = n * 2) {
// handler.run_test(new Jacobi(n, MVType::SimpleMV));
// handler.run_test(new Jacobi(n, MVType::LargeMV));
//}
int GAn = 4;
int GAm = 3;
@ -77,10 +82,11 @@ int main()
float GB[] = { 2, -1, 0, 1, 0, 0,
-1, 2, -1, 0, 1, 0,
0, -1, 2, 0, 0, 1 };
Gauss g1(GAn, GAm, GA);
Gauss g2(GBn, GBm, GB);
Gauss g(GBn, GBm, GB);
handler.run_test(&g);
//handler.run_test(&g1);
//handler.run_test(&g2);
return 0;
}

16
Linear/LinearTests.h

@ -12,13 +12,17 @@ protected:
cl::Context* context;
cl::CommandQueue* queue;
cl::Program* program;
std::string name;
public:
virtual void dewIt(int n, int m, float* y, const float* A, const float* x, const float* b) = 0;
virtual cl_ulong dewIt(int n, int m, float* y, const float* A, const float* x, const float* b) = 0;
std::string getName() {
return name;
}
};
class Jacobi : public TestCase {
private:
const int Jn = 8;
int Jn;
// CPU
float* Jx_c[2] = { NULL, NULL };
float* JA_c = NULL;
@ -35,7 +39,7 @@ private:
void printMatrix(int n, int m, float* A);
MatrixVectorMultiplier* MethodFactory(MVType type, cl::Context* context, cl::CommandQueue* queue, cl::Program* program);
public:
Jacobi(MVType type);
Jacobi(int n, MVType type);
void collect_results(cl::CommandQueue* queue);
void gpu_compute(cl::Context* context, cl::CommandQueue* queue, cl::Program* program, cl::Event* Event);
void cpu_compute();
@ -61,17 +65,17 @@ public:
class Simple : public MatrixVectorMultiplier {
public:
Simple(cl::Context* context, cl::CommandQueue* queue, cl::Program* program);
void dewIt(int n, int m, float* y, const float* A, const float* x, const float* b);
cl_ulong dewIt(int n, int m, float* y, const float* A, const float* x, const float* b);
};
class Reduce : public MatrixVectorMultiplier {
public:
Reduce(cl::Context* context, cl::CommandQueue* queue, cl::Program* program);
void dewIt(int n, int m, float* y, const float* A, const float* x, const float* b);
cl_ulong dewIt(int n, int m, float* y, const float* A, const float* x, const float* b);
};
class Large : public MatrixVectorMultiplier {
public:
Large(cl::Context* context, cl::CommandQueue* queue, cl::Program* program);
void dewIt(int n, int m, float* y, const float* A, const float* x, const float* b);
cl_ulong dewIt(int n, int m, float* y, const float* A, const float* x, const float* b);
};

7
Linear/Reduce.cpp

@ -6,9 +6,10 @@ Reduce::Reduce(cl::Context* _context, cl::CommandQueue* _queue, cl::Program* _pr
context = _context;
queue = _queue;
program = _program;
name = "Reduce";
}
void Reduce::dewIt(int n, int m, float* y, const float* A, const float* x, const float* b)
cl_ulong Reduce::dewIt(int n, int m, float* y, const float* A, const float* x, const float* b)
{
cl_int err = CL_SUCCESS;
cl::Event _event;
@ -51,6 +52,10 @@ void Reduce::dewIt(int n, int m, float* y, const float* A, const float* x, const
NULL, //
&_event);
_event.wait();
cl_ulong execStart, execEnd;
execStart = _event.getProfilingInfo<CL_PROFILING_COMMAND_START>(&err);
execEnd = _event.getProfilingInfo<CL_PROFILING_COMMAND_END>(&err);
queue->enqueueReadBuffer(YBuffer, true, 0, sizeof(float) * n, y);
return (execEnd - execStart);
}

8
Linear/Simple.cpp

@ -6,13 +6,15 @@ Simple::Simple(cl::Context* _context, cl::CommandQueue* _queue, cl::Program* _pr
context = _context;
queue = _queue;
program = _program;
name = "Simple";
}
void Simple::dewIt(int n, int m, float* y, const float* A, const float* x, const float* b)
cl_ulong Simple::dewIt(int n, int m, float* y, const float* A, const float* x, const float* b)
{
cl_int err = CL_SUCCESS;
cl::Event _event;
cl::Kernel kernel = cl::Kernel(*program, "simpleMV", &err);
CheckCLError(err);
@ -46,6 +48,10 @@ void Simple::dewIt(int n, int m, float* y, const float* A, const float* x, const
NULL, //
&_event);
_event.wait();
cl_ulong execStart, execEnd;
execStart = _event.getProfilingInfo<CL_PROFILING_COMMAND_START>(&err);
execEnd = _event.getProfilingInfo<CL_PROFILING_COMMAND_END>(&err);
queue->enqueueReadBuffer(YBuffer, true, 0, sizeof(float) * n, y);
return (execEnd - execStart);
}

Loading…
Cancel
Save