| 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 "aclExpressionContainer.h" |
| 25 |
#include "../aclUtilities.h" |
| 26 |
#include "../../aslUtilities.h" |
| 27 |
#include <acl/aclElementBase.h> |
| 28 |
|
| 29 |
|
| 30 |
using namespace std; |
| 31 |
using namespace asl; |
| 32 |
|
| 33 |
namespace acl |
| 34 |
{ |
| 35 |
|
| 36 |
ExpressionContainer::ExpressionContainer(): |
| 37 |
size(0), |
| 38 |
queue(), |
| 39 |
regenerateKernelSource(true) |
| 40 |
{ |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
void ExpressionContainer::addExpression(Element expression_) |
| 45 |
{ |
| 46 |
if (compatible(size, queue, expression_)) |
| 47 |
{ |
| 48 |
size = max(size, expression_->getSize()); |
| 49 |
|
| 50 |
if (expression_->getQueue().get() != 0) |
| 51 |
{ |
| 52 |
queue = expression_->getQueue(); |
| 53 |
} |
| 54 |
|
| 55 |
expression.push_back(expression_); |
| 56 |
addElementToKernelSource(expression_, arguments, localDeclarations); |
| 57 |
regenerateKernelSource = true; |
| 58 |
} |
| 59 |
else |
| 60 |
{ |
| 61 |
errorMessage("ExpressionContainer::addExpression() - last added expression \ |
| 62 |
is incompatible with the previous ones. \ |
| 63 |
Either they reside on different devices or their sizes do not match: " |
| 64 |
+ numToStr(expression_->getSize()) + " and " + numToStr(size)); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
void ExpressionContainer::filterDeclarations() |
| 70 |
{ |
| 71 |
/// sorts all Elements in arguments |
| 72 |
sort(arguments.begin(), arguments.end()); |
| 73 |
vector<Element>::iterator iter; |
| 74 |
/// removes consecutive duplicate Elements in arguments |
| 75 |
iter = unique(arguments.begin(), arguments.end()); |
| 76 |
|
| 77 |
// drop all elements beyond the new end() (= iter) returned by unique |
| 78 |
arguments.resize(iter - arguments.begin()); |
| 79 |
|
| 80 |
|
| 81 |
/// sorts all Elements in localDeclarations |
| 82 |
sort(localDeclarations.begin(), localDeclarations.end()); |
| 83 |
|
| 84 |
/// removes consecutive duplicate Elements in localDeclarations |
| 85 |
iter = unique(localDeclarations.begin(), localDeclarations.end()); |
| 86 |
// drop all elements beyond the new end() (= iter) returned by unique |
| 87 |
localDeclarations.resize(iter - localDeclarations.begin()); |
| 88 |
|
| 89 |
/// \todoZeev remember duplicate Elements and create an extra local |
| 90 |
/// variable for them in order to reduce number of memory reads |
| 91 |
|
| 92 |
// Maybe use std::set to get rid of duplicates? Like this: |
| 93 |
// std::set<std::string> alternatives_set (m_alternatives.begin(), m_alternatives.end()); |
| 94 |
// std::vector<std::string> alternatives_vec (alternatives_set.begin(), alternatives_set.end()); |
| 95 |
} |
| 96 |
|
| 97 |
unsigned int ExpressionContainer::getSize() |
| 98 |
{ |
| 99 |
return size; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
} // namespace acl |