ASL  0.1.7
Advanced Simulation Library
aclVariableSP.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 ACLVARIABLESP_H
25 #define ACLVARIABLESP_H
26 
27 #include "../aclElementBase.h"
28 #include "../../aslUtilities.h"
29 #include "../aclUtilities.h"
30 
31 
32 namespace acl
33 {
34 
35  template <typename T> class VariableSP: public ElementBase
36  {
37  private:
38  std::shared_ptr<T> value;
39  string name;
40  static const string prefix;
41  static unsigned int id;
42  public:
43  explicit VariableSP(std::shared_ptr<T> v);
44  virtual string str(const KernelConfiguration & kernelConfig) const;
45  virtual string getName() const;
46  virtual string getTypeSignature(const KernelConfiguration & kernelConfig) const;
47  virtual string getLocalDeclaration(const KernelConfiguration & kernelConfig) const;
48  virtual void addToKernelSource(vector<Element> & arguments,
49  vector<Element> & localDeclarations) const;
50  virtual void setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const;
51  };
52 
53 
54  template <typename T> VariableSP<T>::VariableSP(std::shared_ptr<T> v):
55  ElementBase(true, 0, typeToTypeID<T>()),
56  value(v)
57  {
58  ++id;
59  name = prefix + asl::numToStr(id);
60  }
61 
62 
63  template <typename T> string VariableSP<T>::getName() const
64  {
65  return name;
66  }
67 
68 
69  template <typename T> string VariableSP<T>::str(const KernelConfiguration & kernelConfig) const
70  {
71  return name;
72  }
73 
74  template <typename T> string VariableSP<T>::getLocalDeclaration(const KernelConfiguration & kernelConfig) const
75  {
76  return "";
77  }
78 
79 
80  template <typename T> void VariableSP<T>::addToKernelSource(vector<Element> & arguments,
81  vector<Element> & localDeclarations) const
82  {
83  }
84 
85  template <typename T> void VariableSP<T>::setAsArgument(cl::Kernel & kernel,
86  unsigned int argumentIndex) const
87  {
88  cl_int status = 0;
89  status = kernel.setArg(argumentIndex, *value);
90  asl::errorMessage(status, "Kernel::setArg() - " + name + ", argument " + asl::numToStr(argumentIndex));
91  }
92 
93 
94 } // namespace acl
95 
96 #endif // ACLVARIABLE_H
Advanced Computational Language.
Definition: acl.h:40
virtual string getTypeSignature(const KernelConfiguration &kernelConfig) const
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
virtual void addToKernelSource(vector< Element > &arguments, vector< Element > &localDeclarations) const
Definition: aclVariableSP.h:80
virtual void setAsArgument(cl::Kernel &kernel, unsigned int argumentIndex) const
Definition: aclVariableSP.h:85
virtual string str(const KernelConfiguration &kernelConfig) const
Definition: aclVariableSP.h:69
VariableSP(std::shared_ptr< T > v)
Definition: aclVariableSP.h:54
ACL Kernel configuration class.
constexpr const TypeID typeToTypeID()
Class interface for cl_kernel.
Definition: cl.hpp:4721
virtual string getName() const
Definition: aclVariableSP.h:63
cl_int setArg(cl_uint index, const T &value)
Definition: cl.hpp:4845
virtual string getLocalDeclaration(const KernelConfiguration &kernelConfig) const
Definition: aclVariableSP.h:74