From 1d74eb9d99b8fdc5126dc912bbfb51c534930cc2 Mon Sep 17 00:00:00 2001 From: liuruilong Date: Mon, 15 Oct 2018 15:06:24 +0800 Subject: [PATCH] init image when init kernel --- src/framework/cl/cl_image.h | 1 + .../kernel/cl/conv_add_bn_relu_kernel.cpp | 15 +++++++++++---- src/operators/kernel/cl/conv_add_kernel.cpp | 3 +++ src/operators/kernel/cl/conv_kernel.cpp | 5 ++--- src/operators/kernel/cl/depthwise_conv_kernel.cpp | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/framework/cl/cl_image.h b/src/framework/cl/cl_image.h index 1c5da6146d..b8645a4298 100644 --- a/src/framework/cl/cl_image.h +++ b/src/framework/cl/cl_image.h @@ -61,6 +61,7 @@ class CLImage { PADDLE_MOBILE_THROW_EXCEPTION( " empty image tensor data shouldn't have value"); } + DLOG << " init empty image "; InitCLImage(context, nullptr, dim); initialized_ = true; } diff --git a/src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp b/src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp index 29b13b6abc..6b16039f15 100644 --- a/src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp +++ b/src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp @@ -24,9 +24,16 @@ namespace operators { template <> bool ConvAddBNReluKernel::Init( FusionConvAddBNReluParam *param) { + PADDLE_MOBILE_ENFORCE( + param->Filter()->dims()[2] == param->Filter()->dims()[3] && + param->Paddings()[0] == param->Paddings()[1], + "need equal"); + + param->Filter()->InitCLImage(cl_helper_.CLContext()); + param->Bias()->InitCLImage(cl_helper_.CLContext()); + // const CL *mean = param->InputMean(); const framework::CLImage *mean = param->InputMean(); - const framework::CLImage *variance = param->InputVariance(); const framework::CLImage *scale = param->InputScale(); const framework::CLImage *bias = param->InputBias(); @@ -52,9 +59,6 @@ bool ConvAddBNReluKernel::Init( new_bias_ptr[i] = bias_ptr[i] - mean_ptr[i] * inv_std_ptr[i] * scale_ptr[i]; } - delete[](new_scale_ptr); - delete[](new_bias_ptr); - framework::CLImage *new_scale = new framework::CLImage(); new_scale->SetTensorData(new_scale_ptr, variance->dims()); @@ -68,6 +72,9 @@ bool ConvAddBNReluKernel::Init( param->SetNewScale(new_scale); param->SetNewBias(new_bias); + delete[](new_scale_ptr); + delete[](new_bias_ptr); + PADDLE_MOBILE_ENFORCE( param->Filter()->dims()[2] == param->Filter()->dims()[3] && param->Paddings()[0] == param->Paddings()[1], diff --git a/src/operators/kernel/cl/conv_add_kernel.cpp b/src/operators/kernel/cl/conv_add_kernel.cpp index b5fd82c47a..ac36e70ed7 100644 --- a/src/operators/kernel/cl/conv_add_kernel.cpp +++ b/src/operators/kernel/cl/conv_add_kernel.cpp @@ -25,6 +25,9 @@ bool ConvAddKernel::Init(FusionConvAddParam *param) { param->Filter()->dims()[2] == param->Filter()->dims()[3] && param->Paddings()[0] == param->Paddings()[1], "need equal"); + param->Filter()->InitCLImage(cl_helper_.CLContext()); + param->Bias()->InitCLImage(cl_helper_.CLContext()); + int offset = static_cast(param->Filter()->dims()[2]) / 2 - static_cast(param->Paddings()[1]); param->SetOffset(offset); diff --git a/src/operators/kernel/cl/conv_kernel.cpp b/src/operators/kernel/cl/conv_kernel.cpp index 8386144685..63c1776f83 100644 --- a/src/operators/kernel/cl/conv_kernel.cpp +++ b/src/operators/kernel/cl/conv_kernel.cpp @@ -26,19 +26,18 @@ bool ConvKernel::Init(ConvParam *param) { param->Paddings()[0] == param->Paddings()[1], "need equal"); + param->Filter()->InitCLImage(cl_helper_.CLContext()); + int offset = static_cast(param->Filter()->dims()[2]) / 2 - static_cast(param->Paddings()[1]); param->SetOffset(offset); DLOG << " init helper: " << &cl_helper_; DLOG << " conv kernel add kernel ~ "; - DLOG << " width of one block: " << param->Filter()->WidthOfOneBlock(); DLOG << " height of one block: " << param->Filter()->HeightOfOneBlock(); - DLOG << " filter dims: " << param->Filter()->dims(); - if (param->Filter()->WidthOfOneBlock() == 1 && param->Filter()->HeightOfOneBlock() == 1) { diff --git a/src/operators/kernel/cl/depthwise_conv_kernel.cpp b/src/operators/kernel/cl/depthwise_conv_kernel.cpp index 99b5a714d6..dcb95b4c6a 100644 --- a/src/operators/kernel/cl/depthwise_conv_kernel.cpp +++ b/src/operators/kernel/cl/depthwise_conv_kernel.cpp @@ -27,6 +27,7 @@ bool DepthwiseConvKernel::Init(ConvParam *param) { param->Filter()->dims()[2] == param->Filter()->dims()[3] && param->Paddings()[0] == param->Paddings()[1], "need equal"); + param->Filter()->InitCLImage(cl_helper_.CLContext()); int offset = static_cast(param->Filter()->dims()[2]) / 2 - static_cast(param->Paddings()[1]); param->SetOffset(offset); -- GitLab