Add cuda constructor declaration and error checking function
This commit is contained in:
parent
6169bdb7b5
commit
03b01e190f
@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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();
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user