-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.h
executable file
·77 lines (58 loc) · 2.08 KB
/
vector.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
template <class T>
class Vector_h;
template <class T>
class Vector_d;
// host vector
template <class T>
class Vector_h: public thrust::host_vector<T> {
public:
// Constructors
Vector_h() {}
inline Vector_h(int N) : thrust::host_vector<T>(N) {}
inline Vector_h(int N, T v) : thrust::host_vector<T>(N,v) {}
inline Vector_h(const Vector_h<T>& a) : thrust::host_vector<T>(a) {}
inline Vector_h(const Vector_d<T>& a) : thrust::host_vector<T>(a) {}
template< typename OtherVector >
inline void copy( const OtherVector &a ) {
this->assign( a.begin( ), a.end( ) );
}
inline Vector_h<T>& operator=(const Vector_h<T> &a) { copy(a); return *this; }
inline Vector_h<T>& operator=(const Vector_d<T> &a) { copy(a); return *this; }
inline T* raw() {
if(bytes()>0) return thrust::raw_pointer_cast(this->data());
else return 0;
}
inline const T* raw() const {
if(bytes()>0) return thrust::raw_pointer_cast(this->data());
else return 0;
}
inline size_t bytes() const { return this->size()*sizeof(T); }
};
// device vector
template <class T>
class Vector_d: public thrust::device_vector<T> {
public:
Vector_d() {}
inline Vector_d(int N) : thrust::device_vector<T>(N) {}
inline Vector_d(int N, T v) : thrust::device_vector<T>(N,v) {}
inline Vector_d(const Vector_d<T>& a) : thrust::device_vector<T>(a) {}
inline Vector_d(const Vector_h<T>& a) : thrust::device_vector<T>(a) {}
template< typename OtherVector >
inline void copy( const OtherVector &a ) {
this->assign( a.begin( ), a.end( ) );
}
inline Vector_d<T>& operator=(const Vector_d<T> &a) { copy(a); return *this; }
inline Vector_d<T>& operator=(const Vector_h<T> &a) { copy(a); return *this; }
inline T* raw() {
if(bytes()>0) return thrust::raw_pointer_cast(this->data());
else return 0;
}
inline const T* raw() const {
if(bytes()>0) return thrust::raw_pointer_cast(this->data());
else return 0;
}
inline size_t bytes() const { return this->size()*sizeof(T); }
};