-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrunBasePowerTest2.cu
More file actions
159 lines (117 loc) · 5.38 KB
/
runBasePowerTest2.cu
File metadata and controls
159 lines (117 loc) · 5.38 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
#include "testFramework.cu"
#include "arithmeticTests.cu"
#include <string>
#include <sys/stat.h>
#include "testHelpers.h"
#include <tuple>
#include <vector>
/*run command
nvcc runBasePowerTest2.cu -lnvidia-ml
*/
template <typename T>
void runAddTest(int iterNum, int blockSize, int blockSizeScalar,
const char* outputName, float acceptableError)
{
AddKernel1Test<T> test1(blockSize, iterNum, blockSizeScalar);
TestRunner<AddKernel1Test<T>> tester1(&test1, outputName, acceptableError);
tester1.getGoodSample();
tester1.dataToFile();
}
template <typename T>
void runMultTest(int iterNum, int blockSize, int blockSizeScalar,
const char* outputName, float acceptableError)
{
MultKernel1TestNonVolatile<T> test1(blockSize, iterNum, blockSizeScalar);
TestRunner<MultKernel1TestNonVolatile<T>> tester1(&test1, outputName, acceptableError);
tester1.getGoodSample();
tester1.dataToFile();
}
template <typename T>
void runAddTestVolatile(int iterNum, int blockSize, int blockSizeScalar,
const char* outputName, float acceptableError)
{
AddKernel1TestVolatile<T> test1(blockSize, iterNum, blockSizeScalar);
TestRunner<AddKernel1TestVolatile<T>> tester1(&test1, outputName, acceptableError);
tester1.getGoodSample();
tester1.dataToFile();
}
void runClassicBP2WithAddFP32(int argc, char* argv[]) {
int blockSize = 256;
int addIter = config_t.basePow2_iter;
float acceptableError = 1000; //set large so it has no affect
std::string folderPath = setupStoragePath(argc, argv);
printf("---- beginning runs of the 2nd approach to base power measuring. Storing at '%s' ----\n", folderPath.c_str());
for (int blckScalr = 1; blckScalr <= 8; blckScalr++) {
// char outName[100]; // array to hold the result.
// strcpy(result,one); // copy string one into the result.
// strcat(result,two); // append string two to the result.
//if foobar is a string obj. get const char* with: foobar.c_str()
std::string pathName = folderPath + std::string("/outputBlockScalar_");
std::string fileType = ".csv";
std::string numStr = std::to_string(blckScalr);
const char *outName= (pathName + numStr + fileType).c_str();
printf("---- beginning run #%d ----\n", blckScalr);
runMultTest<float>(addIter, blockSize, blckScalr,
(pathName + numStr + fileType).c_str(), acceptableError);
printf("---- test end ----\n");
}
}
template <typename KernelClass>
std::vector< std::tuple<int, float, float> > basePowerTest2_SpecifyKernel() {
//int blockSize = 256;
int blockSize = 50;
int iterNum = config_t.basePow2_iter;
float acceptableError = 1000; //set large so it has no affect
std::vector<std::tuple<int, float, float>> runsVector;
printf("---- beginning runs of the 2nd approach to base power measuring. ----\n");
for (int blckScalr = 1; blckScalr <= 6; blckScalr++) {
for (int testDepth = 1; testDepth <=1; testDepth++) {
printf("---- beginning run #%d ----\n", blckScalr);
KernelClass test1(blockSize, iterNum, blckScalr);
TestRunner<KernelClass> tester1(&test1, "deleteMe.csv", acceptableError);
tester1.getGoodSample();
runsVector.push_back( std::tuple<int, float, float>(blckScalr, (float)tester1.getPowerAvg(), tester1.getElapsedTime()));
printf("---- test end ----\n");
}
}
return runsVector;
}
void basePowVectorToFile(std::vector< std::tuple<int,float,float> > vec, const char* fileName){
FILE *fp = fopen(fileName, "w+");
if (fp == NULL) {
printf("Attempt at opening '%s' failed. Error: ", fileName);
perror("");
printf("Terminating...");
exit(0);
}
fprintf(fp, "runID, avgPower, elapsedTime\n");
for (int i = 0; i < vec.size(); i++){
std::tuple<int,float,float> tup = vec[i];
fprintf(fp, "%d, %.3lf, %.3lf\n", std::get<0>(tup), std::get<1>(tup)/1000.0, std::get<2>(tup)/1000.0);
}
fclose(fp);
}
void runBP2WithAllKernels(std::string storagePath) {
std::vector< std::tuple<int,float,float> > powData;
powData = basePowerTest2_SpecifyKernel<AddKernel1Test<float>>();
basePowVectorToFile(powData, (storagePath + std::string("basePow2_addFloat.csv")).c_str());
powData = basePowerTest2_SpecifyKernel<AddKernel1Test<double>>();
basePowVectorToFile(powData, (storagePath + std::string("basePow2_addDouble.csv")).c_str());
powData = basePowerTest2_SpecifyKernel<AddKernel1Test<int>>();
basePowVectorToFile(powData, (storagePath + std::string("basePow2_addInt.csv")).c_str());
powData = basePowerTest2_SpecifyKernel<MultKernel1Test<int>>();
basePowVectorToFile(powData, (storagePath + std::string("basePow2_multInt.csv")).c_str());
powData = basePowerTest2_SpecifyKernel<MultKernel1Test<float>>();
basePowVectorToFile(powData, (storagePath + std::string("basePow2_multFloat.csv")).c_str());
powData = basePowerTest2_SpecifyKernel<MultKernel1Test<double>>();
basePowVectorToFile(powData, (storagePath + std::string("basePow2_multDouble.csv")).c_str());
powData = basePowerTest2_SpecifyKernel<FmaKernel1Test<float>>();
basePowVectorToFile(powData, (storagePath + std::string("basePow2_fmaFloat.csv")).c_str());
powData = basePowerTest2_SpecifyKernel<FmaKernel1Test<double>>();
basePowVectorToFile(powData, (storagePath + std::string("basePow2_fmaDouble.csv")).c_str());
}
int main(int argc, char *argv[]) {
std::string storagePath = setupStoragePath(argc, argv);
runBP2WithAllKernels(storagePath);
return 0;
}