SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
reduce.h
Go to the documentation of this file.
1 
5 #ifndef REDUCE_H
6 #define REDUCE_H
7 
8 
9 #include <starpu.h>
10 #ifdef SKEPU_OPENCL
11  #include <starpu_opencl.h>
12 #endif
13 
14 
15 #ifdef SKEPU_OPENCL
16 #include <string>
17 #include <vector>
18 #ifdef USE_MAC_OPENCL
19 #include <OpenCL/opencl.h>
20 #else
21 #include <CL/cl.h>
22 #endif
23 #include "src/device_cl.h"
24 #endif
25 
26 #include "src/environment.h"
27 #include "skepu/vector.h"
28 #include "skepu/task.h"
29 #include "src/operator_macros.h"
30 #include "src/exec_plan.h"
31 #include "skepu/task.h"
32 
33 namespace skepu
34 {
35 
36  #define MAX_REDUCE_PART 10
37 
59 template <typename ReduceFunc, typename T>
60 class Reduce: public Task
61 {
62 
63 public:
64 // typename ReduceFunc::TYPE resultValue;
65  starpu_data_handle_t scalar_result_handle;
66  bool isScalarStarPU;
67 
68  Reduce(ReduceFunc* reduceFunc);
69 
70  Reduce(ReduceFunc* reduceFunc, Vector<T> *in, T *out);
71 
72  ~Reduce();
73 
74 
75  void *get_result()
76  {
77  if(isScalarStarPU)
78  {
79  starpu_data_unregister(scalar_result_handle); // unregister as this data can be modified
80  isScalarStarPU = false;
81  }
82 
83  return output;
84  }
85 
86 
87  void setInput(Vector<T> *in)
88  {
89  input = in;
90  }
91 
92  void setOutput(T *out)
93  {
94  if(isScalarStarPU)
95  starpu_data_acquire(scalar_result_handle, STARPU_W);
96 
97  output = out;
98 
99  if(isScalarStarPU)
100  starpu_data_release(scalar_result_handle);
101  }
102 
103  T getOutput()
104  {
105  if(isScalarStarPU)
106  {
107  T _output;
108  starpu_data_acquire(scalar_result_handle, STARPU_R); // acquire as we know that it is just a read access…
109  _output = *output;
110  starpu_data_release(scalar_result_handle); // release acquire before returning control…
111  return _output;
112  }
113  return *output;
114  }
115 
116  void run_async();
117 
118  void finishAll() {m_environment->finishAll();}
119  void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
120 
121 private:
122  Environment<int>* m_environment;
123  ReduceFunc* m_reduceFunc;
124  ExecPlan m_execPlan;
125 
126 #ifdef USE_STARPU_HISTORY_MODEL
127  starpu_perfmodel *red_perf_model;
128 #endif
129 
130  struct starpu_codelet *codelet;
131 
132  #ifdef UNEVEN_PART
133  struct starpu_codelet *codelet2;
134  #endif
135 
136 public:
137  T operator()(Vector<T>& input);
138 
139  T operator()(Vector<T>& input, int parts);
140 
141 public:
142  static void cpu_func(void *buffers[], void *arg);
143 
144 #ifdef SKEPU_OPENMP
145 public:
146  static void omp_func(void *buffers[], void *arg);
147 #endif
148 
149 #ifdef SKEPU_CUDA
150 public:
151  static void cuda_func(void *buffers[], void *arg);
152 #endif
153 
154 #ifdef SKEPU_OPENCL
155 public:
156  static void opencl_func(void *buffers[], void *arg);
157 
158 public:
159  struct starpu_opencl_program opencl_codelet;
160 
161 
162  char kernelNameArray[1028];
163 
164  void replaceText(std::string& text, std::string find, std::string replace);
165  void createOpenCLProgram();
166 #endif
167 
168 private:
169  std::string perfmodel_str;
170 
171  Vector<T> *input;
172  T *output;
173  Vector<T> *temp_output;
174 // T *inter_output[MAX_REDUCE_PART];
175 
176 };
177 
178 }
179 
180 #include "src/reduce.inl"
181 
182 #include "src/reduce_cpu.inl"
183 
184 #ifdef SKEPU_OPENMP
185 #include "src/reduce_omp.inl"
186 #endif
187 
188 #ifdef SKEPU_OPENCL
189 #include "src/reduce_cl.inl"
190 #endif
191 
192 #ifdef SKEPU_CUDA
193 #include "src/reduce_cu.inl"
194 #endif
195 
196 #endif
197 
static void opencl_func(void *buffers[], void *arg)
Definition: reduce_cl.inl:92
Reduce(ReduceFunc *reduceFunc)
Definition: reduce.inl:19
Includes the macro files needed for the defined backends.
Contains the definitions of OpenMP specific functions for the Reduce skeleton.
void finishAll()
Definition: environment.inl:119
void replaceText(std::string &text, std::string find, std::string replace)
Definition: reduce_cl.inl:26
void createOpenCLProgram()
Definition: reduce_cl.inl:47
Contains the definitions of CPU specific functions for the Reduce skeleton.
Contains a class declaration for the object that represents an OpenCL device.
static void omp_func(void *buffers[], void *arg)
Definition: reduce_omp.inl:27
Contains the definitions of non-backend specific functions for the Reduce skeleton.
Contains the definitions of CUDA specific functions for the Reduce skeleton.
A vector container class, implemented as a wrapper for std::vector. It is configured to use StarPU DS...
Definition: vector.h:40
~Reduce()
Definition: reduce.inl:209
A class that describes an execution plan, not used very much in this case as decision is mostly left ...
Definition: exec_plan.h:75
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.
A class representing the Reduce skeleton.
Definition: reduce.h:60
Contains a class declaration for Environment class.
static void cuda_func(void *buffers[], void *arg)
Definition: reduce_cu.inl:27
static void cpu_func(void *buffers[], void *arg)
Definition: reduce_cpu.inl:21
void run_async()
Definition: reduce.inl:237
T operator()(Vector< T > &input)
Definition: reduce.inl:260
Contains a class that stores information about which back ends to use when executing.
Contains the definitions of OpenCL specific functions for the Reduce skeleton.