|
SkePU 0.7
|
00001 00005 #ifndef MAP_ARRAY_H 00006 #define MAP_ARRAY_H 00007 00008 00009 00010 #include <starpu.h> 00011 #ifdef SKEPU_OPENCL 00012 #include <starpu_opencl.h> 00013 #endif 00014 00015 00016 #ifdef SKEPU_OPENCL 00017 #include <string> 00018 #include <vector> 00019 #ifdef USE_MAC_OPENCL 00020 #include <OpenCL/opencl.h> 00021 #else 00022 #include <CL/cl.h> 00023 #endif 00024 #include "src/device_cl.h" 00025 #endif 00026 00027 #include "src/environment.h" 00028 #include "skepu/task.h" 00029 #include "skepu/vector.h" 00030 #include "src/operator_macros.h" 00031 #include "src/exec_plan.h" 00032 00033 namespace skepu 00034 { 00035 00062 template <typename MapArrayFunc, typename T, skepu_container_type c_type=SKEPU_VECTOR> 00063 class MapArray: public Task 00064 { 00065 00066 typedef struct 00067 { 00068 MapArray<MapArrayFunc,T, c_type> *pMapArr; 00069 bool parts; 00070 }ArgumentBuffer; 00071 00072 public: 00073 00074 MapArray(MapArrayFunc* mapArrayFunc); 00075 00076 MapArray(MapArrayFunc* mapArrayFunc, Vector<T> *in1, Vector<T> *in2, Vector<T> *out, int _parts=1); 00077 00078 ~MapArray(); 00079 00080 Vector<T>& getOutput() 00081 { 00082 return *output; 00083 } 00084 00085 void *get_result() 00086 { 00087 return output; 00088 } 00089 00090 00091 void setInput1(Vector<T> *in) 00092 { 00093 input1 = in; 00094 } 00095 00096 void setInput2(Vector<T> *in) 00097 { 00098 input2 = in; 00099 } 00100 00101 void setOutput(Vector<T> *out) 00102 { 00103 output = out; 00104 } 00105 00106 void setPartitions(int _parts) 00107 { 00108 parts = _parts; 00109 } 00110 00111 00112 void run_async(); 00113 00114 void finishAll() {m_environment->finishAll();} 00115 void setExecPlan(ExecPlan& plan) {m_execPlan = plan;} 00116 00117 private: 00118 Environment<int>* m_environment; 00119 MapArrayFunc* m_mapArrayFunc; 00120 ExecPlan m_execPlan; 00121 00122 #ifdef USE_STARPU_HISTORY_MODEL 00123 starpu_perfmodel_t *maparr_perf_model; 00124 #endif 00125 00126 00127 starpu_codelet *codelet; 00128 00129 public: 00130 void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& output); 00131 00132 void operator()(Vector<T>& input1, Vector<T>& input2, Vector<T>& output, int parts); 00133 00134 public: 00135 static void cpu_func(void *buffers[], void *arg); 00136 00137 #ifdef SKEPU_OPENMP 00138 public: 00139 static void omp_func(void *buffers[], void *arg); 00140 #endif 00141 00142 #ifdef SKEPU_CUDA 00143 public: 00144 static void cuda_func(void *buffers[], void *arg); 00145 #endif 00146 00147 #ifdef SKEPU_OPENCL 00148 public: 00149 static void opencl_func(void *buffers[], void *arg); 00150 00151 public: 00152 struct starpu_opencl_program opencl_codelet; 00153 char kernelNameArray[1024]; 00154 00155 void replaceText(std::string& text, std::string find, std::string replace); 00156 void createOpenCLProgram(); 00157 00158 #endif 00159 00160 private: 00161 std::string perfmodel_str; 00162 00163 Vector<T> *input1; 00164 Vector<T> *input2; 00165 Vector<T> *output; 00166 int parts; 00167 00168 }; 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00209 template <typename MapArrayFunc, typename T> 00210 class MapArray<MapArrayFunc, T, MATRIX>: public Task 00211 { 00212 00213 public: 00214 00215 MapArray(MapArrayFunc* mapArrayFunc); 00216 00217 MapArray(MapArrayFunc* mapArrayFunc, Vector<T> *in1, Matrix<T> *in2, Matrix<T> *out, int _parts=1); 00218 00219 ~MapArray(); 00220 00221 void finishAll() {m_environment->finishAll();} 00222 void setExecPlan(ExecPlan& plan) {m_execPlan = plan;} 00223 00224 private: 00225 Environment<int>* m_environment; 00226 MapArrayFunc* m_mapArrayFunc; 00227 ExecPlan m_execPlan; 00228 00229 #ifdef USE_STARPU_HISTORY_MODEL 00230 starpu_perfmodel_t *maparr_matr_perf_model; 00231 #endif 00232 00233 Matrix<T>& getOutput() 00234 { 00235 return *output; 00236 } 00237 00238 void *get_result() 00239 { 00240 return output; 00241 } 00242 00243 00244 void setInput1(Vector<T> *in) 00245 { 00246 input1 = in; 00247 } 00248 00249 void setInput2(Matrix<T> *in) 00250 { 00251 input2 = in; 00252 } 00253 00254 void setOutput(Matrix<T> *out) 00255 { 00256 output = out; 00257 } 00258 00259 void setPartitions(int _parts) 00260 { 00261 parts = _parts; 00262 } 00263 00264 void run_async(); 00265 00266 void setConstant1(T constant1) {m_mapArrayFunc->setConstant1(constant1);} 00267 00268 void setConstant2(T constant1) {m_mapArrayFunc->setConstant2(constant1);} 00269 00270 starpu_codelet *codelet; 00271 00272 public: 00273 void operator()(Vector<T>& input1, Matrix<T>& input2, Matrix<T>& output, int parts=1); 00274 00275 public: 00276 static void cpu_func(void *buffers[], void *arg); 00277 00278 #ifdef SKEPU_OPENMP 00279 public: 00280 static void omp_func(void *buffers[], void *arg); 00281 #endif 00282 00283 #ifdef SKEPU_CUDA 00284 public: 00285 static void cuda_func(void *buffers[], void *arg); 00286 #endif 00287 00288 #ifdef SKEPU_OPENCL 00289 public: 00290 static void opencl_func(void *buffers[], void *arg); 00291 00292 public: 00293 struct starpu_opencl_program opencl_codelet; 00294 char kernelNameArray[1024]; 00295 00296 void replaceText(std::string& text, std::string find, std::string replace); 00297 void createOpenCLProgram(); 00298 00299 #endif 00300 00301 private: 00302 std::string perfmodel_str; 00303 00304 Vector<T> *input1; 00305 Matrix<T> *input2; 00306 Matrix<T> *output; 00307 int parts; 00308 }; 00309 00310 00311 00312 } 00313 00314 #include "src/maparray.inl" 00315 00316 #include "src/maparray_cpu.inl" 00317 00318 #ifdef SKEPU_OPENMP 00319 #include "src/maparray_omp.inl" 00320 #endif 00321 00322 #ifdef SKEPU_OPENCL 00323 #include "src/maparray_cl.inl" 00324 #endif 00325 00326 #ifdef SKEPU_CUDA 00327 #include "src/maparray_cu.inl" 00328 #endif 00329 00330 #endif 00331
1.7.4