forked from lazarcl/research
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharithmeticTests.h
More file actions
244 lines (170 loc) · 5.83 KB
/
arithmeticTests.h
File metadata and controls
244 lines (170 loc) · 5.83 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#ifndef ARITHMETICTESTS_H
#define ARITHMETICTESTS_H
//mult, add and FMA Kernels work for FP32, FP64, and Int
// without register limiting
//#include <stdio.h>
//------------ EXPERIMENT VOLATILE KERNEL FOR BASEPOWER 2 ---------
template <typename T>
__global__
void addKernel1Volatile(int n, int iterateNum, T *x);
template <typename T>
__global__
void multKernel1_nonVolitile(int n, int iterateNum, T *x);
//------------ BASEPOW1: SET SHARED MEMORY KERNEL ---------
template <typename T>
__global__
void addKernel1_DynamicSharedMem(int n, int iterateNum, T *x);
template <typename T>
__global__
void multKernel_DynamicSharedMem(int n, int iterateNum, T *x);
template <typename T>
__global__
void fmaKernel_DynamicSharedMem(int n, int iterateNum, T *x);
//------------ ADDITION KERNELS ---------
template <typename T>
__global__
void addKernel1(int n, int iterateNum, T *x);
template <typename T>
__global__
void addKernel2(int n, int iterateNum, T *x);
//------------ MULTIPLICATION KERNELS ---------
template <typename T>
__global__
void multKernel1(int n, int iterateNum, T *x);
template <typename T>
__global__
void multKernel2(int n, int iterateNum, T *x);
//------------ FMA KERNELS ---------
template <typename T>
__global__
void fmaKernel1(int n, int iterateNum, T *x);
template <typename T>
__global__
void fmaKernel2(int n, int iterateNum, T *x);
template <typename T>
__global__
void createData(int n, T *x);
//------------ BASE CLASS FOR TESTS TO INHERIT FROM ---------
template <typename T>
class ArithmeticTestBase {
public:
T *d_x;
int n;
int iterNum;
int numBlocks;
int blockSize;
int numBlockScale;
int opsPerIteration; //number of operations in one iteration. Not including loop calculations
ArithmeticTestBase(int blockSize, int iterNum);
ArithmeticTestBase(int blockSize, int iterNum, int numBlockScale);
~ArithmeticTestBase();
void kernelSetup(cudaDeviceProp deviceProp);
//get the number of threads launched in the kernel. Must be
//called after kernelSetup() or the neccisary fields may not be initialized
int getNumThreads();
//return the number of operations that are executed in the kernel's loop
//for the specified number of operations.
//Ex: 6 operations per iteration * 1000000 iterations = 6000000 operations
int getOpsPerThread();
void runKernel();
void CUDA_ERROR(cudaError_t e);
};
//------------ TEST CLASS FOR BASE POWER MEASUREMENT APPR 1 ---------
template <typename T>
class AddKernel1TestSetSharedMem : public ArithmeticTestBase<T> {
public:
unsigned int sharedMemRequest;
float sharedMemScale;
AddKernel1TestSetSharedMem(int blockSize, int iterNum);
AddKernel1TestSetSharedMem(int blockSize, int iterNum, int numBlockScale);
//in addition to normal setup, figure out how much shared memory to request
void kernelSetup(cudaDeviceProp deviceProp);
void setSharedMem(float newScale);
void runKernel();
};
template <typename T>
class MultKernel1TestSetSharedMem : public ArithmeticTestBase<T> {
public:
unsigned int sharedMemRequest;
float sharedMemScale;
MultKernel1TestSetSharedMem(int blockSize, int iterNum);
MultKernel1TestSetSharedMem(int blockSize, int iterNum, int numBlockScale);
//in addition to normal setup, figure out how much shared memory to request
void kernelSetup(cudaDeviceProp deviceProp);
void setSharedMem(float newScale);
void runKernel();
};
template <typename T>
class FMAKernel1TestSetSharedMem : public ArithmeticTestBase<T> {
public:
unsigned int sharedMemRequest;
float sharedMemScale;
FMAKernel1TestSetSharedMem(int blockSize, int iterNum);
FMAKernel1TestSetSharedMem(int blockSize, int iterNum, int numBlockScale);
//in addition to normal setup, figure out how much shared memory to request
void kernelSetup(cudaDeviceProp deviceProp);
void setSharedMem(float newScale);
void runKernel();
};
//------------ TEST CASE FOR BASE POWER APPR 2 ---------
template <typename T>
class AddKernel1TestVolatile : public ArithmeticTestBase<T> {
public:
AddKernel1TestVolatile(int blockSize, int iterNum);
AddKernel1TestVolatile(int blockSize, int iterNum, int numBlockScale);
void runKernel();
};
template <typename T>
class MultKernel1TestNonVolatile : public ArithmeticTestBase<T> {
public:
MultKernel1TestNonVolatile(int blockSize, int iterNum);
MultKernel1TestNonVolatile(int blockSize, int iterNum, int numBlockScale);
void runKernel();
};
//------------ ADDITION TEST CLASSES ---------
template <typename T>
class AddKernel1Test : public ArithmeticTestBase<T> {
public:
//this->opsPerIteration = 6;
AddKernel1Test(int blockSize, int iterNum);
AddKernel1Test(int blockSize, int iterNum, int numBlockScale);
void runKernel();
};
template <typename T>
class AddKernel2Test : public ArithmeticTestBase<T> {
public:
AddKernel2Test(int blockSize, int iterNum);
AddKernel2Test(int blockSize, int iterNum, int numBlockScale);
void runKernel();
};
//------------ MULTIPLICATION TEST CLASSES ---------
template <typename T>
class MultKernel1Test : public ArithmeticTestBase<T> {
public:
MultKernel1Test(int blockSize, int iterNum);
MultKernel1Test(int blockSize, int iterNum, int numBlockScale);
void runKernel();
};
template <typename T>
class MultKernel2Test : public ArithmeticTestBase<T> {
public:
MultKernel2Test(int blockSize, int iterNum);
MultKernel2Test(int blockSize, int iterNum, int numBlockScale);
void runKernel();
};
//------------ FMA TEST CLASSES ---------
template <typename T>
class FmaKernel1Test : public ArithmeticTestBase<T> {
public:
FmaKernel1Test(int blockSize, int iterNum);
FmaKernel1Test(int blockSize, int iterNum, int numBlockScale);
void runKernel();
};
template <typename T>
class FmaKernel2Test : public ArithmeticTestBase<T> {
public:
FmaKernel2Test(int blockSize, int iterNum);
FmaKernel2Test(int blockSize, int iterNum, int numBlockScale);
void runKernel();
};
#endif