Go to the documentation of this file.00001
00005 #ifndef REDUCE_H
00006 #define REDUCE_H
00007
00008 #ifdef SKEPU_OPENCL
00009 #include <string>
00010 #include <vector>
00011 #include <CL/cl.h>
00012 #include "src/device_cl.h"
00013 #endif
00014
00015 #include "src/environment.h"
00016 #include "skepu/vector.h"
00017 #include "src/operator_macros.h"
00018 #include "src/exec_plan.h"
00019
00020 namespace skepu
00021 {
00022
00045 template <typename ReduceFunc>
00046 class Reduce
00047 {
00048
00049 public:
00050
00051 Reduce(ReduceFunc* reduceFunc);
00052
00053 ~Reduce();
00054
00055 void finishAll() {m_environment->finishAll();}
00056 void setExecPlan(ExecPlan& plan) {m_execPlan = plan;}
00057
00058 private:
00059 Environment<int>* m_environment;
00060 ReduceFunc* m_reduceFunc;
00061 ExecPlan m_execPlan;
00062
00063 public:
00064 template <typename T>
00065 T operator()(Vector<T>& input);
00066
00067 template <typename InputIterator>
00068 typename InputIterator::value_type operator()(InputIterator inputBegin, InputIterator inputEnd);
00069
00070 public:
00071 template <typename T>
00072 T CPU(Vector<T>& input);
00073
00074 template <typename InputIterator>
00075 typename InputIterator::value_type CPU(InputIterator inputBegin, InputIterator inputEnd);
00076
00077 #ifdef SKEPU_OPENMP
00078 public:
00079 template <typename T>
00080 T OMP(Vector<T>& input);
00081
00082 template <typename InputIterator>
00083 typename InputIterator::value_type OMP(InputIterator inputBegin, InputIterator inputEnd);
00084 #endif
00085
00086 #ifdef SKEPU_CUDA
00087 public:
00088 template <typename T>
00089 T CU(Vector<T>& input, int useNumGPU = 1);
00090
00091 template <typename InputIterator>
00092 typename InputIterator::value_type CU(InputIterator inputBegin, InputIterator inputEnd, int useNumGPU = 1);
00093
00094 private:
00095 template <typename InputIterator>
00096 typename InputIterator::value_type reduceSingleThread_CU(InputIterator inputBegin, InputIterator inputEnd, int deviceID);
00097 #endif
00098
00099 #ifdef SKEPU_OPENCL
00100 public:
00101 template <typename T>
00102 T CL(Vector<T>& input, int useNumGPU = 1);
00103
00104 template <typename InputIterator>
00105 typename InputIterator::value_type CL(InputIterator inputBegin, InputIterator inputEnd, int useNumGPU = 1);
00106
00107 private:
00108 template <typename InputIterator>
00109 typename InputIterator::value_type reduceSingle_CL(InputIterator inputBegin, InputIterator inputEnd, int deviceID);
00110
00111 template <typename InputIterator>
00112 typename InputIterator::value_type reduceNumDevices_CL(InputIterator inputBegin, InputIterator inputEnd, int numDevices);
00113
00114 private:
00115 std::vector<std::pair<cl_kernel, Device_CL*> > m_kernels_CL;
00116
00117 void replaceText(std::string& text, std::string find, std::string replace);
00118 void createOpenCLProgram();
00119 #endif
00120
00121 };
00122
00123 }
00124
00125 #include "src/reduce.inl"
00126
00127 #include "src/reduce_cpu.inl"
00128
00129 #ifdef SKEPU_OPENMP
00130 #include "src/reduce_omp.inl"
00131 #endif
00132
00133 #ifdef SKEPU_OPENCL
00134 #include "src/reduce_cl.inl"
00135 #endif
00136
00137 #ifdef SKEPU_CUDA
00138 #include "src/reduce_cu.inl"
00139 #endif
00140
00141 #endif