ASL  0.1.6
Advanced Simulation Library
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"
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;
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);
51  bool compatible(Element e1, Element e2);
52 
54  inline bool compatibleSizes(unsigned int s1, unsigned int s2);
56  bool compatibleSizes(Element e1, Element e2);
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 
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 
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
constexpr const TypeID typeToTypeID< cl_long >()
Definition: aclUtilities.h:115
bool isDeclarable(Element e)
Advanced Computational Language.
Definition: acl.h:40
bool compatibleSizes(unsigned int s, Element e)
if s and size of e are the same or at least one of them is 0
The OpenCL C++ bindings are defined within this namespace.
Definition: acl.h:33
constexpr const TypeID typeToTypeID< cl_int >()
Definition: aclUtilities.h:105
std::string numToStr(T i)
Converts numbers or another type to string.
Definition: aslUtilities.h:48
constexpr const TypeID typeToTypeID< cl_float >()
Definition: aclUtilities.h:100
const std::string typeToStr(unsigned int i)
Definition: aclUtilities.h:120
std::shared_ptr< cl::CommandQueue > CommandQueue
Definition: acl.h:51
constexpr const TypeID typeToTypeID< cl_uint >()
Definition: aclUtilities.h:110
void addElementToKernelSource(Element e, std::vector< Element > &arguments, std::vector< Element > &localDeclarations)
adds e either to arguments or to localDeclarations
unsigned int paddingElements(unsigned int size, const KernelConfiguration &kernelConfig)
Adds padding in elements based on vector width.
unsigned int paddingBytes(unsigned int size, unsigned int typeSize, CommandQueue queue)
Adds padding in bytes based on the device&#39;s alignment.
ACL Kernel configuration class.
bool onSameDevice(Element e1, Element e2)
std::shared_ptr< ElementBase > Element
Definition: acl.h:49
constexpr const TypeID typeToTypeID()
TypeID
Definition: aclTypes.h:38
bool compatible(Element e1, Element e2)
useful common utilities
const KernelConfiguration KERNEL_BASIC
bool isArgument(Element e)
const std::string INDEX
Definition: aclUtilities.h:39
constexpr const TypeID typeToTypeID< cl_double >()
Definition: aclUtilities.h:95