ASL 0.1.7
Advanced Simulation Library
testASLData.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
28#include "acl/acl.h"
29#include "acl/aclGenerators.h"
32#include "aslGenerators.h"
33#include "aslUtilities.h"
38
39using namespace acl;
40using namespace asl;
41using namespace std;
42
44{
45 Block bl(makeAVec(10,5),0.1);
46 auto a(generateDataContainerACL_SP<double>(bl,1,1));
47 auto b(generateDataContainerACL_SP<double>(bl,1,1));
48
49 Kernel k;
50
51 k<<(a->getEContainer()=acl::generateVEConstant<double>(0));
52 k<<(b->getEContainer()=acl::generateVEConstant<double>(0));
53
54 k.setup();
55 cout<<k.getKernelSource ()<<endl;
56
57 return true;
58}
59
60
62{
63 Block bl(makeAVec(10,5),0.1);
64 auto a(generateDataContainerACL_SP<double>(bl, 1, 1));
65
66 initData(a->getEContainer(),acl::generateVEConstant<double>(0));
67
68 return true;
69}
70
71
73{
74 cout << "Test of UploadToLocalMem()..." << flush;
75
76 unsigned int componentsNum = 2;
77 unsigned int groupSize = 27;
79 kConf.local = true;
80 Kernel kernel(kConf);
81 Element groupID(new GroupID());
82 Element c0(new Constant<cl_uint>(0));
83
84 asl::AVec<int> totalDimensions(asl::makeAVec(10, 10, 10));
85 // dx = 1
86 asl::Block block(totalDimensions, 1);
87
88 // boundary = 0
89 auto source(asl::generateDataContainerACL_SP<float>(block,
90 componentsNum,
91 0u));
92 // initialize source with value "13"
93 acl::initData(source->getEContainer(), acl::generateVEConstantN(componentsNum,
94 13));
95
96 // boundary = 0
97 auto destination(asl::generateDataContainerACL_SP<float>(block,
98 componentsNum,
99 0u));
100 // initialize source with value "27"
101 acl::initData(destination->getEContainer(), acl::generateVEConstantN(componentsNum,
102 27));
103
104
105 asl::AVec<int> portionDimensions(asl::makeAVec(5, 5, 5));
106
107 unsigned int portionSize = productOfElements(portionDimensions);
108 unsigned int totalSize = productOfElements(totalDimensions);
109 unsigned int groupsNumber = totalSize / portionSize;
110 Element cPortionSize(new Constant<cl_uint>(portionSize));
111 kernel.setGroupsNumber(groupsNumber);
112
113 VectorOfElements localSource(componentsNum);
114 copy(uploadToLocalMem(*source, portionDimensions, groupSize, kernel), localSource);
115
116 using namespace elementOperators;
117 kernel.addExpression(barrier("CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE"));
118 // overwrite destination with localSource
119 for (unsigned int i = 0; i < componentsNum; ++i)
120 kernel.addExpression(syncCopy(localSource[i], destination->getEContainer()[i],
121 c0, cPortionSize * groupID, cPortionSize));
122
123 kernel.setup();
124 kernel.compute();
125
126
127 bool status(true);
128 vector<cl_float> src(totalSize);
129 vector<cl_float> dst(totalSize);
130 for (unsigned int i = 0; i < componentsNum; ++i)
131 {
132 copy(source->getEContainer()[i], src);
133 copy(destination->getEContainer()[i], dst);
134
135 cout << src << endl << endl << dst << endl;
136
137 status &= (src == dst);
138 }
139
140 errorMessage(status);
141
142 return status;
143}
144
145int main()
146{
147 bool allTestsPassed(true);
148
149 allTestsPassed &= testSimpleKernel();
150 allTestsPassed &= testInitData();
151 allTestsPassed &= testUploadToLocalMem();
152
153 return allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE;
154}
useful common utilities
void copy(const ComplexNumOfElements &source, ComplexNumOfElements &destination)
function copies the ComplexNumOfElements class.
void addExpression(Element expression_)
ACL Kernel configuration class.
OpenCl Kernel generator.
Definition: aclKernel.h:49
std::string getKernelSource()
void setGroupsNumber(unsigned int n)
void setup()
void compute()
The class represents several Element.
void initData(VectorOfElements a, VectorOfElements initializationValue, const KernelConfiguration &kernelConfig)
AVec< T > makeAVec(T a1)
acl::VectorOfElements uploadToLocalMem(AbstractData &source, const AVec< int > &size, unsigned int groupSize, acl::Kernel &kernel)
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
const KernelConfiguration KERNEL_BASIC
void initData(Element a, Element initializationValue, const KernelConfiguration &kernelConfig=KERNEL_BASIC)
Element syncCopy(Element source, Element destination, Element srcOffset, Element dstOffset, Element length)
Element barrier(std::string flags="CLK_LOCAL_MEM_FENCE")
VectorOfElements productOfElements(const VectorOfElements &a, const VectorOfElements &b)
VectorOfElements generateVEConstantN(unsigned int n, T a)
Generates VectorOfElements with n Elements acl::Constant with values a.
Advanced Computational Language.
Definition: acl.h:41
std::shared_ptr< ElementBase > Element
Definition: acl.h:49
Advanced Simulation Library.
Definition: aslDataInc.h:31
AVec< T > makeAVec(T a1)
cl_int flush(void)
Definition: cl.hpp:7042
STL namespace.
bool testInitData()
Definition: testASLData.cc:61
bool testSimpleKernel()
Definition: testASLData.cc:43
bool testUploadToLocalMem()
Definition: testASLData.cc:72
int main()
Definition: testASLData.cc:145
const acl::KernelConfiguration & kConf(acl::KERNEL_BASIC)