From 111c0b6d9137842d97e9844f7fbaa2b977a0c818 Mon Sep 17 00:00:00 2001 From: Yanzhan Yang Date: Wed, 28 Aug 2019 18:23:55 +0800 Subject: [PATCH] fix elementwise_add && fix run.py && add namespace change script (#1898) --- .../kernel/cl/elementwise_add_kernel.cpp | 20 +++++++--- mobile/tools/python/fluidtools/run.py | 5 ++- mobile/tools/shell/change_mobile_namespace.sh | 39 +++++++++++++++++++ 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100755 mobile/tools/shell/change_mobile_namespace.sh diff --git a/mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp b/mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp index be051e1942..1506956280 100644 --- a/mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp +++ b/mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp @@ -25,17 +25,27 @@ bool ElementwiseAddKernel::Init( DLOG << "-----init add-----"; CLImage *bias = reinterpret_cast(const_cast(param->InputY())); - if (!bias->isInit()) { - bias->InitNormalCLImage(cl_helper_.CLContext(), - this->cl_helper_.CLCommandQueue()); - } - DLOG << " bias: " << *bias; if (bias->dims().size() == 4) { + if (!bias->isInit()) { + bias->InitNormalCLImage(cl_helper_.CLContext(), + this->cl_helper_.CLCommandQueue()); + } + DLOG << " bias: " << *bias; this->cl_helper_.AddKernel("elementwise_add", "elementwise_add_kernel.cl"); } else if (param->InputY()->dims().size() == 1) { if (param->Axis() == param->InputX()->dims().size() - 1) { + if (!bias->isInit()) { + bias->InitNormalCLImage(cl_helper_.CLContext(), + this->cl_helper_.CLCommandQueue()); + } + DLOG << " bias: " << *bias; this->cl_helper_.AddKernel("width_add", "channel_add_kernel.cl"); } else if (param->Axis() == param->InputX()->dims().size() - 3) { + if (!bias->isInit()) { + bias->InitCLImage(cl_helper_.CLContext(), + this->cl_helper_.CLCommandQueue()); + } + DLOG << " bias: " << *bias; this->cl_helper_.AddKernel("channel_add", "channel_add_kernel.cl"); } else { DLOG << "error:bias dims is error"; diff --git a/mobile/tools/python/fluidtools/run.py b/mobile/tools/python/fluidtools/run.py index 2bf704fb8d..06ffdd11b9 100644 --- a/mobile/tools/python/fluidtools/run.py +++ b/mobile/tools/python/fluidtools/run.py @@ -285,8 +285,9 @@ def save_all_op_output(feed_kv=None): for fetch in fetches: fetch_names.append(fetch.name) feed_names = feeds - for fetch_name in fetch_names: - output_var_filter.append(fetch_name) + if len(output_var_filter) > 0: + for fetch_name in fetch_names: + output_var_filter.append(fetch_name) for i in range(len(ops)): op = ops[i] var_name = None diff --git a/mobile/tools/shell/change_mobile_namespace.sh b/mobile/tools/shell/change_mobile_namespace.sh new file mode 100755 index 0000000000..5de8744844 --- /dev/null +++ b/mobile/tools/shell/change_mobile_namespace.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# set -o xtrace + +extension=$1 + +convert () { + perl -pi -e "s/namespace paddle_mobile/namespace paddle_mobile_${1}/g" "${2}" + perl -pi -e "s/paddle_mobile::/paddle_mobile_${1}::/g" "${2}" +} + +revert () { + perl -pi -e "s/namespace paddle_mobile_[\w]*/namespace paddle_mobile/g" "${2}" + perl -pi -e "s/paddle_mobile_[\w]*::/paddle_mobile::/g" "${2}" +} + +if [[ $2 == "revert" ]]; then + for file in $(find src -name "*\.*") + do + echo "reverting ${file}" + revert $extension $file + done + for file in $(find test -name "*\.*") + do + echo "reverting ${file}" + revert $extension $file + done +else + for file in $(find src -name "*\.*") + do + echo "converting ${file}" + convert $extension $file + done + # for file in $(find test -name "*\.*") + # do + # echo "converting ${file}" + # convert $extension $file + # done +fi -- GitLab