Debian Codegraph @

src/acl/aclUtilities.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 "aclUtilities.h"
25 #include "Kernels/aclKernelConfigurationTemplates.h"
26 #include "acl/aclElementBase.h"
27
28 #include "aclTypesList.h"
29 #include "aclHardware.h"
30
31 using namespace std;
32
33 namespace acl
34 {
35
36 bool compatible(unsigned int size1,
37 CommandQueue queue1,
38 unsigned int size2,
39 CommandQueue queue2)
40 {
41 return ((compatibleSizes(size1, size2)) && (onSameDevice(queue1, queue2)));
42 }
43
44
45 bool compatible(unsigned int size, CommandQueue queue, Element e)
46 {
47 return compatible(size, queue, e->getSize(), e->getQueue());
48 }
49
50
51 bool compatible(Element e1, Element e2)
52 {
53 return compatible(e1->getSize(), e1->getQueue(), e2->getSize(), e2->getQueue());
54 }
55
56
57 bool compatibleSizes(Element e1, Element e2)
58 {
59 return compatibleSizes(e1->getSize(), e2->getSize());
60 }
61
62
63 bool compatibleSizes(unsigned int s, Element e)
64 {
65 return compatibleSizes(s, e->getSize());
66 }
67
68
69 bool onSameDevice(CommandQueue queue1, CommandQueue queue2)
70 {
71 return ((queue1 == queue2) || (queue1.get() == 0) || (queue2.get() == 0));
72 }
73
74 bool onSameDevice(CommandQueue queue, Element e)
75 {
76 return onSameDevice(queue, e->getQueue());
77 }
78
79
80 bool onSameDevice(Element e1, Element e2)
81 {
82 return onSameDevice(e1->getQueue(), e2->getQueue());
83 }
84
85
86 bool isDeclarable(Element e)
87 {
88 return ((e->getTypeSignature(KERNEL_BASIC) != "") || (e->getLocalDeclaration(KERNEL_BASIC) != ""));
89 }
90
91
92 bool isArgument(Element e)
93 {
94 return (e->getTypeSignature(KERNEL_BASIC) != "");
95 }
96
97
98 void addElementToKernelSource(Element e,
99 vector<Element> & arguments,
100 vector<Element> & localDeclarations)
101 {
102 // adds expression_ either to arguments or to localDeclarations
103 // in a case that expression_ isDeclarable
104 if (isDeclarable(e))
105 {
106 if (isArgument(e))
107 {
108 arguments.push_back(e);
109 }
110 else
111 {
112 localDeclarations.push_back(e);
113 }
114 }
115 else
116 {
117 // adds expressions' elements either to arguments or to localDeclarations;
118 // multiply occurences of the same element possible.
119 // needs to be filtered
120 e->addToKernelSource(arguments, localDeclarations);
121 }
122 }
123
124
125 unsigned int paddingBytes(unsigned int size, unsigned int typeSize, CommandQueue queue)
126 {
127 // second modulo is added in order to make padding = 0 in the case
128 // that (size * typeSize) is divisible by getAlignment(queue)
129 return (getAlignment(queue) - ((size * typeSize) % getAlignment(queue))) % getAlignment(queue);
130 }
131
132
133 unsigned int paddingElements(unsigned int size, const KernelConfiguration & kernelConfig)
134 {
135 // second modulo is added in order to make padding = 0 in the case
136 // that size is divisible by kernelConfig.vectorWidth
137 return (kernelConfig.vectorWidth - (size % kernelConfig.vectorWidth)) % kernelConfig.vectorWidth;
138 }
139
140 template <typename T> const std::string& typeToStr()
141 {
142 return TYPE[typeToTypeID<T>()];
143 }
144
145 #define BOOST_TT_rep_expression(r, data, T) \
146 template const std::string& typeToStr<T>();
147 BOOST_PP_SEQ_FOR_EACH(BOOST_TT_rep_expression, ~, BOOST_TT_acl_types)
148 #undef BOOST_TT_rep_expression
149
150
151 } // namespace acl