Debian Codegraph @

src/acl/Operators/aclElementFor.cxx

raw
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 "aclElementFor.h"
25 #include "../aclUtilities.h"
26 #include "../../aslUtilities.h"
27
28 using namespace asl;
29
30 namespace acl
31 {
32
33 ElementFor::ElementFor(Element initialization_, Element condition_, Element increase_):
34 // typeID fictitious
35 ElementBase(false, 0, TYPE_INT),
36 initialization(initialization_),
37 condition(condition_),
38 increase(increase_)
39 {
40 if (compatible(size, queue, initialization_))
41 {
42 size = max(size, initialization_->getSize());
43 if (initialization_->getQueue().get() != 0)
44 queue = initialization_->getQueue();
45 }
46 if (compatible(size, queue, condition_))
47 {
48 size = max(size, condition_->getSize());
49 if (condition_->getQueue().get() != 0)
50 queue = condition_->getQueue();
51 }
52 if (compatible(size, queue, increase_))
53 {
54 size = max(size, increase_->getSize());
55 if (increase_->getQueue().get() != 0)
56 queue = increase_->getQueue();
57 }
58 }
59
60
61 string ElementFor::str(const KernelConfiguration & kernelConfig) const
62 {
63 string s("");
64
65 // only if "for"'s body is not empty
66 // create for (...) loop
67 if (expression.size() > 0)
68 {
69 s = "for (" + initialization->str(kernelConfig) + "; "
70 + condition->str(kernelConfig) + "; "
71 + increase->str(kernelConfig) + ")\n\t{";
72
73 for (unsigned int i = 0; i < expression.size(); i++)
74 {
75 s += "\n\t\t" + expression[i]->str(kernelConfig) + ";";
76 }
77
78 s += "\n\t}";
79 }
80
81 return s;
82 }
83
84
85 void ElementFor::addBodyExpression(Element expression_)
86 {
87 if (compatible(size, queue, expression_))
88 {
89 size = max(size, expression_->getSize());
90 if (expression_->getQueue().get() != 0)
91 queue = expression_->getQueue();
92 expression.push_back(expression_);
93 }
94 else
95 {
96 errorMessage("ElementFor::addBodyExpression - last added expression \
97 is incompatible with the previous ones. \
98 Either they reside on different devices or their sizes do not match: "
99 + numToStr(expression_->getSize()) + " and " + numToStr(size));
100 }
101 }
102
103
104 void ElementFor::addToKernelSource(vector<Element> & arguments,
105 vector<Element> & localDeclarations) const
106 {
107 addElementToKernelSource(initialization, arguments, localDeclarations);
108 addElementToKernelSource(condition, arguments, localDeclarations);
109 addElementToKernelSource(increase, arguments, localDeclarations);
110
111 for (unsigned int i = 0; i < expression.size(); i++)
112 {
113 addElementToKernelSource(expression[i], arguments, localDeclarations);
114 }
115 }
116
117
118 void ElementFor::setAsArgument(cl::Kernel & kernel, unsigned int argumentIndex) const
119 {
120 }
121
122
123 string ElementFor::getName() const
124 {
125 return "";
126 }
127
128
129 string ElementFor::getTypeSignature(const KernelConfiguration & kernelConfig) const
130 {
131 return "";
132 }
133
134
135 string ElementFor::getLocalDeclaration(const KernelConfiguration & kernelConfig) const
136 {
137 return "";
138 }
139 } // namespace acl