| 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 |
|
| 24 |
/** |
| 25 |
\example testKernelMerger.cc |
| 26 |
*/ |
| 27 |
|
| 28 |
|
| 29 |
#include "acl/acl.h" |
| 30 |
#include "acl/DataTypes/aclConstant.h" |
| 31 |
#include "acl/DataTypes/aclArray.h" |
| 32 |
#include "acl/Kernels/aclKernel.h" |
| 33 |
#include "acl/Kernels/aclKernelMerger.h" |
| 34 |
#include "aslUtilities.h" |
| 35 |
#include <math.h> |
| 36 |
#include <initializer_list> |
| 37 |
|
| 38 |
using namespace acl; |
| 39 |
using namespace std; |
| 40 |
|
| 41 |
bool testKernelMerger() |
| 42 |
{ |
| 43 |
cout << "Test of \"KernelMerger\" functionality..." << flush; |
| 44 |
ElementData vec0(new Array<cl_float> (10)); |
| 45 |
ElementData vec1(new Array<cl_float> (5)); |
| 46 |
ElementData vec2(new Array<cl_float> (8)); |
| 47 |
ElementData vec3(new Array<cl_float> (20)); |
| 48 |
|
| 49 |
Element c0(new Constant<cl_double>(2)); |
| 50 |
Element c1(new Constant<cl_double>(1)); |
| 51 |
Element c2(new Constant<cl_double>(4)); |
| 52 |
Element c3(new Constant<cl_double>(7)); |
| 53 |
|
| 54 |
SPKernel k0(new Kernel()); |
| 55 |
SPKernel k1(new Kernel()); |
| 56 |
SPKernel k2(new Kernel()); |
| 57 |
SPKernel k3(new Kernel()); |
| 58 |
{ |
| 59 |
using namespace elementOperators; |
| 60 |
k0->addExpression(operatorAssignment (vec0, c0)); |
| 61 |
k1->addExpression(operatorAssignment (vec1, c1)); |
| 62 |
k2->addExpression(operatorAssignment (vec2, c2)); |
| 63 |
k3->addExpression(operatorAssignment (vec3, c3)); |
| 64 |
} |
| 65 |
|
| 66 |
KernelMerger km; |
| 67 |
km.addKernel(k0); |
| 68 |
km.addKernel(k1); |
| 69 |
km.addKernel(k2); |
| 70 |
// km.addKernel(k3); |
| 71 |
|
| 72 |
km.setup(); |
| 73 |
km.compute(); |
| 74 |
|
| 75 |
bool status((acl::map<float>(vec0).get()[9] == 2) && |
| 76 |
(acl::map<float>(vec1).get()[3] == 1) && |
| 77 |
(acl::map<float>(vec2).get()[7] == 4));// && |
| 78 |
// (acl::map<float>(vec3).get()[19] == 7)); |
| 79 |
errorMessage(status); |
| 80 |
cout << km.getKernelSource() << endl; |
| 81 |
return status; |
| 82 |
} |
| 83 |
|
| 84 |
int main() |
| 85 |
{ |
| 86 |
bool allTestsPassed(true); |
| 87 |
|
| 88 |
allTestsPassed &= testKernelMerger(); |
| 89 |
|
| 90 |
return allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE; |
| 91 |
} |