forked from krrishnarraj/clpeak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute_short.cpp
143 lines (105 loc) · 4.38 KB
/
compute_short.cpp
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
#include <clpeak.h>
int clPeak::runComputeShort(cl::CommandQueue &queue, cl::Program &prog, device_info_t &devInfo)
{
float timed, gflops;
cl_uint workPerWI;
cl::NDRange globalSize, localSize;
cl_short A = 4;
uint iters = devInfo.computeIters;
if (!isComputeShort)
return 0;
try
{
log->print(NEWLINE TAB TAB "Integer short (16bit) compute (GIOPS)" NEWLINE);
log->xmlOpenTag("integer_compute_short");
log->xmlAppendAttribs("unit", "giops");
cl::Context ctx = queue.getInfo<CL_QUEUE_CONTEXT>();
uint64_t globalWIs = (devInfo.numCUs) * (devInfo.computeWgsPerCU) * (devInfo.maxWGSize);
uint64_t t = std::min((globalWIs * sizeof(cl_short)), devInfo.maxAllocSize) / sizeof(cl_short);
globalWIs = roundToMultipleOf(t, devInfo.maxWGSize);
cl::Buffer outputBuf = cl::Buffer(ctx, CL_MEM_WRITE_ONLY, (globalWIs * sizeof(cl_short)));
globalSize = globalWIs;
localSize = devInfo.maxWGSize;
cl::Kernel kernel_v1(prog, "compute_short_v1");
kernel_v1.setArg(0, outputBuf), kernel_v1.setArg(1, A);
cl::Kernel kernel_v2(prog, "compute_short_v2");
kernel_v2.setArg(0, outputBuf), kernel_v2.setArg(1, A);
cl::Kernel kernel_v4(prog, "compute_short_v4");
kernel_v4.setArg(0, outputBuf), kernel_v4.setArg(1, A);
cl::Kernel kernel_v8(prog, "compute_short_v8");
kernel_v8.setArg(0, outputBuf), kernel_v8.setArg(1, A);
cl::Kernel kernel_v16(prog, "compute_short_v16");
kernel_v16.setArg(0, outputBuf), kernel_v16.setArg(1, A);
///////////////////////////////////////////////////////////////////////////
// Vector width 1
if (!forceTest || strcmp(specifiedTestName, "short") == 0)
{
log->print(TAB TAB TAB "short : ");
workPerWI = 2048; // Indicates integer operations executed per work-item
timed = run_kernel(queue, kernel_v1, globalSize, localSize, iters);
gflops = (static_cast<float>(globalWIs) * static_cast<float>(workPerWI)) / timed / 1e3f;
log->print(gflops);
log->print(NEWLINE);
log->xmlRecord("short", gflops);
}
///////////////////////////////////////////////////////////////////////////
// Vector width 2
if (!forceTest || strcmp(specifiedTestName, "short2") == 0)
{
log->print(TAB TAB TAB "short2 : ");
workPerWI = 2048;
timed = run_kernel(queue, kernel_v2, globalSize, localSize, iters);
gflops = (static_cast<float>(globalWIs) * static_cast<float>(workPerWI)) / timed / 1e3f;
log->print(gflops);
log->print(NEWLINE);
log->xmlRecord("short2", gflops);
}
///////////////////////////////////////////////////////////////////////////
// Vector width 4
if (!forceTest || strcmp(specifiedTestName, "short4") == 0)
{
log->print(TAB TAB TAB "short4 : ");
workPerWI = 2048;
timed = run_kernel(queue, kernel_v4, globalSize, localSize, iters);
gflops = (static_cast<float>(globalWIs) * static_cast<float>(workPerWI)) / timed / 1e3f;
log->print(gflops);
log->print(NEWLINE);
log->xmlRecord("short4", gflops);
}
///////////////////////////////////////////////////////////////////////////
// Vector width 8
if (!forceTest || strcmp(specifiedTestName, "short8") == 0)
{
log->print(TAB TAB TAB "short8 : ");
workPerWI = 2048;
timed = run_kernel(queue, kernel_v8, globalSize, localSize, iters);
gflops = (static_cast<float>(globalWIs) * static_cast<float>(workPerWI)) / timed / 1e3f;
log->print(gflops);
log->print(NEWLINE);
log->xmlRecord("short8", gflops);
}
///////////////////////////////////////////////////////////////////////////
// Vector width 16
if (!forceTest || strcmp(specifiedTestName, "short16") == 0)
{
log->print(TAB TAB TAB "short16 : ");
workPerWI = 2048;
timed = run_kernel(queue, kernel_v16, globalSize, localSize, iters);
gflops = (static_cast<float>(globalWIs) * static_cast<float>(workPerWI)) / timed / 1e3f;
log->print(gflops);
log->print(NEWLINE);
log->xmlRecord("short16", gflops);
}
///////////////////////////////////////////////////////////////////////////
log->xmlCloseTag(); // integer_compute
}
catch (cl::Error &error)
{
stringstream ss;
ss << error.what() << " (" << error.err() << ")" NEWLINE
<< TAB TAB TAB "Tests skipped" NEWLINE;
log->print(ss.str());
return -1;
}
return 0;
}