diff --git a/src/framework/cl/cl_engine.cpp b/src/framework/cl/cl_engine.cpp index 8a6611b7d80ed23b2da072e04371c3c6e52a873c..04d1675227aac0967f8dee94aa7a27ae5ea73c0f 100644 --- a/src/framework/cl/cl_engine.cpp +++ b/src/framework/cl/cl_engine.cpp @@ -23,12 +23,15 @@ namespace paddle_mobile { namespace framework { bool CLEngine::Init() { + if (initialized_) { + return true; + } cl_int status; SetPlatform(); SetClDeviceId(); - initialized_ = true; - // setClContext(); + initialized_ = true; + return initialized_; // setClCommandQueue(); // std::string filename = "./HelloWorld_Kernel.cl"; // loadKernelFromFile(filename.c_str()); @@ -37,6 +40,7 @@ bool CLEngine::Init() { CLEngine *CLEngine::Instance() { static CLEngine cl_engine_; + cl_engine_.Init(); return &cl_engine_; } diff --git a/src/framework/cl/cl_engine.h b/src/framework/cl/cl_engine.h index 930e511957dc1cd1a2ca588e39d89c19d372bf19..509be5f92f3ee64953aeba54e178ba2a6cfe9678 100644 --- a/src/framework/cl/cl_engine.h +++ b/src/framework/cl/cl_engine.h @@ -33,18 +33,21 @@ class CLEngine { bool Init(); std::unique_ptr<_cl_context, CLContextDeleter> CreateContext() { - cl_context c = clCreateContext(NULL, 1, devices_, NULL, NULL, NULL); + cl_int status; + cl_context c = clCreateContext(NULL, 1, devices_, NULL, NULL, &status); std::unique_ptr<_cl_context, CLContextDeleter> context_ptr(c); + CL_CHECK_ERRORS(status); return std::move(context_ptr); } std::unique_ptr<_cl_command_queue, CLCommQueueDeleter> - CreateClCommandQueue() { + CreateClCommandQueue(cl_context context) { cl_int status; cl_command_queue queue = - clCreateCommandQueue(context_.get(), devices_[0], 0, &status); + clCreateCommandQueue(context, devices_[0], 0, &status); std::unique_ptr<_cl_command_queue, CLCommQueueDeleter> command_queue_ptr( queue); + CL_CHECK_ERRORS(status); return std::move(command_queue_ptr); } @@ -100,10 +103,6 @@ class CLEngine { cl_int status_; - std::unique_ptr<_cl_context, CLContextDeleter> context_; - - std::unique_ptr<_cl_command_queue, CLCommQueueDeleter> command_queue_; - std::unique_ptr<_cl_program, CLProgramDeleter> program_; // bool SetClContext(); diff --git a/src/framework/cl/cl_scope.h b/src/framework/cl/cl_scope.h index 2b2ad8367fdfeeb0ca6943ed18ea21e570596413..93a74a36452f42a019954d200af093b699d17344 100644 --- a/src/framework/cl/cl_scope.h +++ b/src/framework/cl/cl_scope.h @@ -30,9 +30,8 @@ class CLScope { public: CLScope() { CLEngine *engin = CLEngine::Instance(); - engin->Init(); context_ = engin->CreateContext(); - command_queue_ = engin->CreateClCommandQueue(); + command_queue_ = engin->CreateClCommandQueue(context_.get()); } cl_command_queue CommandQueue() { return command_queue_.get(); } diff --git a/src/operators/kernel/cl/cl_kernel/conv_kernel.cl b/src/operators/kernel/cl/cl_kernel/conv_kernel.cl index fa718a7326d8fcdd5fff614f8c67632c9badec3e..113f1be9a1a8cf52c1bd57c73208295efffd1b84 100644 --- a/src/operators/kernel/cl/cl_kernel/conv_kernel.cl +++ b/src/operators/kernel/cl/cl_kernel/conv_kernel.cl @@ -12,6 +12,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -//#include "conv_kernel.inc.cl" -__kernel void conv_3x3() {} \ No newline at end of file +__kernel void conv_3x3() { + + +} + + diff --git a/src/operators/kernel/cl/conv_kernel.cpp b/src/operators/kernel/cl/conv_kernel.cpp index 232579098a23e49a62662b461430829a32d0117c..bb26843795eda54669f473e36a9e66721790630b 100644 --- a/src/operators/kernel/cl/conv_kernel.cpp +++ b/src/operators/kernel/cl/conv_kernel.cpp @@ -93,32 +93,52 @@ void ConvKernel::Compute(const ConvParam ¶m) { DLOG << " begin set kernel arg "; - status = clSetKernelArg(kernel, 0, sizeof(int), &c_block); - status = clSetKernelArg(kernel, 1, sizeof(int), &w); - status = clSetKernelArg(kernel, 2, sizeof(int), &nh); - status = clSetKernelArg(kernel, 3, sizeof(cl_mem), &input); - status = clSetKernelArg(kernel, 4, sizeof(cl_mem), &filter); - status = clSetKernelArg(kernel, 5, sizeof(cl_mem), &output); - status = clSetKernelArg(kernel, 6, sizeof(int), &stride); - status = clSetKernelArg(kernel, 7, sizeof(int), &offset); - status = clSetKernelArg(kernel, 8, sizeof(int), &input_c); - status = clSetKernelArg(kernel, 9, sizeof(int), &dilation); - status = clSetKernelArg(kernel, 10, sizeof(int), &input_width); - status = clSetKernelArg(kernel, 11, sizeof(int), &input_height); +// status = clSetKernelArg(kernel, 0, sizeof(int), &c_block); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 1, sizeof(int), &w); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 2, sizeof(int), &nh); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 3, sizeof(cl_mem), &input); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 4, sizeof(cl_mem), &filter); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 5, sizeof(cl_mem), &output); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 6, sizeof(int), &stride); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 7, sizeof(int), &offset); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 8, sizeof(int), &input_c); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 9, sizeof(int), &dilation); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 10, sizeof(int), &input_width); +// CL_CHECK_ERRORS(status); +// +// status = clSetKernelArg(kernel, 11, sizeof(int), &input_height); +// CL_CHECK_ERRORS(status); DLOG << " end set kernel arg "; - CL_CHECK_ERRORS(status); - DLOG << " begin enqueue "; status = clEnqueueNDRangeKernel(this->cl_helper_.CLCommandQueue(), kernel, 3, NULL, default_work_size.data(), NULL, 0, NULL, NULL); - + CL_CHECK_ERRORS(status); DLOG << " end enqueue "; - CL_CHECK_ERRORS(status); } template class ConvKernel;