ASL 0.1.7
Advanced Simulation Library
Loading...
Searching...
No Matches
aclUtilities.h
Go to the documentation of this file.
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
32namespace cl
33{
34 class CommandQueue;
35}
36
37namespace acl
38{
39 extern const std::string INDEX;
41
42 class ElementBase;
43 typedef std::shared_ptr<ElementBase> Element;
44 typedef std::shared_ptr<cl::CommandQueue> CommandQueue;
45
48 bool compatible(unsigned int size1, CommandQueue queue1,
49 unsigned int size2, CommandQueue queue2);
50 bool compatible(unsigned int size, CommandQueue queue, Element e);
52
54 inline bool compatibleSizes(unsigned int s1, unsigned int s2);
58 bool compatibleSizes(unsigned int s, Element e);
59
61 unsigned int paddingBytes(unsigned int size,
62 unsigned int typeSize,
63 CommandQueue queue);
64
66 unsigned int paddingElements(unsigned int size,
67 const KernelConfiguration & kernelConfig);
68
73
75
77
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
ACL Kernel configuration class.
const KernelConfiguration KERNEL_BASIC
std::string numToStr(T i)
Converts numbers or another type to string.
Advanced Computational Language.
Definition acl.h:41
const std::string INDEX
std::shared_ptr< cl::CommandQueue > CommandQueue
Definition acl.h:51
bool compatible(unsigned int size1, CommandQueue queue1, unsigned int size2, CommandQueue queue2)
constexpr const TypeID typeToTypeID()
bool onSameDevice(CommandQueue queue1, CommandQueue queue2)
checks whether both elements reside on the same device
constexpr const TypeID typeToTypeID< cl_int >()
unsigned int paddingBytes(unsigned int size, unsigned int typeSize, CommandQueue queue)
Adds padding in bytes based on the device's alignment.
constexpr const TypeID typeToTypeID< cl_uint >()
TypeID
Definition aclTypes.h:39
@ TYPE_INT
Definition aclTypes.h:40
@ TYPE_LONG
Definition aclTypes.h:44
@ TYPE_UINT
Definition aclTypes.h:41
@ TYPE_DOUBLE
Definition aclTypes.h:43
@ TYPE_FLOAT
Definition aclTypes.h:42
unsigned int paddingElements(unsigned int size, const KernelConfiguration &kernelConfig)
Adds padding in elements based on vector width.
bool isDeclarable(Element e)
constexpr const TypeID typeToTypeID< cl_float >()
const std::string & typeToStr()
bool compatibleSizes(unsigned int s, const VectorOfElements &a)
constexpr const TypeID typeToTypeID< cl_long >()
bool isArgument(Element e)
void addElementToKernelSource(Element e, std::vector< Element > &arguments, std::vector< Element > &localDeclarations)
adds e either to arguments or to localDeclarations
constexpr const TypeID typeToTypeID< cl_double >()
std::shared_ptr< ElementBase > Element
Definition acl.h:49
The OpenCL C++ bindings are defined within this namespace.
Definition acl.h:34