Debian Codegraph @

src/acl/aclUtilities.h

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 #ifndef ACLUTILITIES_H
25 #define ACLUTILITIES_H
26
27 #include "aslUtilities.h"
28 #include "Kernels/aclKernelConfiguration.h"
29 //#include "aclHardware.h"
30 #include "aclTypes.h"
31
32 namespace cl
33 {
34 class CommandQueue;
35 }
36
37 namespace acl
38 {
39 extern const std::string INDEX;
40 extern const KernelConfiguration KERNEL_BASIC;
41
42 class ElementBase;
43 typedef std::shared_ptr<ElementBase> Element;
44 typedef std::shared_ptr<cl::CommandQueue> CommandQueue;
45
46 /// determines whether two elements are compatible
47 /// i.e. have compatible sizes and reside on the same device
48 bool compatible(unsigned int size1, CommandQueue queue1,
49 unsigned int size2, CommandQueue queue2);
50 bool compatible(unsigned int size, CommandQueue queue, Element e);
51 bool compatible(Element e1, Element e2);
52
53 /// if \p s and size of \p e are the same or at least one of them is 0
54 inline bool compatibleSizes(unsigned int s1, unsigned int s2);
55 /// if both elements have the same size or size of at least one of them is 0
56 bool compatibleSizes(Element e1, Element e2);
57 /// if \p s and size of \p e are the same or at least one of them is 0
58 bool compatibleSizes(unsigned int s, Element e);
59
60 /// Adds padding in bytes based on the device's alignment
61 unsigned int paddingBytes(unsigned int size,
62 unsigned int typeSize,
63 CommandQueue queue);
64
65 /// Adds padding in elements based on vector width
66 unsigned int paddingElements(unsigned int size,
67 const KernelConfiguration & kernelConfig);
68
69 /// checks whether both elements reside on the same device
70 bool onSameDevice(CommandQueue queue1, CommandQueue queue2);
71 bool onSameDevice(CommandQueue queue, Element e);
72 bool onSameDevice(Element e1, Element e2);
73
74 bool isDeclarable(Element e);
75
76 bool isArgument(Element e);
77
78 /// adds \p e either to \p arguments or to \p localDeclarations
79 void addElementToKernelSource(Element e,
80 std::vector<Element> & arguments,
81 std::vector<Element> & localDeclarations);
82
83 template <typename T> const std::string& typeToStr();
84 template <typename T> inline const std::string typeToStr(unsigned int i);
85
86 template <typename T> inline constexpr const TypeID typeToTypeID();
87
88 // ------------------------Implementation ---------------
89
90 inline bool compatibleSizes(unsigned int s1, unsigned int s2)
91 {
92 return (s1 == s2 || (s1 * s2) == 0);
93 }
94
95 template <> inline constexpr const TypeID typeToTypeID<cl_double>()
96 {
97 return TYPE_DOUBLE;
98 }
99
100 template <> inline constexpr const TypeID typeToTypeID<cl_float>()
101 {
102 return TYPE_FLOAT;
103 }
104
105 template <> inline constexpr const TypeID typeToTypeID<cl_int>()
106 {
107 return TYPE_INT;
108 }
109
110 template <> inline constexpr const TypeID typeToTypeID<cl_uint>()
111 {
112 return TYPE_UINT;
113 }
114
115 template <> inline constexpr const TypeID typeToTypeID<cl_long>()
116 {
117 return TYPE_LONG;
118 }
119
120 template <typename T> inline const std::string typeToStr(unsigned int i)
121 {
122 if (i == 1)
123 return typeToStr<T>();
124 else
125 return typeToStr<T>() + asl::numToStr(i);
126 }
127
128
129 } // namespace acl
130 #endif // ACLUTILITIES_H