| 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 ACLLOCALARRAY_H |
| 25 |
#define ACLLOCALARRAY_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 |
|
| 37 |
/** |
| 38 |
This Element appears in the Kernel source code as a local array. |
| 39 |
It is not passed to the Kernel as an argument. |
| 40 |
*/ |
| 41 |
template <typename T> class LocalArray: public ElementBase |
| 42 |
{ |
| 43 |
private: |
| 44 |
string name; |
| 45 |
static const string prefix; |
| 46 |
static unsigned int id; |
| 47 |
public: |
| 48 |
explicit LocalArray(unsigned int size_); |
| 49 |
virtual string str(const KernelConfiguration & kernelConfig) const; |
| 50 |
virtual string getName() const; |
| 51 |
virtual string getAddressSpaceQualifier() const; |
| 52 |
virtual string getTypeSignature(const KernelConfiguration & kernelConfig) const; |
| 53 |
virtual string getLocalDeclaration(const KernelConfiguration & kernelConfig) const; |
| 54 |
virtual void addToKernelSource(vector<Element> & arguments, |
| 55 |
vector<Element> & localDeclarations) const; |
| 56 |
virtual void setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const; |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 60 |
template <typename T> LocalArray<T>::LocalArray(unsigned int size_): |
| 61 |
ElementBase(true, size_, typeToTypeID<T>()) |
| 62 |
{ |
| 63 |
++id; |
| 64 |
name = prefix + asl::numToStr(id); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
template <typename T> string LocalArray<T>::str(const KernelConfiguration & kernelConfig) const |
| 69 |
{ |
| 70 |
if (kernelConfig.unaligned && kernelConfig.vectorWidth > 1) |
| 71 |
{ |
| 72 |
return "vload" + numToStr(kernelConfig.vectorWidth) + "(0, &" + name + "[" + INDEX + "])"; |
| 73 |
} |
| 74 |
else |
| 75 |
{ |
| 76 |
return name + "[" + INDEX + "]"; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
template <typename T> string LocalArray<T>::getName() const |
| 82 |
{ |
| 83 |
return name; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
template <typename T> string LocalArray<T>::getTypeSignature(const KernelConfiguration & kernelConfig) const |
| 88 |
{ |
| 89 |
return ""; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
template <typename T> string LocalArray<T>::getAddressSpaceQualifier() const |
| 94 |
{ |
| 95 |
return "__local"; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
template <typename T> string LocalArray<T>::getLocalDeclaration(const KernelConfiguration & kernelConfig) const |
| 100 |
{ |
| 101 |
return "__local " + typeToStr<T>(kernelConfig.unaligned ? 1 : kernelConfig.vectorWidth) |
| 102 |
+ " " + name + "[" + asl::numToStr(size + paddingElements(size, kernelConfig)) + "]"; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
template <typename T> void LocalArray<T>::addToKernelSource(vector<Element> & arguments, |
| 107 |
vector<Element> & localDeclarations) const |
| 108 |
{ |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
// can't be set as an argument |
| 113 |
template <typename T> void LocalArray<T>::setAsArgument(cl::Kernel & kernel, |
| 114 |
unsigned int argumentIndex) const |
| 115 |
{ |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
} // namespace acl |
| 120 |
|
| 121 |
#endif // ACLLOCALARRAY_H |