ASL 0.1.7
Advanced Simulation Library
Loading...
Searching...
No Matches
testPrivateVar.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 "utilities/aslUValue.h"
29#include "acl/Kernels/aclKernel.h"
30#include "acl/Kernels/aclKernelConfigurationTemplates.h"
31#include <acl/acl.h>
32#include <acl/aclMath/aclVectorOfElements.h>
33#include <acl/aclGenerators.h>
34#include <utilities/aslTimer.h>
35
36const unsigned int nLength(1000000);
37const unsigned int nOperations(10);
38const unsigned int nCycles(10000);
40//const acl::KernelConfiguration & kConf(acl::KERNEL_SIMDUA);
41
43{
44 cout << "Test of \"Simple kernel\" function..." << flush;
45
46 auto vec1(acl::generateVEData<float>(nLength,1u));
48
50 k << (res = acl::generateVEConstant(0.));
51 for(unsigned int i(0); i<nOperations; ++i)
52 {
54 k << (tempRes=acl::generateVEIndex() * i+5.*i*i+7./(i+1.));
55 k << (res+=tempRes*tempRes+rsqrt(.2*tempRes)+ 1./tempRes);
56 }
57 k << (vec1=res);
58 k.setup();
59
60 asl::Timer timer;
61 timer.start();
62 for(unsigned int i(0); i<nCycles; ++i)
63 k.compute();
64 timer.stop();
65 std::cout<<"Unoptimized: "<<timer.realTime()<<endl;
66
67 return true;
68}
69
70
72{
73 cout << "Test of \"Simple kernel\" function..." << flush;
74
75 auto vec1(acl::generateVEData<float>(nLength,1u));
77
79 k << (res = acl::generateVEConstant(0.));
80 vector<acl::VectorOfElements> tempRes(nOperations);
81 for(unsigned int i(0); i<nOperations; ++i)
82 {
84 k << (tempRes[i]=acl::generateVEIndex() * i+5.*i*i+7./(i+1.));
85 }
86 for(unsigned int i(0); i<nOperations; ++i)
87 k << (res+=tempRes[i]*tempRes[i]+rsqrt(.2*tempRes[i])+ 1./tempRes[i]);
88 k << (vec1=res);
89 k.setup();
90
91 asl::Timer timer;
92 timer.start();
93 for(unsigned int i(0); i<nCycles; ++i)
94 k.compute();
95 timer.stop();
96 std::cout<<"UnoptimizedPlus: "<<timer.realTime()<<endl;
97
98 return true;
99}
100
101
103{
104 cout << "Test of \"Simple kernel\" function..." << flush;
105
106 auto vec1(acl::generateVEData<float>(nLength,1u));
108
111 k << (res = acl::generateVEConstant(0.));
112 for(unsigned int i(0); i<nOperations; ++i)
113 {
114 k << (tempRes=acl::generateVEIndex() * i+5.*i*i+7./(i+1.));
115 k << (res+=tempRes*tempRes+rsqrt(.2*tempRes)+ 1./tempRes);
116 }
117 k << (vec1=res);
118 k.setup();
119// cout<<k.getKernelSource()<<endl;
120
121 asl::Timer timer;
122 timer.start();
123 for(unsigned int i(0); i<nCycles; ++i)
124 k.compute();
125 timer.stop();
126 std::cout<<"Optimized: "<<timer.realTime()<<endl;
127
128 return true;
129}
130
131
132
133int main()
134{
138
139 return 0;
140}
ACL Kernel configuration class.
OpenCl Kernel generator.
Definition aclKernel.h:49
void setup()
void compute()
const double realTime() const
Definition aslTimer.h:45
void stop()
Definition aslTimer.h:44
void start()
Definition aslTimer.h:43
const KernelConfiguration KERNEL_BASIC
VectorOfElements generateVEConstant(T a)
Generates VectorOfElements with 1 Element acl::Constant with value a.
VectorOfElements generateVEPrivateVariable(unsigned int n)
Generates VectorOfElements with n Element of acl::PrivateVariable.
VectorOfElements generateVEIndex(unsigned int size=0)
@ TYPE_FLOAT
Definition aclTypes.h:42
int main()
bool testKernelOptimized()
const unsigned int nOperations(10)
bool testKernelUnoptimized()
const acl::KernelConfiguration & kConf(acl::KERNEL_BASIC)
bool testKernelUnoptimizedPlus()
const unsigned int nLength(1000000)
const unsigned int nCycles(10000)