From 26c68a0e5f555e316cab18352fa3b62f22af8bfb Mon Sep 17 00:00:00 2001 From: SiCong Li Date: Tue, 14 Nov 2023 15:17:10 +0000 Subject: Fix various coverity issues Resolves COMPMID-6677 Signed-off-by: SiCong Li Change-Id: I99bf2385f6edc0836faacb31f5c66ed4fb051e40 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10729 Benchmark: Arm Jenkins Reviewed-by: Viet-Hoa Do Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- src/core/CL/CLMutableCommandBuffer.cpp | 7 ++++++- src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp | 6 ++++-- src/gpu/cl/operators/ClMatMul.cpp | 2 -- src/runtime/CL/CLMemoryRegion.cpp | 11 ++++++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/core/CL/CLMutableCommandBuffer.cpp b/src/core/CL/CLMutableCommandBuffer.cpp index 05b351fc25..0e078d8416 100644 --- a/src/core/CL/CLMutableCommandBuffer.cpp +++ b/src/core/CL/CLMutableCommandBuffer.cpp @@ -26,6 +26,7 @@ #include "arm_compute/core/Error.h" +#include "src/common/utils/Log.h" #include "src/core/CL/CLUtils.h" namespace arm_compute @@ -48,7 +49,11 @@ CLMutableCommandBuffer::CLMutableCommandBuffer(cl_command_queue queue) : CLComma CLMutableCommandBuffer::~CLMutableCommandBuffer() { const auto status = clReleaseCommandBufferKHR(_cb); - handle_cl_error("clReleaseCommandBufferKHR", status); + if (status != CL_SUCCESS) + { + const std::string error_message = "clReleaseCommandBufferKHR - Error code: " + std::to_string(status); + ARM_COMPUTE_LOG_ERROR_ACL(error_message); + } } void CLMutableCommandBuffer::add_kernel(cl_kernel kernel, diff --git a/src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp b/src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp index 82bd465c99..611bc76463 100644 --- a/src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp +++ b/src/cpu/operators/internal/CpuGemmAssemblyDispatch.cpp @@ -541,6 +541,7 @@ void Fallback::prepare(ITensorPack &tensors) { auto b = tensors.get_const_tensor(TensorType::ACL_SRC_1); auto c = tensors.get_const_tensor(TensorType::ACL_SRC_2); + ARM_COMPUTE_ERROR_ON_NULLPTR(b); // Setup up matrix bias in the assembly kernel, it's just a pointer to matrix C. if (c && c->info()->data_type() == DataType::S32) @@ -614,6 +615,7 @@ void Fallback::run(ITensorPack &tensors) auto b = tensors.get_const_tensor(TensorType::ACL_SRC_1); auto c = tensors.get_const_tensor(TensorType::ACL_SRC_2); auto d = tensors.get_tensor(TensorType::ACL_DST); + ARM_COMPUTE_ERROR_ON_NULLPTR(a, d); int lda = a->info()->strides_in_bytes().y() / a->info()->element_size(); int ldb = 0; @@ -652,7 +654,7 @@ void Fallback::run(ITensorPack &tensors) } // Check if B is pre-tranposed and de-reference if not - if (!_gemm_kernel_asm->B_is_pretransposed()) + if (b_to_use && !_gemm_kernel_asm->B_is_pretransposed()) { ldb = b_to_use->info()->strides_in_bytes().y() / b_to_use->info()->element_size(); multi_stride_b = b_to_use->info()->strides_in_bytes().z() / b_to_use->info()->element_size(); @@ -670,7 +672,7 @@ void Fallback::run(ITensorPack &tensors) } // Pretranspose B if required - if (_B_pretranspose_required) + if (b_to_use && _B_pretranspose_required) { // Fixed format kernels need no pretranspose. ARM_COMPUTE_ERROR_ON(arm_compute::is_fixed_format( diff --git a/src/gpu/cl/operators/ClMatMul.cpp b/src/gpu/cl/operators/ClMatMul.cpp index 9962ee550a..43303001d0 100644 --- a/src/gpu/cl/operators/ClMatMul.cpp +++ b/src/gpu/cl/operators/ClMatMul.cpp @@ -91,8 +91,6 @@ MatMulKernelType get_matmul_kernel(const ITensorInfo *lhs, return MatMulKernelType::NATIVE_FP; } - - return is_quantized ? MatMulKernelType::NATIVE_QUANTIZED : MatMulKernelType::NATIVE_FP; } } // namespace using namespace arm_compute::opencl::kernels; diff --git a/src/runtime/CL/CLMemoryRegion.cpp b/src/runtime/CL/CLMemoryRegion.cpp index 835958b816..c9ddf9b85c 100644 --- a/src/runtime/CL/CLMemoryRegion.cpp +++ b/src/runtime/CL/CLMemoryRegion.cpp @@ -26,6 +26,8 @@ #include "arm_compute/core/Error.h" #include "arm_compute/runtime/CL/CLScheduler.h" +#include "src/common/utils/Log.h" + namespace arm_compute { ICLMemoryRegion::ICLMemoryRegion(size_t size) @@ -72,7 +74,14 @@ CLBufferMemoryRegion::~CLBufferMemoryRegion() // Flush the command queue to ensure all commands that may use this memory buffer are scheduled to be finished before // this buffer is freed // Do not call finish as it is a blocking call which affects the performance - CLScheduler::get().queue().flush(); + try + { + CLScheduler::get().queue().flush(); + } + catch (const std::exception &e) + { + ARM_COMPUTE_LOG_ERROR_ACL(e.what()); + } } void *CLBufferMemoryRegion::ptr() -- cgit v1.2.1