SkePU  1.2
 All Classes Namespaces Files Functions Variables Enumerations Friends Macros Groups Pages
generate.h
Go to the documentation of this file.
1 
5 #ifndef GENERATE_H
6 #define GENERATE_H
7 
8 #ifdef SKEPU_OPENCL
9 #include <string>
10 #include <vector>
11 #ifdef USE_MAC_OPENCL
12 #include <OpenCL/opencl.h>
13 #else
14 #include <CL/cl.h>
15 #endif
16 #include "src/device_cl.h"
17 #endif
18 
19 #include "src/environment.h"
20 
21 #include "skepu/vector.h"
22 #include "skepu/matrix.h"
23 
24 #include "src/operator_macros.h"
25 #include "src/exec_plan.h"
26 
27 namespace skepu
28 {
29 
52 template <typename GenerateFunc>
53 class Generate
54 {
55 
56 public:
57 
58  Generate(GenerateFunc* generateFunc);
59 
60  ~Generate();
61 
65  template <typename T>
66  void setConstant(T constant1)
67  {
68  m_generateFunc->setConstant(constant1);
69  }
70 
74  void finishAll()
75  {
76  m_environment->finishAll();
77  }
78  void setExecPlan(ExecPlan& plan)
79  {
80  m_execPlan = &plan;
81  }
82  void setExecPlan(ExecPlan *plan)
83  {
84  m_execPlanMulti = plan;
85  }
86 
87 private:
88  Environment<int>* m_environment;
89  GenerateFunc* m_generateFunc;
90 
92  ExecPlan *m_execPlanMulti;
93 
95  ExecPlan *m_execPlan;
96 
98  ExecPlan m_defPlan;
99 
100 
101 public:
102  template <typename T>
103  void operator()(size_t numElements, Vector<T>& output);
104 
105  template <typename T>
106  void operator()(size_t numRows, size_t numCols, Matrix<T>& output);
107 
108  template <typename OutputIterator>
109  void operator()(size_t numElements, OutputIterator outputBegin);
110 
111 public:
112  template <typename T>
113  void CPU(size_t numElements, Vector<T>& output);
114 
115  template <typename T>
116  void CPU(size_t numRows, size_t numCols, Matrix<T>& output);
117 
118  template <typename OutputIterator>
119  void CPU(size_t numElements, OutputIterator outputBegin);
120 
121 
122 #ifdef SKEPU_OPENMP
123 public:
124  template <typename T>
125  void OMP(size_t numElements, Vector<T>& output);
126 
127  template <typename T>
128  void OMP(size_t numRows, size_t numCols, Matrix<T>& output);
129 
130  template <typename OutputIterator>
131  void OMP(size_t numElements, OutputIterator outputBegin);
132 
133 #endif
134 
135 #ifdef SKEPU_CUDA
136 public:
137  template <typename T>
138  void CU(size_t numElements, Vector<T>& output, int useNumGPU = 1);
139 
140  template <typename T>
141  void CU(size_t numRows, size_t numCols, Matrix<T>& output, int useNumGPU = 1);
142 
143  template <typename OutputIterator>
144  void CU(size_t numElements, OutputIterator outputBegin, int useNumGPU = 1);
145 
146 private:
147  unsigned int cudaDeviceID;
148 
149  template <typename OutputIterator>
150  void generateSingleThread_CU(size_t numElements, OutputIterator outputBegin, unsigned int deviceID);
151 
152 #endif
153 
154 #ifdef SKEPU_OPENCL
155 public:
156  template <typename T>
157  void CL(size_t numElements, Vector<T>& output, int useNumGPU = 1);
158 
159  template <typename T>
160  void CL(size_t numRows, size_t numCols, Matrix<T>& output, int useNumGPU = 1);
161 
162  template <typename OutputIterator>
163  void CL(size_t numElements, OutputIterator outputBegin, int useNumGPU = 1);
164 
165 private:
166  template <typename OutputIterator>
167  void generateNumDevices_CL(size_t numElements, OutputIterator outputBegin, size_t numDevices);
168 
169 private:
170  std::vector<std::pair<cl_kernel, Device_CL*> > m_kernels_CL;
171 
172  void createOpenCLProgram();
173 #endif
174 
175 };
176 
177 }
178 
179 #include "src/generate.inl"
180 
181 #include "src/generate_cpu.inl"
182 
183 #ifdef SKEPU_OPENMP
184 #include "src/generate_omp.inl"
185 #endif
186 
187 #ifdef SKEPU_OPENCL
188 #include "src/generate_cl.inl"
189 #endif
190 
191 #ifdef SKEPU_CUDA
192 #include "src/generate_cu.inl"
193 #endif
194 
195 #endif
196 
197 
Contains the definitions of CUDA specific member functions for the Generate skeleton.
void operator()(size_t numElements, Vector< T > &output)
Definition: generate.inl:102
Generate(GenerateFunc *generateFunc)
Definition: generate.inl:21
Includes the macro files needed for the defined backends.
Contains the definitions of CPU specific member functions for the Generate skeleton.
void finishAll()
Definition: environment.inl:575
A class representing the Generate skeleton.
Definition: generate.h:53
void CL(size_t numElements, Vector< T > &output, int useNumGPU=1)
Definition: generate_cl.inl:217
Contains a class declaration for the object that represents an OpenCL device.
void setConstant(T constant1)
Definition: generate.h:66
void CU(size_t numElements, Vector< T > &output, int useNumGPU=1)
Definition: generate_cu.inl:70
void OMP(size_t numElements, Vector< T > &output)
Definition: generate_omp.inl:26
Contains the definitions of non-backend specific member functions for the Generate skeleton...
void finishAll()
Definition: generate.h:74
Contains a class declaration for the Matrix container.
~Generate()
Definition: generate.inl:83
A class that describes an execution plan.
Definition: exec_plan.h:47
void CPU(size_t numElements, Vector< T > &output)
Definition: generate_cpu.inl:23
Contains a class declaration for the Vector container.
Contains a class declaration for Environment class.
A class representing the column-wise iterator for the Matrix data-type.
Contains a class that stores information about which back ends to use when executing.
Contains the definitions of OpenCL specific member functions for the Generate skeleton.
Contains the definitions of OpenMP specific member functions for the Generate skeleton.