| 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 |
|
| 31 |
using namespace asl; |
| 32 |
|
| 33 |
namespace 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 |