forked from ZaidQureshi/bam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbafs_ptr.h
147 lines (122 loc) · 3.84 KB
/
bafs_ptr.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef __BAFS_PTR_H__
#define __BAFS_PTR_H__
#ifndef __device__
#define __device__
#endif
#ifndef __host__
#define __host__
#endif
#ifndef __forceinline__
#define __forceinline__ inline
#endif
#include "page_cache.h"
#include <cstdint>
template<typename T>
class bafs_ptr {
private:
array_t<T>* h_pData;
array_d_t<T>* pData;
uint64_t start_idx;
public:
__host__
void print_stats() const {
if (h_pData)
h_pData->print_reset_stats();
}
__host__ __device__ bafs_ptr():
h_pData(NULL), pData(NULL),start_idx(0){
}
// __host__ __device__ bafs_ptr(array_d_t<T>* const pValue):
// h_pData(NULL), pData(pValue),start_idx(0){
// }
__host__ __device__ bafs_ptr(array_d_t<T>* const pValue, const uint64_t start_off):
h_pData(NULL), pData(pValue),start_idx(start_off){
}
__host__ __device__ bafs_ptr(array_t<T>* const pValue):
h_pData(pValue), pData(pValue->d_array_ptr),start_idx(0){
}
__host__ __device__ bafs_ptr(array_t<T>* const pValue, const uint64_t start_off):
h_pData(pValue), pData(pValue->d_array_ptr),start_idx(start_off){
}
__host__ __device__ ~bafs_ptr(){}
__host__ __device__ bafs_ptr(const bafs_ptr &var){
h_pData = var.h_pData;
pData = var.pData;
start_idx = var.start_idx;
}
__device__ T operator*(){
return (*pData)[start_idx];
}
__host__ __device__ bafs_ptr<T>& operator=(const bafs_ptr<T>& obj) {
if(*this == obj)
return *this;
else{
this->h_pData = obj.h_pData;
this->pData = obj.pData;
this->start_idx = obj.start_idx;
}
return *this;
}
template<typename T_>
friend __host__ __device__ bool operator==(const bafs_ptr<T_>& lhs, const bafs_ptr<T_>& rhs);
// template<typename T_>
// friend __host__ __device__ bool operator==(bafs_ptr<T>* lhs, const bafs_ptr<T_>& rhs);
__host__ __device__ void operator()(const uint64_t i, const T val) {
(*pData)(i, val);
}
__host__ __device__ T operator[](const uint64_t i) {
return (*pData)[start_idx+i];
}
__host__ __device__ const T operator[](const uint64_t i) const {
return (*pData)[start_idx+i];
}
__host__ __device__ bafs_ptr<T> operator+(const uint64_t i){
uint64_t new_start_idx = this->start_idx+i;
return bafs_ptr<T>(this->pData, new_start_idx);
}
__host__ __device__ bafs_ptr<T> operator-(const uint64_t i){
uint64_t new_start_idx = this->start_idx-i;
return bafs_ptr<T>(this->pData, new_start_idx);
}
//posfix operator
__host__ __device__ bafs_ptr<T> operator++(int){
bafs_ptr<T> cpy = *this;
this->start_idx += 1;
return cpy;
}
//prefix operator
__host__ __device__ bafs_ptr<T>& operator++(){
this->start_idx += 1;
return *this;
}
//posfix operator
__host__ __device__ bafs_ptr<T> operator--(int){
bafs_ptr<T> cpy = *this;
this->start_idx -= 1;
return cpy;
}
//prefix operator
__host__ __device__ bafs_ptr<T>& operator--(){
this->start_idx -= 1;
return *this;
}
__host__ __device__ void memcpy_to_array_aligned(const uint64_t src_idx, const uint64_t count, T* dest) const {
pData->memcpy(src_idx, count, dest);
}
};
template<typename T_>
__host__ __device__
bool operator==(const bafs_ptr<T_>& lhs, const bafs_ptr<T_>& rhs){
return (lhs.pData == rhs.pData && lhs.start_idx == rhs.start_idx && lhs.h_pData == rhs.h_pData);
}
// template<typename T_>
// __host__ __device__
// bool operator==(bafs_ptr<T_>* lhs, const bafs_ptr<T_>& rhs){
// return (lhs->pData == rhs.pData && lhs->start_idx == rhs.start_idx);
// }
//#ifndef __CUDACC__
//#undef __device__
//#undef __host__
//#undef __forceinline__
//#endif
#endif //__BAFS_PTR_H__