diff --git a/CMakeLists.txt b/CMakeLists.txt index f506823db3351c8d50f5a4c3c9c093338062af7d..8887123e3a463e643534714db804d71319b730c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,10 @@ endif() if (GPU_CL) add_definitions(-DPADDLE_MOBILE_CL) + + # opencl version + add_definitions(-DCL_TARGET_OPENCL_VERSION=220) + link_libraries(/Users/liuruilong/GitHub/paddle-mobile/third_party/opencl/libOpenCL.so) include_directories(third_party/opencl/OpenCL-Headers) else() @@ -82,7 +86,6 @@ else() file(GLOB_RECURSE _tmp_list_h src/framework/cl/*.h) foreach(f ${_tmp_list_h}) - message(STATUS ${f}) list(REMOVE_ITEM PADDLE_MOBILE_H ${f}) endforeach() endif() diff --git a/src/framework/operator.h b/src/framework/operator.h index d4ff39a4239ff28631c497467760e627a68042f3..8908f036617a04b27744767fd456a655bdbbe9a0 100644 --- a/src/framework/operator.h +++ b/src/framework/operator.h @@ -115,7 +115,11 @@ class OperatorWithKernel : public OperatorBase { const VariableNameMap &outputs, const AttributeMap &attrs, std::shared_ptr scope) : OperatorBase(type, inputs, outputs, attrs, scope), - param_(inputs, outputs, attrs, *scope) {} + param_(inputs, outputs, attrs, *scope) { +#ifdef PADDLE_MOBILE_CL + kernel_.InitCLHelper(scope->GetCLScpoe()); +#endif + } virtual void RunImpl() { this->kernel_.Compute(this->param_); } @@ -126,6 +130,8 @@ class OperatorWithKernel : public OperatorBase { // DLOG << i.first; // DLOG << i.second; // } + + PADDLE_MOBILE_ENFORCE(kernel_.Init(¶m_), " %s kernel init failed", this->type_.c_str()); } @@ -141,10 +147,16 @@ class OperatorWithKernel : public OperatorBase { template class OpKernelBase { public: + OpKernelBase() = default; -// OpKernelBase(CLScope *clscope): cl_helper_(CLHelper(clscope)) { -// } +#ifdef PADDLE_MOBILE_CL + + virtual void InitCLHelper(CLScope *clScope) { + cl_helper_ = CLHelper(clScope); + } + +#endif /* * @b 所有kernel 需实现 Compute 方法 @@ -163,7 +175,9 @@ class OpKernelBase { virtual ~OpKernelBase() = default; protected: -// CLHelper cl_helper_; +#ifdef PADDLE_MOBILE_CL + CLHelper cl_helper_; +#endif private: #ifdef PADDLE_MOBILE_MALI_GPU