Add starts of OpenCL implementation
This commit is contained in:
parent
a745ffc724
commit
38e1e3b704
77
src/OCLStream.cpp
Normal file
77
src/OCLStream.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
|
||||
#include "OCLStream.h"
|
||||
|
||||
template <class T>
|
||||
OCLStream<T>::OCLStream(const unsigned int ARRAY_SIZE)
|
||||
{
|
||||
array_size = ARRAY_SIZE;
|
||||
|
||||
// Setup default OpenCL GPU
|
||||
context = cl::Context::getDefault();
|
||||
//queue = cl::CommandQueue::getDefault();
|
||||
|
||||
// Create program
|
||||
|
||||
std::string kernels{R"CLC(
|
||||
|
||||
const double scalar = 3.0;
|
||||
|
||||
kernel void copy(
|
||||
global const double * restrict a,
|
||||
global double * restrict c)
|
||||
{
|
||||
const size_t i = get_global_id(0);
|
||||
c[i] = a[i];
|
||||
}
|
||||
)CLC"};
|
||||
|
||||
std::cout << kernels << std::endl;
|
||||
|
||||
//cl::Program program(kernels);
|
||||
//program.build();
|
||||
|
||||
exit(-1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void OCLStream<T>::copy()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void OCLStream<T>::mul()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void OCLStream<T>::add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void OCLStream<T>::triad()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void OCLStream<T>::write_arrays(const std::vector<T>& a, const std::vector<T>& b, const std::vector<T>& c)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void OCLStream<T>::read_arrays(std::vector<T>& a, std::vector<T>& b, std::vector<T>& c)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
template class OCLStream<float>;
|
||||
template class OCLStream<double>;
|
||||
|
||||
43
src/OCLStream.h
Normal file
43
src/OCLStream.h
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#define CL_HPP_ENABLE_EXCEPTIONS
|
||||
#define CL_HPP_TARGET_OPENCL_VERSION 120
|
||||
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
|
||||
|
||||
#include "cl2.hpp"
|
||||
|
||||
#include "Stream.h"
|
||||
|
||||
template <class T>
|
||||
class OCLStream : public Stream<T>
|
||||
{
|
||||
protected:
|
||||
// Size of arrays
|
||||
unsigned int array_size;
|
||||
|
||||
// Device side pointers to arrays
|
||||
cl::Buffer d_a;
|
||||
cl::Buffer d_b;
|
||||
cl::Buffer d_c;
|
||||
|
||||
// OpenCL objects
|
||||
cl::Context context;
|
||||
cl::CommandQueue queue;
|
||||
|
||||
public:
|
||||
|
||||
OCLStream(const unsigned int);
|
||||
~OCLStream();
|
||||
|
||||
virtual void copy() override;
|
||||
virtual void add() override;
|
||||
virtual void mul() override;
|
||||
virtual void triad() override;
|
||||
|
||||
virtual void write_arrays(const std::vector<T>& a, const std::vector<T>& b, const std::vector<T>& c) override;
|
||||
virtual void read_arrays(std::vector<T>& a, std::vector<T>& b, std::vector<T>& c) override;
|
||||
|
||||
};
|
||||
|
||||
@ -10,7 +10,8 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "Stream.h"
|
||||
#include "CUDAStream.h"
|
||||
|
||||
#include "OCLStream.h"
|
||||
|
||||
|
||||
const unsigned int ARRAY_SIZE = 52428800;
|
||||
@ -45,7 +46,10 @@ void run()
|
||||
Stream<T> *stream;
|
||||
|
||||
// Use the CUDA implementation
|
||||
stream = new CUDAStream<T>(ARRAY_SIZE);
|
||||
//stream = new CUDAStream<T>(ARRAY_SIZE);
|
||||
|
||||
// Use the OpenCL implementation
|
||||
stream = new OCLStream<T>(ARRAY_SIZE);
|
||||
|
||||
stream->write_arrays(a, b, c);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user