-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCudaVector.h
61 lines (50 loc) · 1.31 KB
/
CudaVector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include <string>
#define NUM_BLOCKS 1024
#define NUM_THREADS_PER_BLOCK 1024
/**
* Class CudaVector
* ----------------
*
* Handles vector operations such as:
* 1. Addition
* 2. Division
* 3. Subtraction
* 4. Multiplication
*
* All operations are done on GPU without the programmer
* needing to specify how.
*
*/
template <class T>
class CudaVector {
private:
T* _array; // vector array
unsigned long _size; // size of vector array
public:
CudaVector(unsigned long size); // constructor
~CudaVector(); // destructor
/**
* Member Functions
*/
unsigned long size(); // returns size of array
// Operator overloading
T& operator[](unsigned long);
CudaVector<T> operator+(const CudaVector<T>&);
CudaVector<T> operator-(const CudaVector<T>&);
CudaVector<T> operator*(const CudaVector<T>&);
CudaVector<T> operator*(const double&);
CudaVector<T> operator/(const double&);
/**
* Exception Class
*/
class CudaVectorException : public std::exception {
private:
std::string message_;
public:
explicit CudaVectorException(const std::string& message);
const char* what() const noexcept override { return message_.c_str(); }
};
};
// Including here to avoid import errors
#include "CudaVector.cu"