| 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 |
#include "aclElementParser.h" |
| 25 |
#include "../aclUtilities.h" |
| 26 |
#include "../../aslUtilities.h" |
| 27 |
|
| 28 |
using namespace asl; |
| 29 |
|
| 30 |
namespace acl |
| 31 |
{ |
| 32 |
|
| 33 |
ElementParser::ElementParser(): |
| 34 |
// set typeID fictitious first, change with the first call of addElementNamePair |
| 35 |
ElementBase(false, 0, TYPE_INT) |
| 36 |
{ |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
void ElementParser::addElementNamePair(Element element, string name) |
| 41 |
{ |
| 42 |
if (compatible(size, queue, element)) |
| 43 |
{ |
| 44 |
size = max(size, element->getSize()); |
| 45 |
typeID = element->getTypeID(); |
| 46 |
if (element->getQueue().get() != 0) |
| 47 |
queue = element->getQueue(); |
| 48 |
elementNamePairs.push_back(make_pair(element, name)); |
| 49 |
} |
| 50 |
else |
| 51 |
{ |
| 52 |
errorMessage("ElementParser::addElementNamePair - last added expression \ |
| 53 |
is incompatible with the previous ones. \ |
| 54 |
Either they reside on different devices or their sizes do not match: " |
| 55 |
+ numToStr(element->getSize()) + " and " + numToStr(size)); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
void ElementParser::setStatement(string statement_) |
| 61 |
{ |
| 62 |
statement = statement_; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
string ElementParser::str(const KernelConfiguration & kernelConfig) const |
| 67 |
{ |
| 68 |
string s = statement; |
| 69 |
|
| 70 |
for (unsigned int i = 0; i < elementNamePairs.size(); ++i) |
| 71 |
{ |
| 72 |
size_t found = s.find(elementNamePairs[i].second); |
| 73 |
|
| 74 |
int nameSize(elementNamePairs[i].second.size()); |
| 75 |
string fieldStr(elementNamePairs[i].first->str(kernelConfig)); |
| 76 |
while (found != string::npos) |
| 77 |
{ |
| 78 |
s.replace(found, nameSize, fieldStr); |
| 79 |
found = s.find(elementNamePairs[i].second, found + fieldStr.size()); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
return s; |
| 84 |
} |
| 85 |
|
| 86 |
/// \todoZeev Add to kernel only Elements that were found in the statement!!! |
| 87 |
void ElementParser::addToKernelSource(vector<Element> & arguments, |
| 88 |
vector<Element> & localDeclarations) const |
| 89 |
{ |
| 90 |
if (statement == "") |
| 91 |
errorMessage("ElementParser::addToKernelSource() - statement is an empty string"); |
| 92 |
|
| 93 |
for (unsigned int i = 0; i < elementNamePairs.size(); ++i) |
| 94 |
{ |
| 95 |
addElementToKernelSource(elementNamePairs[i].first, arguments, localDeclarations); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
void ElementParser::setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const |
| 101 |
{ |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
string ElementParser::getName() const |
| 106 |
{ |
| 107 |
return ""; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
string ElementParser::getTypeSignature(const KernelConfiguration & kernelConfig) const |
| 112 |
{ |
| 113 |
return ""; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
string ElementParser::getLocalDeclaration(const KernelConfiguration & kernelConfig) const |
| 118 |
{ |
| 119 |
return ""; |
| 120 |
} |
| 121 |
} // namespace acl |