| 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 ACLPRIVATEARRAY_H |
| 25 |
#define ACLPRIVATEARRAY_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 |
| 39 |
as a private array (without address space qualifier). |
| 40 |
It is not passed to the Kernel as an argument. |
| 41 |
*/ |
| 42 |
template <typename T> class PrivateArray: public ElementBase |
| 43 |
{ |
| 44 |
private: |
| 45 |
string name; |
| 46 |
static const string prefix; |
| 47 |
static unsigned int id; |
| 48 |
vector<T> initVector; |
| 49 |
public: |
| 50 |
explicit PrivateArray(const vector<T> & initVector_); |
| 51 |
virtual string str(const KernelConfiguration & kernelConfig) const; |
| 52 |
virtual string getName() const; |
| 53 |
virtual string getAddressSpaceQualifier() const; |
| 54 |
virtual string getTypeSignature(const KernelConfiguration & kernelConfig) const; |
| 55 |
virtual string getLocalDeclaration(const KernelConfiguration & kernelConfig) const; |
| 56 |
virtual void addToKernelSource(vector<Element> & arguments, |
| 57 |
vector<Element> & localDeclarations) const; |
| 58 |
virtual void setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const; |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
template <typename T> PrivateArray<T>::PrivateArray(const vector<T> & initVector_): |
| 63 |
ElementBase(true, initVector_.size(), typeToTypeID<T>()), |
| 64 |
initVector(initVector_) |
| 65 |
{ |
| 66 |
++id; |
| 67 |
name = prefix + asl::numToStr(id); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
template <typename T> string PrivateArray<T>::str(const KernelConfiguration & kernelConfig) const |
| 72 |
{ |
| 73 |
if (kernelConfig.vectorWidth > 1) |
| 74 |
{ |
| 75 |
errorMessage("PrivateArray should not be used in a SIMD Kernel"); |
| 76 |
return ""; |
| 77 |
} |
| 78 |
else |
| 79 |
return name + "[" + INDEX + "]"; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
template <typename T> string PrivateArray<T>::getName() const |
| 84 |
{ |
| 85 |
return name; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
template <typename T> string PrivateArray<T>::getTypeSignature(const KernelConfiguration & kernelConfig) const |
| 90 |
{ |
| 91 |
return ""; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
template <typename T> string PrivateArray<T>::getAddressSpaceQualifier() const |
| 96 |
{ |
| 97 |
return "__private"; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
template <typename T> string PrivateArray<T>::getLocalDeclaration(const KernelConfiguration & kernelConfig) const |
| 102 |
{ |
| 103 |
string s = typeToStr<T>() + " " + name + "[" + asl::numToStr(size) + "] = {"; |
| 104 |
|
| 105 |
for (unsigned int i = 0; i < size; ++i) |
| 106 |
s += numToStr(initVector[i]) + ", "; |
| 107 |
|
| 108 |
// drop last ", " |
| 109 |
s.erase(s.size() - 2); |
| 110 |
s += "}"; |
| 111 |
|
| 112 |
return s; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
template <typename T> void PrivateArray<T>::addToKernelSource(vector<Element> & arguments, |
| 117 |
vector<Element> & localDeclarations) const |
| 118 |
{ |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
// can't be set as an argument |
| 123 |
template <typename T> void PrivateArray<T>::setAsArgument(cl::Kernel & kernel, |
| 124 |
unsigned int argumentIndex) const |
| 125 |
{ |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
} // namespace acl |
| 130 |
|
| 131 |
#endif // ACLPRIVATEARRAY_H |