SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
scan.h
Go to the documentation of this file.
1 
5 #ifndef SCAN_H
6 #define SCAN_H
7 
8 
9 
10 #include <starpu.h>
11 #ifdef SKEPU_OPENCL
12  #include <starpu_opencl.h>
13 #endif
14 
15 
16 
17 #ifdef SKEPU_OPENCL
18 #include <string>
19 #include <vector>
20 #ifdef USE_MAC_OPENCL
21 #include <OpenCL/opencl.h>
22 #else
23 #include <CL/cl.h>
24 #endif
25 #include "src/device_cl.h"
26 #endif
27 
28 #include "src/environment.h"
29 #include "skepu/vector.h"
30 #include "skepu/task.h"
31 #include "src/operator_macros.h"
32 #include "src/exec_plan.h"
33 
34 #ifdef SKEPU_CUDA
36 #include "src/device_cu.h"
37 
38 #endif
39 
40 namespace skepu
41 {
42 
47 {
48  INCLUSIVE,
49  EXCLUSIVE
50 };
51 
80 template <typename ScanFunc, typename T>
81 class Scan: public Task
82 {
83 
84 typedef struct
85 {
86  Scan<ScanFunc,T> *pScan;
87  bool unaryOperand;
88  ScanType type;
89  T initValue;
90 }ArgumentBuffer;
91 
92 public:
93  ScanType type;
94  T initValue;
95  Vector<T> *input;
96  Vector<T> *output;
97 
98  Scan(ScanFunc* scanFunc);
99 
100  Scan(ScanFunc* scanFunc, Vector<T> *in, Vector<T> *out, ScanType type, T init = T());
101 
102  ~Scan();
103 
104  Vector<T>& getOutput()
105  {
106  return *output;
107  }
108 
109  void *get_result()
110  {
111  return output;
112  }
113 
114  void setInput(Vector<T> *in)
115  {
116  input = in;
117  }
118 
119  void setOutput(Vector<T> *out)
120  {
121  output = out;
122  }
123 
124  void setInitValue(T _init)
125  {
126  initValue = _init;
127  }
128 
129  void run_async();
130 
131  void finishAll() {m_environment->finishAll();}
132  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
133 
134 public:
135  Environment<int>* m_environment;
136  ScanFunc* m_scanFunc;
137  ExecPlan m_execPlan;
138 
139  struct starpu_codelet *codelet;
140  struct starpu_codelet *codelet_two;
141 
142  bool unaryOperand;
143 
144 #ifdef USE_STARPU_HISTORY_MODEL
145  starpu_perfmodel *scan1_perf_model;
146  starpu_perfmodel *scan2_perf_model;
147 #endif
148 
149 public:
150  void operator()(Vector<T>& input, ScanType type, T init = T());
151 
152  void operator()(Vector<T>& input, Vector<T>& output, ScanType type, T init = T());
153 
154 public:
155  static void cpu_func(void *buffers[], void *arg);
156 
157 #ifdef SKEPU_OPENMP
158 public:
159  static void omp_func(void *buffers[], void *arg);
160 #endif
161 
162 #ifdef SKEPU_CUDA
163 public:
164  static void cuda_func(void *buffers[], void *arg);
165 
166  T scanLargeVectorRecursively_CU(T* input, T* output, std::vector<DeviceMemPointer_CU<T>*>& blockSums, unsigned int numElements, int level, ScanType type, T init, int deviceID);
167 #endif
168 
169 #ifdef SKEPU_OPENCL
170 public:
171  static void opencl_func(void *buffers[], void *arg);
172 
173  T scanLargeVectorRecursively_CL(T* input, T* output, std::vector<DeviceMemPointer_CL<T>*>& blockSums, unsigned int numElements, int level, ScanType type, T init, Device_CL *deviceCL);
174 
175 public:
176  struct starpu_opencl_program opencl_codelet;
177  char kernelNameScan[1024];
178  char kernelNameScanUpdate[1024];
179  char kernelNameScanAdd[1024];
180 
181  void replaceText(std::string& text, std::string find, std::string replace);
182  void createOpenCLProgram();
183 #endif
184 
185  std::string perfmodel1_str;
186  std::string perfmodel2_str;
187 
188 };
189 
190 }
191 
192 #include "src/scan.inl"
193 
194 #include "src/scan_cpu.inl"
195 
196 #ifdef SKEPU_OPENMP
197 #include "src/scan_omp.inl"
198 #endif
199 
200 #ifdef SKEPU_OPENCL
201 #include "src/scan_cl.inl"
202 #endif
203 
204 #ifdef SKEPU_CUDA
205 #include "src/scan_cu.inl"
206 #endif
207 
208 #endif
209 
Contains a class declaration for an object which represents an CUDA device memory allocation...
~Scan()
Definition: scan.inl:240
Includes the macro files needed for the defined backends.
void operator()(Vector< T > &input, ScanType type, T init=T())
Definition: scan.inl:263
static void opencl_func(void *buffers[], void *arg)
Definition: scan_cl.inl:101
T scanLargeVectorRecursively_CU(T *input, T *output, std::vector< DeviceMemPointer_CU< T > * > &blockSums, unsigned int numElements, int level, ScanType type, T init, int deviceID)
Definition: scan_cu.inl:36
void finishAll()
Definition: environment.inl:119
Contains the definitions of OpenCL specific functions for the Scan skeleton.
A class representing an OpenCL device memory allocation.
Definition: device_mem_pointer_cl.h:38
Contains a class declaration for the object that represents an OpenCL device.
Contains the definitions of OpenMP specific functions for the Scan skeleton.
void run_async()
Definition: scan.inl:220
Contains the definitions of non-backend specific functions for the Scan skeleton. ...
void createOpenCLProgram()
Definition: scan_cl.inl:48
Scan(ScanFunc *scanFunc)
Definition: scan.inl:21
Contains a class declaration for the object that represents a CUDA device.
A vector container class, implemented as a wrapper for std::vector. It is configured to use StarPU DS...
Definition: vector.h:40
static void omp_func(void *buffers[], void *arg)
Definition: scan_omp.inl:26
A class that describes an execution plan, not used very much in this case as decision is mostly left ...
Definition: exec_plan.h:75
void replaceText(std::string &text, std::string find, std::string replace)
Definition: scan_cl.inl:26
A class representing a CUDA device memory allocation.
Definition: device_mem_pointer_cu.h:34
Contains a class definition for Task.
A class representing a Task for the farm skeleton.
Definition: task.h:31
Contains a class declaration for the Vector container.
Contains a class declaration for Environment class.
static void cpu_func(void *buffers[], void *arg)
Definition: scan_cpu.inl:21
T scanLargeVectorRecursively_CL(T *input, T *output, std::vector< DeviceMemPointer_CL< T > * > &blockSums, unsigned int numElements, int level, ScanType type, T init, Device_CL *deviceCL)
Definition: scan_cl.inl:187
A class representing an OpenCL device.
Definition: device_cl.h:37
Contains the definitions of CUDA specific functions for the Scan skeleton.
static void cuda_func(void *buffers[], void *arg)
Definition: scan_cu.inl:89
A class representing the Scan skeleton.
Definition: scan.h:81
Contains a class that stores information about which back ends to use when executing.
Contains the definitions of CPU specific functions for the Scan skeleton.
ScanType
Definition: scan.h:46