| 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 testVectorOfElements.cc |
| 26 |
*/ |
| 27 |
|
| 28 |
#include "acl/acl.h" |
| 29 |
#include "utilities/aslUValue.h" |
| 30 |
#include "acl/aclGenerators.h" |
| 31 |
#include "acl/Kernels/aclKernel.h" |
| 32 |
#include <acl/aclMath/aclVectorOfElements.h> |
| 33 |
#include "aslUtilities.h" |
| 34 |
#include <math.h> |
| 35 |
|
| 36 |
using namespace asl; |
| 37 |
using namespace acl; |
| 38 |
using namespace std; |
| 39 |
|
| 40 |
bool testSimpleKernel() |
| 41 |
{ |
| 42 |
cout << "Test of \"Simple kernel\" function..." << flush; |
| 43 |
|
| 44 |
VectorOfElements vec0(3); |
| 45 |
VectorOfElements vec1(1); |
| 46 |
copy(generateVEData<float>(10u,3u),vec0); |
| 47 |
copy(generateVEData<float>(10u,1u),vec1); |
| 48 |
|
| 49 |
Kernel k; |
| 50 |
{ |
| 51 |
using namespace elementOperators; |
| 52 |
k << (vec0=generateVEConstant(0.1f,1.f,2.f)); |
| 53 |
k << (vec1=generateVEConstant(0.f,1.f,2.f)*vec0+generateVEConstant(1.f)); |
| 54 |
} |
| 55 |
k.setup(); |
| 56 |
k.compute(); |
| 57 |
|
| 58 |
vector<cl_float> output0(10), output1(10), output2(10); |
| 59 |
vector<cl_float> output3(10); |
| 60 |
copy(vec0[0], output0); |
| 61 |
copy(vec0[1], output1); |
| 62 |
copy(vec0[2], output2); |
| 63 |
copy(vec1[0], output3); |
| 64 |
|
| 65 |
bool status(output0[9]<0.101 && output1[2] ==1 && output2[5] ==2. && output3[1] ==6.); |
| 66 |
errorMessage(status); |
| 67 |
|
| 68 |
return status; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
bool testAdvancedOperations() |
| 73 |
{ |
| 74 |
cout << "Test of advanced operations..." << flush; |
| 75 |
VectorOfElements vec0(2); |
| 76 |
VectorOfElements vec1(2); |
| 77 |
VectorOfElements res(2); |
| 78 |
VectorOfElements ind(1); |
| 79 |
VectorOfElements c(1); |
| 80 |
|
| 81 |
asl::UValue<cl_int> v0(7); |
| 82 |
asl::UValue<cl_int> v1(8); |
| 83 |
copy(generateVEConstant(3, 4), vec0); |
| 84 |
copy(generateVEVariableSP(v0.p, v1.p), vec1); |
| 85 |
copy(generateVEData<int>(11, 2), res); |
| 86 |
copy(generateVEIndex(), ind); |
| 87 |
copy(generateVEConstant(5), c); |
| 88 |
|
| 89 |
vector<cl_int> output0(11, 0); |
| 90 |
vector<cl_int> output1(11, 3); |
| 91 |
vector<cl_int> expected0({10, 10, 10, 10, 10, 10, -4, -4, -4, -4, -4}); |
| 92 |
vector<cl_int> expected1({12, 12, 12, 12, 12, 12, -4, -4, -4, -4, -4}); |
| 93 |
|
| 94 |
|
| 95 |
Kernel k; |
| 96 |
{ |
| 97 |
k << (res = select(vec0 + vec1, vec0 - vec1, ind > c)); |
| 98 |
} |
| 99 |
k.setup(); |
| 100 |
k.compute(); |
| 101 |
|
| 102 |
copy(res[0], output0); |
| 103 |
copy(res[1], output1); |
| 104 |
|
| 105 |
bool status(output0 == expected0 && output1 == expected1); |
| 106 |
errorMessage(status); |
| 107 |
|
| 108 |
return status; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
int main() |
| 113 |
{ |
| 114 |
bool allTestsPassed(true); |
| 115 |
|
| 116 |
allTestsPassed &= testSimpleKernel(); |
| 117 |
allTestsPassed &= testAdvancedOperations(); |
| 118 |
|
| 119 |
return allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE; |
| 120 |
} |