Add cuda constructor declaration and error checking function

This commit is contained in:
Tom Deakin 2016-04-26 14:49:04 +01:00
parent 6169bdb7b5
commit 03b01e190f
3 changed files with 26 additions and 1 deletions

View File

@ -1,6 +1,24 @@
#include "CUDAStream.h" #include "CUDAStream.h"
void check_error(void)
{
cudaError_t err = cudaGetLastError();
if (err != cudaSuccess)
{
std::cerr << "Error: " << cudaGetErrorString(err) << std::endl;
exit(err);
}
}
template <class T>
CUDAStream<T>::CUDAStream(const unsigned int ARRAY_SIZE)
{
// Create device buffers
cudaMalloc(&d_a, ARRAY_SIZE*sizeof(T));
}
template <typename T> template <typename T>
__global__ void copy_kernel(const T * a, T * c) __global__ void copy_kernel(const T * a, T * c)
{ {

View File

@ -1,4 +1,5 @@
#include <iostream>
#include "Stream.h" #include "Stream.h"
@ -13,6 +14,9 @@ class CUDAStream : public Stream<T>
public: public:
CUDAStream(const unsigned int);
void copy(); void copy();
void add(); void add();
void mul(); void mul();

View File

@ -25,7 +25,10 @@ int main(int argc, char *argv[])
std::vector<double> c(ARRAY_SIZE, 0.0); std::vector<double> c(ARRAY_SIZE, 0.0);
Stream<double> *stream; Stream<double> *stream;
stream = new CUDAStream<double>();
// Use the CUDA implementation
stream = new CUDAStream<double>(ARRAY_SIZE);
stream->copy(); stream->copy();
delete[] stream; delete[] stream;