ASL
0.1.7
Advanced Simulation Library
Toggle main menu visibility
Loading...
Searching...
No Matches
test
testMath
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
27
28
#include "
acl/acl.h
"
29
#include "
acl/aclGenerators.h
"
30
#include "
acl/DataTypes/aclGroupID.h
"
31
#include "
acl/DataTypes/aclConstant.h
"
32
#include "
aslGenerators.h
"
33
#include "
aslUtilities.h
"
34
#include "
acl/Kernels/aclKernel.h
"
35
#include "
data/aslDataUtilities.h
"
36
#include <
acl/aclMath/aclVectorOfElements.h
>
37
#include <
data/aslDataWithGhostNodes.h
>
38
39
using namespace
acl
;
40
using namespace
asl
;
41
using namespace
std
;
42
43
bool
testSimpleKernel
()
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
61
bool
testInitData
()
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
72
bool
testUploadToLocalMem
()
73
{
74
cout <<
"Test of UploadToLocalMem()..."
<< flush;
75
76
unsigned
int
componentsNum = 2;
77
unsigned
int
groupSize = 27;
78
KernelConfiguration
kConf
(
KERNEL_BASIC
);
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.h
aclConstant.h
aclGenerators.h
aclGroupID.h
aclKernel.h
aclVectorOfElements.h
aslDataUtilities.h
aslDataWithGhostNodes.h
aslGenerators.h
aslUtilities.h
useful common utilities
acl::Constant
Definition
aclConstant.h:34
acl::ExpressionContainer::addExpression
void addExpression(Element expression_)
acl::GroupID
Definition
aclGroupID.h:33
acl::KernelConfiguration
ACL Kernel configuration class.
Definition
aclKernelConfiguration.h:35
acl::Kernel
OpenCl Kernel generator.
Definition
aclKernel.h:49
acl::Kernel::getKernelSource
std::string getKernelSource()
acl::Kernel::setGroupsNumber
void setGroupsNumber(unsigned int n)
acl::Kernel::setup
void setup()
acl::Kernel::compute
void compute()
acl::VectorOfElements
The class represents several Element.
Definition
aclVectorOfElementsDef.h:92
asl::AVec
Definition
aslVectorsDynamicLength.h:40
asl::Block
Definition
aslBlocks.h:57
asl::generateDataContainerACL_SP
SPDataWrapperACLData generateDataContainerACL_SP(const Block &b, unsigned int n=1)
generates pointer to ACL Data field with n components
asl::uploadToLocalMem
acl::VectorOfElements uploadToLocalMem(AbstractData &source, const AVec< int > &size, unsigned int groupSize, acl::Kernel &kernel)
asl::errorMessage
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
acl::KERNEL_BASIC
const KernelConfiguration KERNEL_BASIC
Definition
aclElementBase.h:45
acl::initData
void initData(Element a, Element initializationValue, const KernelConfiguration &kernelConfig=KERNEL_BASIC)
acl::generateVEConstantN
VectorOfElements generateVEConstantN(unsigned int n, T a)
Generates VectorOfElements with n Elements acl::Constant with values a.
acl::generateVEConstant
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
acl::elementOperators
definitions of mathematical operators and functions for class Element
Definition
acl.h:56
acl
Advanced Computational Language.
Definition
acl.h:41
acl::copy
void copy(MemBlock &source, T *destination)
acl::Element
std::shared_ptr< ElementBase > Element
Definition
acl.h:49
asl
Advanced Simulation Library.
Definition
aslDataInc.h:31
asl::makeAVec
AVec< T > makeAVec(T a1)
Definition
aslVectorsDynamicLength.h:176
asl::productOfElements
T productOfElements(const AVec< T > &a)
Definition
aslVectorsDynamicLengthOperations.h:314
std
STL namespace.
testInitData
bool testInitData()
Definition
testASLData.cc:61
testSimpleKernel
bool testSimpleKernel()
Definition
testASLData.cc:43
testUploadToLocalMem
bool testUploadToLocalMem()
Definition
testASLData.cc:72
main
int main()
Definition
testASLData.cc:145
kConf
const acl::KernelConfiguration & kConf(acl::KERNEL_BASIC)
Generated by
1.17.0