From 3ec333e851a73ad0530e88f29689136b564b80b5 Mon Sep 17 00:00:00 2001 From: chenzupeng Date: Thu, 20 Aug 2020 16:49:15 +0800 Subject: [PATCH] fix bug in softmax --- build.sh | 25 ++++++++----------- .../runtime/kernel/opencl/kernel/softmax.cc | 2 +- .../src/runtime/opencl/opencl_allocator.cc | 3 ++- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/build.sh b/build.sh index 911135906a..9e03268835 100755 --- a/build.sh +++ b/build.sh @@ -482,22 +482,17 @@ gene_ocl_program() { SPIRV_DIR=build/spirv rm -rf ${SPIRV_DIR} mkdir -pv ${SPIRV_DIR} - for sub_dir in "${CL_SRC_DIR}"/* + if [ ! -d ${CL_SRC_DIR} ]; then + return + fi + for file_path in "${CL_SRC_DIR}"/* do - data_type="$(basename ${sub_dir})" - if [ ! -d ${CL_SRC_DIR}/${data_type} ]; then - continue - fi - #echo $(cd "$(dirname $0)"; pwd) - for file_path in "${CL_SRC_DIR}/${data_type}"/* - do - file="$(basename ${file_path})" - if [ "${file##*.}" != "cl" ]; then - continue - fi - clang -Xclang -finclude-default-header -cl-std=CL2.0 --target=spir64-unknown-unknown -emit-llvm \ - -c -O0 -o ${SPIRV_DIR}/${file%.*}.bc ${CL_SRC_DIR}/${data_type}/${file} - done + file="$(basename ${file_path})" + if [ "${file##*.}" != "cl" ]; then + continue + fi + clang -Xclang -finclude-default-header -cl-std=CL2.0 --target=spir64-unknown-unknown -emit-llvm \ + -c -O0 -o ${SPIRV_DIR}/${file%.*}.bc ${CL_SRC_DIR}/${file} done bcs=`ls ${SPIRV_DIR}/*.bc` diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc index 9d55ba5d53..a3e82228ac 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc @@ -33,7 +33,7 @@ using mindspore::schema::PrimitiveType_SoftMax; namespace mindspore::kernel { std::vector SoftmaxOpenCLKernel::GetMaskForLastChannel(int channels) { - std::vector mask{4, 0.0f}; + std::vector mask{0.0f, 0.0f, 0.0f, 0.0f}; const int reminder = channels % 4 == 0 ? 4 : channels % 4; for (int i = 0; i < reminder; ++i) { mask[i] = 1.0f; diff --git a/mindspore/lite/src/runtime/opencl/opencl_allocator.cc b/mindspore/lite/src/runtime/opencl/opencl_allocator.cc index ac423a3c6d..445b7f7163 100644 --- a/mindspore/lite/src/runtime/opencl/opencl_allocator.cc +++ b/mindspore/lite/src/runtime/opencl/opencl_allocator.cc @@ -109,8 +109,9 @@ void *OpenCLAllocator::Malloc(size_t size, const std::vector &img_size) cl::Image2D *image = new (std::nothrow) cl::Image2D(*ocl_runtime->Context(), image_format, *buffer, img_size[0], img_size[1], img_pitch * sizeof(cl_float4), &ret); if (image == nullptr || ret != CL_SUCCESS) { - MS_LOG(ERROR) << "Create OpenCL Image2D failed! (ERROR CODE: " << ret << ")"; + delete buffer; UnLock(); + MS_LOG(ERROR) << "Create OpenCL Image2D failed! (ERROR CODE: " << ret << ")"; return nullptr; } MS_LOG(DEBUG) << "Malloc a new Image2D, width=" << img_size[0] << ", height=" << img_size[1];