ASL
0.1.7
Advanced Simulation Library
Loading...
Searching...
No Matches
testASLData.cc
/*
* Advanced Simulation Library <http://asl.org.il>
*
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
*
*
* This file is part of Advanced Simulation Library (ASL).
*
* ASL is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* ASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "
acl/acl.h
"
#include "
acl/aclGenerators.h
"
#include "
acl/DataTypes/aclGroupID.h
"
#include "
acl/DataTypes/aclConstant.h
"
#include "
aslGenerators.h
"
#include "
aslUtilities.h
"
#include "
acl/Kernels/aclKernel.h
"
#include "
data/aslDataUtilities.h
"
#include <
acl/aclMath/aclVectorOfElements.h
>
#include <
data/aslDataWithGhostNodes.h
>
using namespace
acl
;
using namespace
asl
;
using namespace
std
;
bool
testSimpleKernel
()
{
Block
bl(makeAVec(10,5),0.1);
auto
a(generateDataContainerACL_SP<double>(bl,1,1));
auto
b(generateDataContainerACL_SP<double>(bl,1,1));
Kernel
k;
k<<(a->getEContainer()=acl::generateVEConstant<double>(0));
k<<(b->getEContainer()=acl::generateVEConstant<double>(0));
k.
setup
();
cout<<k.
getKernelSource
()<<endl;
return
true
;
}
bool
testInitData
()
{
Block
bl(makeAVec(10,5),0.1);
auto
a(generateDataContainerACL_SP<double>(bl, 1, 1));
initData(a->getEContainer(),acl::generateVEConstant<double>(0));
return
true
;
}
bool
testUploadToLocalMem
()
{
cout <<
"Test of UploadToLocalMem()..."
<<
flush
;
unsigned
int
componentsNum = 2;
unsigned
int
groupSize = 27;
KernelConfiguration
kConf
(KERNEL_BASIC);
kConf
.
local
=
true
;
Kernel
kernel(
kConf
);
Element
groupID(
new
GroupID
());
Element
c0(
new
Constant<cl_uint>
(0));
asl::AVec<int>
totalDimensions(
asl::makeAVec
(10, 10, 10));
// dx = 1
asl::Block
block(totalDimensions, 1);
// boundary = 0
auto
source(asl::generateDataContainerACL_SP<float>(block,
componentsNum,
0u));
// initialize source with value "13"
acl::initData
(source->getEContainer(),
acl::generateVEConstantN
(componentsNum,
13));
// boundary = 0
auto
destination(asl::generateDataContainerACL_SP<float>(block,
componentsNum,
0u));
// initialize source with value "27"
acl::initData
(destination->getEContainer(),
acl::generateVEConstantN
(componentsNum,
27));
asl::AVec<int>
portionDimensions(
asl::makeAVec
(5, 5, 5));
unsigned
int
portionSize =
productOfElements
(portionDimensions);
unsigned
int
totalSize =
productOfElements
(totalDimensions);
unsigned
int
groupsNumber = totalSize / portionSize;
Element
cPortionSize(
new
Constant<cl_uint>
(portionSize));
kernel.setGroupsNumber(groupsNumber);
VectorOfElements
localSource(componentsNum);
copy
(
uploadToLocalMem
(*source, portionDimensions, groupSize, kernel), localSource);
using namespace
elementOperators;
kernel.addExpression(
barrier
(
"CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE"
));
// overwrite destination with localSource
for
(
unsigned
int
i = 0; i < componentsNum; ++i)
kernel.addExpression(
syncCopy
(localSource[i], destination->getEContainer()[i],
c0, cPortionSize * groupID, cPortionSize));
kernel.setup();
kernel.compute();
bool
status(
true
);
vector<cl_float> src(totalSize);
vector<cl_float> dst(totalSize);
for
(
unsigned
int
i = 0; i < componentsNum; ++i)
{
copy
(source->getEContainer()[i], src);
copy
(destination->getEContainer()[i], dst);
cout << src << endl << endl << dst << endl;
status &= (src == dst);
}
errorMessage
(status);
return
status;
}
int
main
()
{
bool
allTestsPassed(
true
);
allTestsPassed &=
testSimpleKernel
();
allTestsPassed &=
testInitData
();
allTestsPassed &=
testUploadToLocalMem
();
return
allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE;
}
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::GroupID
Definition
aclGroupID.h:33
acl::KernelConfiguration
ACL Kernel configuration class.
Definition
aclKernelConfiguration.h:35
acl::KernelConfiguration::local
bool local
Definition
aclKernelConfiguration.h:45
acl::Kernel
OpenCl Kernel generator.
Definition
aclKernel.h:49
acl::Kernel::getKernelSource
std::string getKernelSource()
acl::Kernel::setup
void setup()
acl::VectorOfElements
The class represents several Element.
Definition
aclVectorOfElementsDef.h:92
asl::AVec
Definition
aslVectorsDynamicLength.h:40
asl::Block
Definition
aslBlocks.h:57
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::initData
void initData(Element a, Element initializationValue, const KernelConfiguration &kernelConfig=KERNEL_BASIC)
acl::elementOperators::syncCopy
Element syncCopy(Element source, Element destination, Element srcOffset, Element dstOffset, Element length)
acl::elementOperators::barrier
Element barrier(std::string flags="CLK_LOCAL_MEM_FENCE")
acl::generateVEConstantN
VectorOfElements generateVEConstantN(unsigned int n, T a)
Generates VectorOfElements with n Elements acl::Constant with values a.
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
cl::flush
cl_int flush(void)
Definition
cl.hpp:7042
std
STL namespace.
main
int main()
Definition
testABDFormat.cc:126
testInitData
bool testInitData()
Definition
testASLData.cc:61
testUploadToLocalMem
bool testUploadToLocalMem()
Definition
testASLData.cc:72
kConf
const acl::KernelConfiguration & kConf(acl::KERNEL_BASIC)
testSimpleKernel
bool testSimpleKernel()
Definition
testVectorOfElements.cc:40
Generated by
1.9.7