ASL 0.1.7
Advanced Simulation Library
Loading...
Searching...
No Matches
aclVariable.h
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
24#ifndef ACLVARIABLE_H
25#define ACLVARIABLE_H
26
27#include "../aclElementBase.h"
28#include "../../aslUtilities.h"
29#include "../aclUtilities.h"
30
31using namespace asl;
32
33namespace acl
34{
35
36 template <typename T> class Variable: public ElementBase
37 {
38 private:
39 T value;
40 string name;
41 static const string prefix;
42 static unsigned int id;
43 public:
44 explicit Variable(T v);
45 virtual string str(const KernelConfiguration & kernelConfig) const;
46 virtual string getName() const;
47 virtual string getTypeSignature(const KernelConfiguration & kernelConfig) const;
48 virtual string getLocalDeclaration(const KernelConfiguration & kernelConfig) const;
49 virtual void addToKernelSource(vector<Element> & arguments,
50 vector<Element> & localDeclarations) const;
51 virtual void setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const;
52 virtual const T getValue() const;
53 void setValue(const T & a);
54 };
55
56
57 template <typename T> Variable<T>::Variable(T v):
58 ElementBase(true, 0, typeToTypeID<T>()),
59 value(v)
60 {
61 ++id;
62 name = prefix + asl::numToStr(id);
63 }
64
65
66 template <typename T> string Variable<T>::getName() const
67 {
68 return name;
69 }
70
71
72 template <typename T> string Variable<T>::str(const KernelConfiguration & kernelConfig) const
73 {
74 return name;
75 }
76
77 template <typename T> string Variable<T>::getLocalDeclaration(const KernelConfiguration & kernelConfig) const
78 {
79 return "";
80 }
81
82
83 template <typename T> void Variable<T>::addToKernelSource(vector<Element> & arguments,
84 vector<Element> & localDeclarations) const
85 {
86 }
87
88
89 template <typename T> void Variable<T>::setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const
90 {
91 cl_int status = 0;
92 status = kernel.setArg(argumentIndex, value);
93 errorMessage(status, "Kernel::setArg() - " + name + ", argument " + asl::numToStr(argumentIndex));
94 }
95
96
97 template <typename T> const T Variable<T>::getValue() const
98 {
99 return value;
100 }
101
102
103 template <typename T> void Variable<T>::setValue(const T & a)
104 {
105 value = a;
106 }
107
108
109} // namespace acl
110
111#endif // ACLVARIABLE_H
ACL Kernel configuration class.
virtual string getTypeSignature(const KernelConfiguration &kernelConfig) const
virtual const T getValue() const
Definition: aclVariable.h:97
virtual void addToKernelSource(vector< Element > &arguments, vector< Element > &localDeclarations) const
Definition: aclVariable.h:83
void setValue(const T &a)
Definition: aclVariable.h:103
virtual void setAsArgument(cl::Kernel &kernel, unsigned int argumentIndex) const
Definition: aclVariable.h:89
virtual string str(const KernelConfiguration &kernelConfig) const
Definition: aclVariable.h:72
virtual string getName() const
Definition: aclVariable.h:66
virtual string getLocalDeclaration(const KernelConfiguration &kernelConfig) const
Definition: aclVariable.h:77
Class interface for cl_kernel.
Definition: cl.hpp:4722
cl_int setArg(cl_uint index, const T &value)
Definition: cl.hpp:4845
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
std::string numToStr(T i)
Converts numbers or another type to string.
Definition: aslUtilities.h:48
Advanced Computational Language.
Definition: acl.h:41
constexpr const TypeID typeToTypeID()
Advanced Simulation Library.
Definition: aslDataInc.h:31