|
SkePU 0.7
|
00001 00005 #ifndef SCAN_H 00006 #define SCAN_H 00007 00008 #ifdef SKEPU_OPENCL 00009 #include <string> 00010 #include <vector> 00011 #ifdef USE_MAC_OPENCL 00012 #include <OpenCL/opencl.h> 00013 #else 00014 #include <CL/cl.h> 00015 #endif 00016 #include "src/device_cl.h" 00017 #endif 00018 00019 #include "src/environment.h" 00020 #include "skepu/vector.h" 00021 #include "src/operator_macros.h" 00022 #include "src/exec_plan.h" 00023 00024 namespace skepu 00025 { 00026 00030 enum ScanType 00031 { 00032 INCLUSIVE, 00033 EXCLUSIVE 00034 }; 00035 00062 template <typename ScanFunc> 00063 class Scan 00064 { 00065 00066 public: 00067 00068 Scan(ScanFunc* scanFunc); 00069 00070 ~Scan(); 00071 00072 void finishAll() {m_environment->finishAll();} 00073 void setExecPlan(ExecPlan& plan) {m_execPlan = plan;} 00074 00075 private: 00076 Environment<int>* m_environment; 00077 ScanFunc* m_scanFunc; 00078 ExecPlan m_execPlan; 00079 00080 public: 00081 template <typename T> 00082 void operator()(Vector<T>& input, ScanType type, T init = T()); 00083 00084 template <typename InputIterator> 00085 void operator()(InputIterator inputBegin, InputIterator inputEnd, ScanType type, typename InputIterator::value_type init = typename InputIterator::value_type()); 00086 00087 template <typename T> 00088 void operator()(Vector<T>& input, Vector<T>& output, ScanType type, T init = T()); 00089 00090 template <typename InputIterator, typename OutputIterator> 00091 void operator()(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init = typename InputIterator::value_type()); 00092 00093 public: 00094 template <typename T> 00095 void CPU(Vector<T>& input, ScanType type = INCLUSIVE, T init = T()); 00096 00097 template <typename InputIterator> 00098 void CPU(InputIterator inputBegin, InputIterator inputEnd, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type()); 00099 00100 template <typename T> 00101 void CPU(Vector<T>& input, Vector<T>& output, ScanType type = INCLUSIVE, T init = T()); 00102 00103 template <typename InputIterator, typename OutputIterator> 00104 void CPU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type()); 00105 00106 #ifdef SKEPU_OPENMP 00107 public: 00108 template <typename T> 00109 void OMP(Vector<T>& input, ScanType type = INCLUSIVE, T init = T()); 00110 00111 template <typename InputIterator> 00112 void OMP(InputIterator inputBegin, InputIterator inputEnd, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type()); 00113 00114 template <typename T> 00115 void OMP(Vector<T>& input, Vector<T>& output, ScanType type = INCLUSIVE, T init = T()); 00116 00117 template <typename InputIterator, typename OutputIterator> 00118 void OMP(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type()); 00119 #endif 00120 00121 #ifdef SKEPU_CUDA 00122 public: 00123 template <typename T> 00124 void CU(Vector<T>& input, ScanType type = INCLUSIVE, T init = T(), int useNumGPU = 1); 00125 00126 template <typename InputIterator> 00127 void CU(InputIterator inputBegin, InputIterator inputEnd, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type(), int useNumGPU = 1); 00128 00129 template <typename T> 00130 void CU(Vector<T>& input, Vector<T>& output, ScanType type = INCLUSIVE, T init = T(), int useNumGPU = 1); 00131 00132 template <typename InputIterator, typename OutputIterator> 00133 void CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type(), int useNumGPU = 1); 00134 00135 private: 00136 template <typename InputIterator, typename OutputIterator> 00137 void scanSingleThread_CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, int deviceID); 00138 00139 template <typename T> 00140 T scanLargeVectorRecursively_CU(DeviceMemPointer_CU<T>* input, DeviceMemPointer_CU<T>* output, std::vector<DeviceMemPointer_CU<T>*>& blockSums, unsigned int numElements, int level, ScanType type, T init, int deviceID); 00141 00142 #endif 00143 00144 #ifdef SKEPU_OPENCL 00145 public: 00146 template <typename T> 00147 void CL(Vector<T>& input, ScanType type = INCLUSIVE, T init = T(), int useNumGPU = 1); 00148 00149 template <typename InputIterator> 00150 void CL(InputIterator inputBegin, InputIterator inputEnd, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type(), int useNumGPU = 1); 00151 00152 template <typename T> 00153 void CL(Vector<T>& input, Vector<T>& output, ScanType type = INCLUSIVE, T init = T(), int useNumGPU = 1); 00154 00155 template <typename InputIterator, typename OutputIterator> 00156 void CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type = INCLUSIVE, typename InputIterator::value_type init = typename InputIterator::value_type(), int useNumGPU = 1); 00157 00158 private: 00159 template <typename InputIterator, typename OutputIterator> 00160 void scanSingle_CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, int deviceID); 00161 00162 template <typename InputIterator, typename OutputIterator> 00163 void scanNumDevices_CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, int numDevices); 00164 00165 template <typename T> 00166 T scanLargeVectorRecursively_CL(DeviceMemPointer_CL<T>* input, DeviceMemPointer_CL<T>* output, std::vector<DeviceMemPointer_CL<T>*>& blockSums, unsigned int numElements, int level, ScanType type, T init, int deviceID); 00167 00168 private: 00169 std::vector<std::pair<cl_kernel, Device_CL*> > m_scanKernels_CL; 00170 std::vector<std::pair<cl_kernel, Device_CL*> > m_scanUpdateKernels_CL; 00171 std::vector<std::pair<cl_kernel, Device_CL*> > m_scanAddKernels_CL; 00172 00173 void replaceText(std::string& text, std::string find, std::string replace); 00174 void createOpenCLProgram(); 00175 #endif 00176 00177 }; 00178 00179 } 00180 00181 #include "src/scan.inl" 00182 00183 #include "src/scan_cpu.inl" 00184 00185 #ifdef SKEPU_OPENMP 00186 #include "src/scan_omp.inl" 00187 #endif 00188 00189 #ifdef SKEPU_OPENCL 00190 #include "src/scan_cl.inl" 00191 #endif 00192 00193 #ifdef SKEPU_CUDA 00194 #include "src/scan_cu.inl" 00195 #endif 00196 00197 #endif 00198
1.7.4