ASL 0.1.7
Advanced Simulation Library
Loading...
Searching...
No Matches
testKernel.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
29#include "acl/acl.h"
44#include "aslUtilities.h"
45#include <math.h>
46#include <initializer_list>
47
49
50
51using namespace acl;
52using namespace std;
53
55{
56 cout << "Test of \"copy\" function..." << flush;
58
59 vector<cl_float> input(10, 3);
60 vector<cl_float> output(10, 1);
61
62 copy(input, vec0);
64
65 bool status(output[3] == 3);
67
68 return status;
69}
70
71
73{
74 cout << "Test of Kernel with double..." << flush;
75
80 Element ind(new Index());
81
82
83 Kernel k;
84 {
85 using namespace elementOperators;
86 k.addExpression(operatorAssignment(vec2, c ));
87 k.addExpression(operatorAssignment(vec0, c + powI(vec2, 3)));
88 k.addExpression(operatorAssignment(vec1, ind));
89 }
90 k.setup();
91 k.compute();
92
93 vector<cl_double> output0(10), output1(10);
94 copy(vec0, output0);
96
97 bool status(output0[9]<10.1 && output1[2]>2-1e-4 && output1[3]<3+1e-4);
99
100 return status;
101}
102
103
105{
106 cout << "Test of KernelSIMD..." << flush;
107
110
111 vector<cl_float> input0(11, 3);
112 vector<cl_float> input1(11, 5);
113 vector<cl_float> output(11, 0);
114 vector<cl_float> expected({8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8});
115 copy(input0, vec0);
116 copy(input1, vec1);
117
119 {
120 using namespace elementOperators;
121 k.addExpression(operatorAssignmentSafe(vec1, vec0 + vec1));
122 }
123
124 k.setup();
125
126 k.compute();
127 copy(vec1, output);
128
129 bool status(output == expected);
131
132 return status;
133}
134
135
137{
138 cout << "Test of KernelSIMDUA..." << flush;
139
140 Element vec0(new Array<cl_float> (11));
141 Element vec1(new Array<cl_float> (11));
142
143 vector<cl_float> input0(11, 3);
144 vector<cl_float> input1(11, 5);
145 vector<cl_float> output(11, 0);
146 vector<cl_float> expected({8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8});
147 copy(input0, vec0);
148 copy(input1, vec1);
149
151// kConf.extensions.push_back("cl_amd_printf");
152 Kernel k(kConf);
153 {
154 using namespace elementOperators;
155 k.addExpression(operatorAssignmentSafe(vec1, vec0 + vec1));
156// k.addExpression(printfFunction("\"index: %d\\n\", index"));
157 }
158
159 k.setup();
160
161 k.compute();
162 copy(vec1, output);
163
164 bool status(output == expected);
166
167 return status;
168}
169
170
172{
173 cout << "Test of kernel with PrivateVariable..." << flush;
174
178
179 vector<cl_float> input1(10, 3);
180 vector<cl_float> input2(10, 5);
181 vector<cl_float> output(10, 1);
182
183 copy(input1, vec0);
184 copy(input2, vec1);
185
186 Kernel k;
187 {
188 using namespace elementOperators;
189 k.addExpression(operatorAssignment(loc, vec0 + vec1));
190 k.addExpression(operatorAssignment(vec1, vec0 - vec1));
191 k.addExpression(operatorAssignment(vec0, loc));
192 }
193 k.setup();
194
195 k.compute();
196 copy(vec0, output);
197
198
199 bool status(output[2] ==8.);
201
202 return status;
203}
204
205
207{
208 cout << "Test of kernel with PrivateArray..." << flush;
209
210 vector<cl_int> inputGaIn({0, 4, 5});
211 vector<cl_float> inputGaOut(3, 0);
212 vector<cl_float> inputPa({-9, 2, 0, 15, 1, 3});
213 vector<cl_float> output(3);
214 vector<cl_float> expected({-9, 1, 3});
215
216 Element gaIn(new Array<cl_int>(3));
219 shared_ptr<ElementExcerpt> ex(new ElementExcerpt(pa, gaIn));
220
222
223
224 Kernel k;
225 {
226 using namespace elementOperators;
227 k.addExpression(operatorAssignment(gaOut, ex));
228 }
229 k.setup();
230
231 k.compute();
232 copy(gaOut, output);
233
234
235 bool status(output == expected);
237
238 return status;
239}
240
241
243{
244 cout << "Test of Variable functionality..." << flush;
245
246 Element vec0(new Array<cl_float> (10));
247 shared_ptr<Variable<cl_float> > a(new Variable<cl_float> (1.));
248
249 vector<cl_float> output(10, 1);
250
251 Kernel k;
252
254 k.setup();
255
256 k.compute();
257 a->setValue(10.);
258 k.compute();
259 copy(vec0, output);
260
261 bool status(output[2] ==10.);
263
264 return status;
265}
266
268{
269 cout << "Test of VariableReference functionality..." << flush;
270
271 Element vec0(new Array<cl_float> (10));
272 float v(1.);
274
275 vector<cl_float> output(10, 1);
276
277 Kernel k;
278
280 k.setup();
281
282 k.compute();
283 v=10.;
284 k.compute();
285 copy(vec0, output);
286
287 bool status(output[2] ==10.);
289
290 return status;
291}
292
293
295{
296 cout << "Test of select function..." << flush;
297
298 Element vec0(new Array<cl_double> (10));
299 Element c0(new Constant<cl_double> (2.1));
300
301 vector<cl_double> input(10, 3.);
302 vector<cl_double> output(10, 1.);
303
304 copy(input,vec0);
305
306 Kernel k;
307 {
308 using namespace elementOperators;
309 k.addExpression(operatorAssignment(vec0,
310 select(vec0-c0,
311 vec0*vec0,
312 convert(TYPE_SELECT[TYPE_DOUBLE],
313 vec0 > c0,
314 false))));
315 }
316 k.setup();
317
318 k.compute();
319 copy(vec0, output);
320
321 bool status(output[2] ==9.);
323
324 return status;
325}
326
327
329{
330 cout << "Test of Subvector..." << flush;
331 cl_float init[] = {16, 2, 77, 29, 23, 16, 2, 77, 29, 23};
332 shared_ptr<Array<cl_float> > vec0(new Array<cl_float>(10));
333
334 vector<cl_float> input(init, init + sizeof(init) / sizeof(cl_float) );
335 vector<cl_float> output(2);
336
337 copy(input, vec0);
340
341 bool status(output[0]==16);
343
344 return status;
345}
346
347
349{
350 cout << "Test of Swap functionality..." << flush;
351 shared_ptr<Array<cl_float> > vec0(new Array<cl_float>(10));
352 shared_ptr<Array<cl_float> > vec1(new Array<cl_float>(10));
353
354 vector<cl_float> input0(10, 1);
355 vector<cl_float> input1(10, 2);
356 vector<cl_float> output(10, 10);
357
358 copy(input0, vec0);
359 copy(input1, vec1);
361 copy(vec0, output);
362
363 bool status(output[3] == 2);
365
366 return status;
367}
368
369
371{
372 cout << "Test of LocalArray and syncCopy with barrier()..." << flush;
373
375 kConf.local = true;
376
377 unsigned int groupsNumber = 5;
378 unsigned int groupSize = 2;
379
380 Element vec0(new Array<cl_float>(groupSize * groupsNumber));
381 Element vec1(new Array<cl_float>(groupSize * groupsNumber));
384 Element groupID(new GroupID());
387
388 vector<cl_float> input0(groupSize * groupsNumber, 3);
389 vector<cl_float> input1(groupSize * groupsNumber, 5);
390 vector<cl_float> output(groupSize * groupsNumber, 0);
391 vector<cl_float> expected({2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
392 copy(input0, vec0);
393 copy(input1, vec1);
394
395 Kernel k(kConf);
396 k.setGroupsNumber(groupsNumber);
397 {
398 using namespace elementOperators;
401 k.addExpression(barrier());
402 k.addExpression(operatorAssignment(loc1, loc1 - loc0));
403 k.addExpression(barrier("CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE"));
405 }
406 k.setup();
407
408
409 k.compute();
410 copy(vec1, output);
411
412 bool status(output == expected);
414
415 return status;
416
417}
418
419
useful common utilities
Global array.
Definition aclArray.h:37
void addExpression(Element expression_)
ACL Kernel configuration class.
OpenCl Kernel generator.
Definition aclKernel.h:49
void setGroupsNumber(unsigned int n)
void setup()
void compute()
Element operatorAssignment(Element e1, Element e2)
SPDataWrapperACLData generateDataContainerACL_SP(const Block &b, unsigned int n=1)
generates pointer to ACL Data field with n components
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
const KernelConfiguration KERNEL_BASIC
const KernelConfiguration KERNEL_SIMD
const KernelConfiguration KERNEL_SIMDUA
Advanced Computational Language.
Definition acl.h:41
void copy(MemBlock &source, T *destination)
@ TYPE_DOUBLE
Definition aclTypes.h:43
const std::vector< TypeID > TYPE_SELECT
contains trasnlation of types necessery for use in the function select
void swapBuffers(std::shared_ptr< Array< T > >a, std::shared_ptr< Array< T > > b)
std::shared_ptr< ElementBase > Element
Definition acl.h:49
STL namespace.
bool testSubvector()
bool testPrivateVariable()
bool testKernelSIMDUA()
bool testSelect()
bool testKernel()
Definition testKernel.cc:72
bool testVariable()
bool testLocalArray()
bool testVariableReference()
bool testKernelSIMD()
bool testPrivateArray()
int main()
bool testSwapBuffers()
bool testCopy()
Definition testKernel.cc:54
const acl::KernelConfiguration & kConf(acl::KERNEL_BASIC)