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"
34 #include "acl/Kernels/aclKernel.h"
35 #include "data/aslDataUtilities.h"
38 
39 using namespace acl;
40 using namespace asl;
41 using 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 
145 int 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 }
acl::VectorOfElements uploadToLocalMem(AbstractData &source, const AVec< int > &size, unsigned int groupSize, acl::Kernel &kernel)
Advanced Simulation Library.
Definition: aslDataInc.h:30
void setGroupsNumber(unsigned int n)
Advanced Computational Language.
Definition: acl.h:40
Element barrier(std::string flags="CLK_LOCAL_MEM_FENCE")
AVec< T > makeAVec(T a1)
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
std::string getKernelSource()
bool testSimpleKernel()
Definition: testASLData.cc:43
OpenCl Kernel generator.
Definition: aclKernel.h:48
T productOfElements(const AVec< T > &a)
bool testUploadToLocalMem()
Definition: testASLData.cc:72
void addExpression(Element expression_)
cl_int flush(void)
Definition: cl.hpp:7042
The class represents several Element.
bool testInitData()
Definition: testASLData.cc:61
ACL Kernel configuration class.
std::shared_ptr< ElementBase > Element
Definition: acl.h:49
const acl::KernelConfiguration & kConf(acl::KERNEL_BASIC)
VectorOfElements generateVEConstantN(unsigned int n, T a)
Generates VectorOfElements with n Elements acl::Constant with values a.
int main()
Definition: testASLData.cc:145
useful common utilities
void copy(MemBlock &source, T *destination)
void compute()
void initData(Element a, Element initializationValue, const KernelConfiguration &kernelConfig=KERNEL_BASIC)
Element syncCopy(Element source, Element destination, Element srcOffset, Element dstOffset, Element length)
const KernelConfiguration KERNEL_BASIC
void setup()