ASL 0.1.7
Advanced Simulation Library
testPerformance.cc
Go to the documentation of this file.
1/*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
38#include "acl/acl.h"
39#include "acl/aclHardware.h"
47#include "aslUtilities.h"
48#include "utilities/aslTimer.h"
49#include <math.h>
50#include <fstream>
51
53
54#define ARRAY_SIZE 10000000
55//#define ITERATIONS_NUM 20
56#define TIME_INTERVAL 5 // in seconds
57
58using namespace acl;
59using namespace std;
60
61
62// Operators: +
63template <typename T> inline T testSum(T x1, T x2)
64{
65 using namespace elementOperators;
66 return x1 + x2;
67}
68
69
70// Operators: + (non sequential)
71template <typename T> inline T testSumNonSequential(T x1, T x2)
72{
73 Element index(new Index(ARRAY_SIZE));
74 Element c(new Constant<cl_uint>(17));
75 Element cArraySize(new Constant<cl_uint>(ARRAY_SIZE));
76 using namespace elementOperators;
77 return excerpt(x1 + x2, (index * c) % cArraySize);
78}
79
80
81// Operators: +, -, *, /
82template <typename T> inline T testBasicOperators(T x1, T x2)
83{
84 using namespace elementOperators;
85 return x1 * (x2 + x2) * x1 + (x2 + x1 * x1) * x2 * x1 * x2 * x1 - x1 / x2 +
86 x1 * (x1 + x2) * x1 + (x2 - x1 * x2) * x2 - x1 * x2 * x1 - x2 / x1 +
87 x1 * (x2 + x1) * x1 - (x2 + x1 * x1) * x2 * x1 * x2 * x1 + x1 / x2 -
88 x1 * (x1 + x2) * x2 + (x2 - x1 * x2) * x2 - x1 * x2 * x1 - x2 / x1 +
89 x1 * (x2 + x1) * x1 - (x2 + x1 * x1) * x2 * x1 * x2 * x1 + x1 / x2;
90}
91
92
93// Operators: +, -, *, /, sin, cos, sqrt
94template <typename T> inline T testSpecialOperators(T x1, T x2)
95{
96 using namespace elementOperators;
97 return cos(x1*sin(x2+x2)*x1+sqrt(x2+x1*x1)*x2*sin(x1)*x1*sqrt(x2)*x2*x1*sqrt(x1*x2)-x1/x2);
98}
99
100
101/*
102void print(Glib::KeyFile * keyFile,
103 string deviceName,
104 string key,
105 string value,
106 bool writeToKeyFile)
107{
108 cout << key + ": " + value << endl;
109
110 // Save the output for this device to the performance report file if needed
111 if (writeToKeyFile)
112 {
113 keyFile->set_string((deviceName),
114 key,
115 value);
116 }
117}
118*/
119
120/*
121template <typename T> inline void testKernelPerformance(const KernelConfiguration kernelConfig,
122 const CommandQueue & queue,
123 Glib::KeyFile * keyFile,
124 bool writeToKeyFile)
125{
126 Element arr1(new Array<T>(ARRAY_SIZE, queue));
127 Element arr2(new Array<T>(ARRAY_SIZE, queue));
128 Element arrResult(new Array<T>(ARRAY_SIZE, queue));
129 Element c(new Constant<T>(5));
130
131 string typeStr = typeToStr<T>();
132
133 string kernelConfigStr;
134 if (kernelConfig == KERNEL_BASIC)
135 kernelConfigStr = "KERNEL_BASIC";
136 else
137 if (kernelConfig == KERNEL_SIMD)
138 kernelConfigStr = "KERNEL_SIMD";
139 else
140 if (kernelConfig == KERNEL_SIMDUA)
141 kernelConfigStr = "KERNEL_SIMDUA";
142
143
144 Kernel k(kernelConfig);
145
146 // Initialization of the arrays
147 {
148 using namespace elementOperators;
149 k.addExpression(operatorAssignmentSafe(arr1, c));
150 k.addExpression(operatorAssignmentSafe(arr2, c));
151 }
152 k.compute();
153
154 // Test of sum
155 k.clear();
156 {
157 using namespace elementOperators;
158 k.addExpression(operatorAssignmentSafe(arrResult, testSum(arr1, arr2)));
159 }
160 k.setup();
161
162 asl::Timer timer;
163 unsigned int iterationsNum;
164
165 timer.start();
166 timer.stop();
167 iterationsNum = 0;
168 do
169 {
170 timer.resume();
171 k.compute();
172 ++iterationsNum;
173 timer.stop();
174 }
175 while (timer.getTime() < TIME_INTERVAL);
176
177 print(keyFile,
178 getDeviceName(queue),
179 kernelConfigStr + "---" + typeStr + "---" + "Sum",
180 numToStr((float) iterationsNum / timer.getTime()),
181 writeToKeyFile);
182
183 // Test of non sequential sum (only for non SIMD kernels)
184 if (kernelConfig.vectorWidth == 1)
185 {
186 k.clear();
187 {
188 using namespace elementOperators;
189 k.addExpression(operatorAssignmentSafe(arrResult,
190 testSumNonSequential(arr1, arr2)));
191 }
192 k.setup();
193
194 timer.start();
195 timer.stop();
196 iterationsNum = 0;
197 do
198 {
199 timer.resume();
200 k.compute();
201 ++iterationsNum;
202 timer.stop();
203 }
204 while (timer.getTime() < TIME_INTERVAL);
205
206 print(keyFile,
207 getDeviceName(queue),
208 kernelConfigStr + "---" + typeStr + "---" + "NonSequentialSum",
209 numToStr((float) iterationsNum / timer.getTime()),
210 writeToKeyFile);
211
212 }
213
214 // Test of basic operators
215 k.clear();
216 {
217 using namespace elementOperators;
218 k.addExpression(operatorAssignmentSafe(arrResult,
219 testBasicOperators(arr1, arr2)));
220 }
221 k.setup();
222
223 timer.start();
224 timer.stop();
225 iterationsNum = 0;
226 do
227 {
228 timer.resume();
229 k.compute();
230 ++iterationsNum;
231 timer.stop();
232 }
233 while (timer.getTime() < TIME_INTERVAL);
234
235 print(keyFile,
236 getDeviceName(queue),
237 kernelConfigStr + "---" + typeStr + "---" + "BasicOperators",
238 numToStr((float) iterationsNum / timer.getTime()),
239 writeToKeyFile);
240
241
242 // Test of special operators
243 k.clear();
244 if (arr1->getTypeID() != TYPE_INT)
245 {
246 {
247 using namespace elementOperators;
248 k.addExpression(operatorAssignmentSafe(arrResult,
249 testSpecialOperators(arr1, arr2)));
250 }
251 k.setup();
252
253 timer.start();
254 timer.stop();
255 iterationsNum = 0;
256 do
257 {
258 timer.resume();
259 k.compute();
260 ++iterationsNum;
261 timer.stop();
262 }
263 while (timer.getTime() < TIME_INTERVAL);
264
265 print(keyFile,
266 getDeviceName(queue),
267 kernelConfigStr + "---" + typeStr + "---" + "SpecialOperators",
268 numToStr((float) iterationsNum / timer.getTime()),
269 writeToKeyFile);
270 }
271}
272*/
273
274int main()
275{
276 /*
277 const string FILE_NAME("./PerformanceReport.txt");
278 bool writeToKeyFile = false;
279 bool dumpKeyFile = false;
280
281 Glib::KeyFile *keyFile = new Glib::KeyFile;
282
283 ifstream fileCheck(FILE_NAME);
284 if (fileCheck.good())
285 {
286 keyFile->load_from_file(FILE_NAME);
287 }
288 else
289 {
290 warningMessage("Failed to open " + FILE_NAME + " . Creating new file");
291 keyFile->set_comment("\n Performance test report\n\n");
292 }
293
294
295 for (unsigned int i = 0; i < hardware.queues.size(); ++i)
296 {
297 if (!keyFile->has_group(getDeviceName(hardware.queues[i])))
298 {
299 writeToKeyFile = true;
300 dumpKeyFile = true;
301 }
302
303 cout << "\nDevice: " + getDeviceName(hardware.queues[i]) + "\n" << endl;
304
305 testKernelPerformance<cl_int>(KERNEL_BASIC,
306 hardware.queues[i],
307 keyFile,
308 writeToKeyFile);
309 testKernelPerformance<cl_float>(KERNEL_BASIC,
310 hardware.queues[i],
311 keyFile,
312 writeToKeyFile);
313 if (doublePrecisionSupport(hardware.queues[i]))
314 testKernelPerformance<cl_double>(KERNEL_BASIC,
315 hardware.queues[i],
316 keyFile,
317 writeToKeyFile);
318
319
320 testKernelPerformance<cl_int>(KERNEL_SIMD,
321 hardware.queues[i],
322 keyFile,
323 writeToKeyFile);
324 testKernelPerformance<cl_float>(KERNEL_SIMD,
325 hardware.queues[i],
326 keyFile,
327 writeToKeyFile);
328 if (doublePrecisionSupport(hardware.queues[i]))
329 testKernelPerformance<cl_double>(KERNEL_SIMD,
330 hardware.queues[i],
331 keyFile,
332 writeToKeyFile);
333
334
335 testKernelPerformance<cl_int>(KERNEL_SIMDUA,
336 hardware.queues[i],
337 keyFile,
338 writeToKeyFile);
339 testKernelPerformance<cl_float>(KERNEL_SIMDUA,
340 hardware.queues[i],
341 keyFile,
342 writeToKeyFile);
343 if (doublePrecisionSupport(hardware.queues[i]))
344 testKernelPerformance<cl_double>(KERNEL_SIMDUA,
345 hardware.queues[i],
346 keyFile,
347 writeToKeyFile);
348
349 writeToKeyFile = false;
350 }
351
352 if (dumpKeyFile)
353 {
354 ofstream file;
355 file.open(FILE_NAME, ios::app);
356 if (!file.good())
357 {
358 errorMessage("Opening file " + FILE_NAME + " failed");
359 }
360 else
361 {
362 file << keyFile->to_data();
363 if (!file.good())
364 errorMessage("Writing to file " + FILE_NAME + " failed");
365 }
366 file.close();
367 }
368
369 delete keyFile;
370 */
371 return 0;
372}
useful common utilities
Element sin(Element e)
Element cos(Element e)
VectorOfElements sqrt(const VectorOfElements &a)
VectorOfElements excerpt(const VectorOfElements &source, const VectorOfElements &filter)
Advanced Computational Language.
Definition: acl.h:41
std::shared_ptr< ElementBase > Element
Definition: acl.h:49
STL namespace.
T testSumNonSequential(T x1, T x2)
#define ARRAY_SIZE
T testSpecialOperators(T x1, T x2)
T testBasicOperators(T x1, T x2)
int main()
T testSum(T x1, T x2)