ASL  0.1.7
Advanced Simulation Library
testPrivateVar.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>
const unsigned int nLength(1000000);
const unsigned int nOperations(10);
const unsigned int nCycles(10000);
//const acl::KernelConfiguration & kConf(acl::KERNEL_SIMDUA);
{
cout << "Test of \"Simple kernel\" function..." << flush;
auto vec1(acl::generateVEData<float>(nLength,1u));
k << (res = acl::generateVEConstant(0.));
for(unsigned int i(0); i<nOperations; ++i)
{
k << (tempRes=acl::generateVEIndex() * i+5.*i*i+7./(i+1.));
k << (res+=tempRes*tempRes+rsqrt(.2*tempRes)+ 1./tempRes);
}
k << (vec1=res);
k.setup();
asl::Timer timer;
timer.start();
for(unsigned int i(0); i<nCycles; ++i)
k.compute();
timer.stop();
std::cout<<"Unoptimized: "<<timer.realTime()<<endl;
return true;
}
{
cout << "Test of \"Simple kernel\" function..." << flush;
auto vec1(acl::generateVEData<float>(nLength,1u));
k << (res = acl::generateVEConstant(0.));
vector<acl::VectorOfElements> tempRes(nOperations);
for(unsigned int i(0); i<nOperations; ++i)
{
k << (tempRes[i]=acl::generateVEIndex() * i+5.*i*i+7./(i+1.));
}
for(unsigned int i(0); i<nOperations; ++i)
k << (res+=tempRes[i]*tempRes[i]+rsqrt(.2*tempRes[i])+ 1./tempRes[i]);
k << (vec1=res);
k.setup();
asl::Timer timer;
timer.start();
for(unsigned int i(0); i<nCycles; ++i)
k.compute();
timer.stop();
std::cout<<"UnoptimizedPlus: "<<timer.realTime()<<endl;
return true;
}
{
cout << "Test of \"Simple kernel\" function..." << flush;
auto vec1(acl::generateVEData<float>(nLength,1u));
k << (res = acl::generateVEConstant(0.));
for(unsigned int i(0); i<nOperations; ++i)
{
k << (tempRes=acl::generateVEIndex() * i+5.*i*i+7./(i+1.));
k << (res+=tempRes*tempRes+rsqrt(.2*tempRes)+ 1./tempRes);
}
k << (vec1=res);
k.setup();
// cout<<k.getKernelSource()<<endl;
asl::Timer timer;
timer.start();
for(unsigned int i(0); i<nCycles; ++i)
k.compute();
timer.stop();
std::cout<<"Optimized: "<<timer.realTime()<<endl;
return true;
}
int main()
{
return 0;
}