ASL  0.1.7
Advanced Simulation Library
aclKernel.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 ACLKERNEL_H
25 #define ACLKERNEL_H
26 
27 #include "aclExpressionContainer.h"
28 #include "aclKernelConfiguration.h"
29 //#include <CL/cl.hpp>
30 // Supply "cl.hpp" with ASL, since it is not present in OpenCL 2.0
31 // Remove the file after switching to OpenCL 2.1
32 #include "acl/cl.hpp"
33 
34 namespace acl
35 {
36 
37  extern const KernelConfiguration KERNEL_BASIC;
38 
40 
49  {
50  protected:
51  static unsigned int kernelNum;
52  unsigned int id;
53  unsigned int groupsNumber;
55  std::string kernelSource;
57 
59  cl_uint detectVectorWidth();
60  void generateExtensions();
61  void generateArguments();
62  void generateIndex();
64  void generateExpressions();
65  virtual void generateKernelSource();
67  void buildKernel();
68  void setKernelArguments();
69  public:
70  explicit Kernel(const KernelConfiguration kernelConfig_ = KERNEL_BASIC);
74  void setup();
75  void compute();
76  void setGroupsNumber(unsigned int n);
77  unsigned int getGroupsNumber();
78  std::string getKernelSource();
79  unsigned int getKernelID();
80  const cl::Kernel & getKernel() const;
82  void clear();
83  inline const KernelConfiguration & getConfiguration()const;
84 
85  friend class KernelMerger;
86  };
87 
89  typedef std::shared_ptr<Kernel> SPKernel;
90 
93  void inline createKernels(std::vector<SPKernel> & vk,
94  unsigned int n,
95  const KernelConfiguration & kernelConfig_ = KERNEL_BASIC);
96 
97 
98 //---------------------------- Implementation -----------------------------
99 
100  void inline createKernels(std::vector<SPKernel> & vk,
101  unsigned int n,
102  const KernelConfiguration & kernelConfig_)
103  {
104  vk.resize(n);
105  for (unsigned int i(0); i < n; ++i)
106  {
107  vk[i].reset(new Kernel(kernelConfig_));
108  }
109  }
110 
112  {
113  return kernelConfig;
114  }
115 
116 
117 } // namespace acl
118 
119 #endif // ACLKERNEL_H
void generateExtensions()
Kernel(const KernelConfiguration kernelConfig_=KERNEL_BASIC)
void setGroupsNumber(unsigned int n)
Advanced Computational Language.
Definition: acl.h:40
void generateExpressions()
unsigned int groupsNumber
Definition: aclKernel.h:53
virtual void generateKernelSource()
void generateLocalDeclarations()
void updateKernelConfiguration()
cl_uint detectVectorWidth()
detects minimal vector width of all available types of Elements
std::string getKernelSource()
OpenCl Kernel merger.
OpenCl Kernel generator.
Definition: aclKernel.h:48
std::shared_ptr< Kernel > SPKernel
Definition: aclKernel.h:89
void buildKernel()
C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and OpenCL 1.2 (rev 15)
KernelConfiguration kernelConfig
Definition: aclKernel.h:54
void clear()
removes all expressions from the kernel
const KernelConfiguration & getConfiguration() const
Definition: aclKernel.h:111
unsigned int getKernelID()
void generateArguments()
static unsigned int kernelNum
Definition: aclKernel.h:51
ACL Kernel configuration class.
unsigned int getGroupsNumber()
void setKernelArguments()
void generateIndex()
void createKernels(std::vector< SPKernel > &vk, unsigned int n, const KernelConfiguration &kernelConfig_)
Definition: aclKernel.h:100
const cl::Kernel & getKernel() const
Class interface for cl_kernel.
Definition: cl.hpp:4721
std::string kernelSource
Definition: aclKernel.h:55
void compute()
unsigned int id
Definition: aclKernel.h:52
const KernelConfiguration KERNEL_BASIC
cl::Kernel kernel
Definition: aclKernel.h:56
void setup()