#include "acl/acl.h"
#include "acl/DataTypes/aclIndex.h"
#include "acl/DataTypes/aclGroupID.h"
#include "acl/DataTypes/aclConstant.h"
#include "acl/DataTypes/aclVariable.h"
#include "acl/DataTypes/aclVariableReference.h"
#include "acl/DataTypes/aclPrivateVariable.h"
#include "acl/DataTypes/aclPrivateArray.h"
#include "acl/DataTypes/aclArray.h"
#include "acl/DataTypes/aclSubvector.h"
#include "acl/DataTypes/aclLocalArray.h"
#include "acl/Operators/aclElementFor.h"
#include "acl/Operators/aclElementIfElse.h"
#include "acl/Operators/aclElementExcerpt.h"
#include "acl/Kernels/aclKernel.h"
#include "aslUtilities.h"
#include <math.h>
#include <initializer_list>
#include <acl/Kernels/aclKernelConfigurationTemplates.h>
using namespace std;
{
cout <<
"Test of \"copy\" function..." <<
flush;
Element vec0(
new Array<cl_float> (10));
vector<cl_float> input(10, 3);
vector<cl_float> output(10, 1);
bool status(output[3] == 3);
return status;
}
{
cout <<
"Test of Kernel with double..." <<
flush;
Element vec0(
new Array<cl_double>(10));
Element vec1(
new Array<cl_double>(10));
Element vec2(
new Array<cl_double>(10));
Element c(
new Constant<cl_double>(2.));
Kernel k;
{
using namespace elementOperators;
}
k.setup();
k.compute();
vector<cl_double> output0(10), output1(10);
bool status(output0[9]<10.1 && output1[2]>2-1e-4 && output1[3]<3+1e-4);
return status;
}
{
cout <<
"Test of KernelSIMD..." <<
flush;
Element vec0(
new Array<cl_float>(11));
Element vec1(
new Array<cl_float>(11));
vector<cl_float> input0(11, 3);
vector<cl_float> input1(11, 5);
vector<cl_float> output(11, 0);
vector<cl_float> expected({8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8});
{
using namespace elementOperators;
}
k.setup();
k.compute();
bool status(output == expected);
return status;
}
{
cout <<
"Test of KernelSIMDUA..." <<
flush;
Element vec0(
new Array<cl_float> (11));
Element vec1(
new Array<cl_float> (11));
vector<cl_float> input0(11, 3);
vector<cl_float> input1(11, 5);
vector<cl_float> output(11, 0);
vector<cl_float> expected({8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8});
{
using namespace elementOperators;
}
k.setup();
k.compute();
bool status(output == expected);
return status;
}
{
cout <<
"Test of kernel with PrivateVariable..." <<
flush;
Element vec0(
new Array<cl_float>(10));
Element vec1(
new Array<cl_float>(10));
Element loc(
new PrivateVariable<cl_float>());
vector<cl_float> input1(10, 3);
vector<cl_float> input2(10, 5);
vector<cl_float> output(10, 1);
Kernel k;
{
using namespace elementOperators;
}
k.setup();
k.compute();
bool status(output[2] ==8.);
return status;
}
{
cout <<
"Test of kernel with PrivateArray..." <<
flush;
vector<cl_int> inputGaIn({0, 4, 5});
vector<cl_float> inputGaOut(3, 0);
vector<cl_float> inputPa({-9, 2, 0, 15, 1, 3});
vector<cl_float> output(3);
vector<cl_float> expected({-9, 1, 3});
Element gaIn(
new Array<cl_int>(3));
Element gaOut(
new Array<cl_float>(3));
Element pa(
new PrivateArray<cl_float>(inputPa));
shared_ptr<ElementExcerpt> ex(new ElementExcerpt(pa, gaIn));
Kernel k;
{
using namespace elementOperators;
}
k.setup();
k.compute();
bool status(output == expected);
return status;
}
{
cout <<
"Test of Variable functionality..." <<
flush;
Element vec0(
new Array<cl_float> (10));
shared_ptr<Variable<cl_float> > a(new Variable<cl_float> (1.));
vector<cl_float> output(10, 1);
Kernel k;
k.setup();
k.compute();
a->setValue(10.);
k.compute();
bool status(output[2] ==10.);
return status;
}
{
cout <<
"Test of VariableReference functionality..." <<
flush;
Element vec0(
new Array<cl_float> (10));
float v(1.);
Element a(
new VariableReference<cl_float> (v));
vector<cl_float> output(10, 1);
Kernel k;
k.setup();
k.compute();
v=10.;
k.compute();
bool status(output[2] ==10.);
return status;
}
{
cout <<
"Test of select function..." <<
flush;
Element vec0(
new Array<cl_double> (10));
Element c0(
new Constant<cl_double> (2.1));
vector<cl_double> input(10, 3.);
vector<cl_double> output(10, 1.);
Kernel k;
{
using namespace elementOperators;
vec0*vec0,
vec0 > c0,
false))));
}
k.setup();
k.compute();
bool status(output[2] ==9.);
return status;
}
{
cout <<
"Test of Subvector..." <<
flush;
cl_float init[] = {16, 2, 77, 29, 23, 16, 2, 77, 29, 23};
shared_ptr<Array<cl_float> > vec0(new Array<cl_float>(10));
vector<cl_float> input(init, init + sizeof(init) / sizeof(cl_float) );
vector<cl_float> output(2);
Element subvec0(
new Subvector<cl_float> (vec0, 2, 0));
bool status(output[0]==16);
return status;
}
{
cout <<
"Test of Swap functionality..." <<
flush;
shared_ptr<Array<cl_float> > vec0(new Array<cl_float>(10));
shared_ptr<Array<cl_float> > vec1(new Array<cl_float>(10));
vector<cl_float> input0(10, 1);
vector<cl_float> input1(10, 2);
vector<cl_float> output(10, 10);
bool status(output[3] == 2);
return status;
}
{
cout <<
"Test of LocalArray and syncCopy with barrier()..." <<
flush;
unsigned int groupsNumber = 5;
unsigned int groupSize = 2;
Element vec0(
new Array<cl_float>(groupSize * groupsNumber));
Element vec1(
new Array<cl_float>(groupSize * groupsNumber));
Element loc0(
new LocalArray<cl_float>(groupSize));
Element loc1(
new LocalArray<cl_float>(groupSize));
Element cGroupSize(
new Constant<cl_uint>(groupSize));
Element c0(
new Constant<cl_uint>(0));
vector<cl_float> input0(groupSize * groupsNumber, 3);
vector<cl_float> input1(groupSize * groupsNumber, 5);
vector<cl_float> output(groupSize * groupsNumber, 0);
vector<cl_float> expected({2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
k.setGroupsNumber(groupsNumber);
{
using namespace elementOperators;
k.addExpression(
syncCopy(vec0, loc0, cGroupSize * groupID, c0, cGroupSize));
k.addExpression(
syncCopy(vec1, loc1, cGroupSize * groupID, c0, cGroupSize));
k.addExpression(
barrier(
"CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE"));
k.addExpression(
syncCopy(loc1, vec1, c0, cGroupSize * groupID, cGroupSize));
}
k.setup();
k.compute();
bool status(output == expected);
return status;
}
{
bool allTestsPassed(true);
return allTestsPassed ? EXIT_SUCCESS : EXIT_FAILURE;
}
Element operatorAssignment(Element e1, Element e2)
Element operatorAssignmentSafe(Element e1, Element e2)
Element select(Element e1, Element e2, Element e3)
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
const KernelConfiguration KERNEL_BASIC
const KernelConfiguration KERNEL_SIMD
const KernelConfiguration KERNEL_SIMDUA
Element powI(Element a, unsigned int i)
Element convert(const TypeID tName, Element e1, bool strong=true)
Element syncCopy(Element source, Element destination, Element srcOffset, Element dstOffset, Element length)
Element barrier(std::string flags="CLK_LOCAL_MEM_FENCE")
Advanced Computational Language.
void copy(MemBlock &source, T *destination)
const std::vector< TypeID > TYPE_SELECT
contains trasnlation of types necessery for use in the function select
void swapBuffers(std::shared_ptr< Array< T > >a, std::shared_ptr< Array< T > > b)
std::shared_ptr< ElementBase > Element
bool testPrivateVariable()
bool testVariableReference()
const acl::KernelConfiguration & kConf(acl::KERNEL_BASIC)