ASL 0.1.7
Advanced Simulation Library
Loading...
Searching...
No Matches
aclArray.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 ACLARRAY_H
25#define ACLARRAY_H
26
27#include "../aclStdIncludes.h"
28#include "aclMemBlock.h"
29
30using namespace asl;
31
32namespace acl
33{
34
36 template <typename T> class Array: public MemBlock
37 {
38 protected:
39 string name;
40 static const string prefix;
41 static unsigned int id;
42 public:
43 explicit Array(unsigned int size, CommandQueue queue_ = hardware.defaultQueue);
45 virtual string str(const KernelConfiguration & kernelConfig) const;
46 virtual string getName() const;
47 virtual string getAddressSpaceQualifier() const;
48 virtual string getTypeSignature(const KernelConfiguration & kernelConfig) const;
49 virtual string getLocalDeclaration(const KernelConfiguration & kernelConfig) const;
50 virtual void addToKernelSource(vector<Element> & arguments,
51 vector<Element> & localDeclarations) const;
52 virtual void setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const;
54 };
55
60
61//------------------- Implementation -------------------------------
62
63 template <typename T> Array<T>::Array(unsigned int size_, CommandQueue queue_):
64 MemBlock(size_, typeToTypeID<T>(), queue_)
65 {
66 ++id;
68 }
69
70
71 template <typename T> Array<T>::Array(unsigned int size_, T *initArray, CommandQueue queue_):
72 MemBlock(size_, typeToTypeID<T>(), queue_, (char*)initArray)
73 {
74 ++id;
76 }
77
78
79
80 template <typename T> string Array<T>::getName() const
81 {
82 return name;
83 }
84
85
86 template <typename T> string Array<T>::str(const KernelConfiguration & kernelConfig) const
87 {
88 if (kernelConfig.unaligned && kernelConfig.vectorWidth > 1)
89 {
90 return "vload" + numToStr(kernelConfig.vectorWidth) + "(0, &" + name + "[" + INDEX + "])";
91 }
92 else
93 {
94 return name + "[" + INDEX + "]";
95 }
96 }
97
98
99 template <typename T> string Array<T>::getTypeSignature(const KernelConfiguration & kernelConfig) const
100 {
101 return "__global " + typeToStr<T>(kernelConfig.unaligned ? 1 : kernelConfig.vectorWidth) + " *" + name;
102 }
103
104
105 template <typename T> string Array<T>::getAddressSpaceQualifier() const
106 {
107 return "__global";
108 }
109
110
111 template <typename T> string Array<T>::getLocalDeclaration(const KernelConfiguration & kernelConfig) const
112 {
113 return "";
114 }
115
116
117 // Must be empty. Only operators can add arguments.
118 template <typename T>
119 void Array<T>::addToKernelSource(vector<Element> & arguments, vector<Element> & localDeclarations) const
120 {
121 }
122
123
124 template <typename T>
125 void Array<T>::setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const
126 {
127 cl_int status = 0;
128 status = kernel.setArg(argumentIndex, *buffer);
129 errorMessage(status, "Kernel::setArg() - " + name
130 + ", argument " + numToStr(argumentIndex));
131 }
132
133
134} // namespace acl
135
136#endif // ACLARRAY_H
Global array.
Definition aclArray.h:37
static unsigned int id
Definition aclArray.h:41
Array(unsigned int size, T *initArray, CommandQueue queue_=hardware.defaultQueue)
virtual string getAddressSpaceQualifier() const
virtual string getTypeSignature(const KernelConfiguration &kernelConfig) const
virtual void addToKernelSource(vector< Element > &arguments, vector< Element > &localDeclarations) const
Definition aclArray.h:119
virtual void setAsArgument(cl::Kernel &kernel, unsigned int argumentIndex) const
virtual string getAddressSpaceQualifier() const
Definition aclArray.h:105
virtual void addToKernelSource(vector< Element > &arguments, vector< Element > &localDeclarations) const
string name
Definition aclArray.h:39
virtual string str(const KernelConfiguration &kernelConfig) const
Definition aclArray.h:86
static const string prefix
Definition aclArray.h:40
virtual string getLocalDeclaration(const KernelConfiguration &kernelConfig) const
virtual void setAsArgument(cl::Kernel &kernel, unsigned int argumentIndex) const
Definition aclArray.h:125
virtual string getName() const
Definition aclArray.h:80
virtual string getName() const
virtual string str(const KernelConfiguration &kernelConfig) const
virtual string getLocalDeclaration(const KernelConfiguration &kernelConfig) const
Definition aclArray.h:111
virtual string getTypeSignature(const KernelConfiguration &kernelConfig) const
Definition aclArray.h:99
Array(unsigned int size, CommandQueue queue_=hardware.defaultQueue)
unsigned int size
CommandQueue defaultQueue
ACL Kernel configuration class.
Class interface for cl_kernel.
Definition cl.hpp:4722
cl_int setArg(cl_uint index, const T &value)
Definition cl.hpp:4845
SPDataWrapperACLData generateDataContainerACL_SP(const Block &b, unsigned int n=1)
generates pointer to ACL Data field with n components
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.
Advanced Computational Language.
Definition acl.h:41
const std::string INDEX
std::shared_ptr< cl::CommandQueue > CommandQueue
Definition acl.h:51
constexpr const TypeID typeToTypeID()
Hardware hardware
shared_ptr< Array< cl_double > > ElementArrayDouble
Definition aclArray.h:58
shared_ptr< Array< cl_float > > ElementArrayFloat
Definition aclArray.h:57
shared_ptr< Array< cl_int > > ElementArrayInt
Definition aclArray.h:56
shared_ptr< Array< cl_long > > ElementArrayLong
Definition aclArray.h:59
Advanced Simulation Library.
Definition aslDataInc.h:31