From 38bb34d390bd435c3ff7e4779340dd4480ae3b84 Mon Sep 17 00:00:00 2001 From: zhaoting Date: Fri, 20 Nov 2020 17:26:31 +0800 Subject: [PATCH] fix codex and review bot warning --- .../ccsrc/backend/kernel_compiler/cpu/adam_cpu_kernel.cc | 6 +++++- .../backend/kernel_compiler/cpu/arithmetic_cpu_kernel.cc | 4 ++++ .../kernel_compiler/cpu/arithmetic_self_cpu_kernel.cc | 4 ++++ .../ccsrc/backend/kernel_compiler/cpu/cast_cpu_kernel.cc | 4 ++++ .../backend/kernel_compiler/cpu/eltwise_grad_cpu_kernel.cc | 4 ++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/adam_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/adam_cpu_kernel.cc index 33767f560e..b51df848ac 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/adam_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/adam_cpu_kernel.cc @@ -86,11 +86,15 @@ bool AdamCPUKernel::Launch(const std::vector &inputs, size_t lens = inputs[0]->size > 0 ? static_cast(inputs[0]->size / sizeof(float)) : 1; auto max_thread_num = std::thread::hardware_concurrency(); size_t thread_num = lens < 128 * max_thread_num ? std::ceil(lens / 128.0) : max_thread_num; - MS_LOG(INFO) << "lens=" << lens << "; use thread_num=" << thread_num << "; max_thread_num: " << max_thread_num; + MS_LOG(INFO) << "Lens=" << lens << "; use thread_num=" << thread_num << "; max_thread_num: " << max_thread_num; std::vector threads; threads.reserve(thread_num); size_t start = 0; size_t once_compute_size = (lens + thread_num - 1) / thread_num; + if (thread_num < 1 || once_compute_size < 1) { + MS_LOG(ERROR) << "Invalid value: thread_num " << thread_num << "; once_compute_size " << once_compute_size; + return false; + } while (start < lens) { size_t end = (start + once_compute_size) > lens ? lens : (start + once_compute_size); threads.emplace_back(std::thread(&AdamCPUKernel::LaunchAdam, this, var, m, v, new_lr, beta1, beta2, epsilon, diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_cpu_kernel.cc index 2e7e0ec5f1..14e60674a3 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_cpu_kernel.cc @@ -217,6 +217,10 @@ void ArithmeticCPUKernel::LaunchKernel(const std::vector &inputs, co threads.reserve(thread_num); size_t start = 0; size_t once_compute_size = (lens + thread_num - 1) / thread_num; + if (thread_num < 1 || once_compute_size < 1) { + MS_LOG(ERROR) << "Invalid value: thread_num " << thread_num << "; once_compute_size " << once_compute_size; + return; + } while (start < lens) { size_t end = (start + once_compute_size) > lens ? lens : (start + once_compute_size); if (operate_type_ == ADD) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_self_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_self_cpu_kernel.cc index c5d71bc711..c501a9bc3d 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_self_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/arithmetic_self_cpu_kernel.cc @@ -75,6 +75,10 @@ void ArithmeticSelfCPUKernel::LaunchKernel(const std::vector &inputs threads.reserve(thread_num); size_t start = 0; size_t once_compute_size = (lens + thread_num - 1) / thread_num; + if (thread_num < 1 || once_compute_size < 1) { + MS_LOG(ERROR) << "Invalid value: thread_num " << thread_num << "; once_compute_size " << once_compute_size; + return; + } while (start < lens) { size_t end = (start + once_compute_size) > lens ? lens : (start + once_compute_size); if (operate_type_ == SQUARE) { diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/cast_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/cast_cpu_kernel.cc index 754e38ca0f..8de86f2d0b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/cast_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/cast_cpu_kernel.cc @@ -43,6 +43,10 @@ void LaunchCast(const std::vector &inputs, const std::vector threads.reserve(thread_num); size_t start = 0; size_t once_compute_size = (lens + thread_num - 1) / thread_num; + if (thread_num < 1 || once_compute_size < 1) { + MS_LOG(ERROR) << "Invalid value: thread_num " << thread_num << "; once_compute_size " << once_compute_size; + return; + } while (start < lens) { size_t end = (start + once_compute_size) > lens ? lens : (start + once_compute_size); threads.emplace_back(std::thread(Cast, input, output, start, end)); diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/eltwise_grad_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/eltwise_grad_cpu_kernel.cc index 799260c3a4..bdeb9cca0c 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/eltwise_grad_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/eltwise_grad_cpu_kernel.cc @@ -149,6 +149,10 @@ void EltWiseGradCPUKernel::LaunchKernel(const std::vector &inputs, c threads.reserve(thread_num); size_t start = 0; size_t once_compute_size = (lens + thread_num - 1) / thread_num; + if (thread_num < 1 || once_compute_size < 1) { + MS_LOG(ERROR) << "Invalid value: thread_num " << thread_num << "; once_compute_size " << once_compute_size; + return; + } while (start < lens) { size_t end = (start + once_compute_size) > lens ? lens : (start + once_compute_size); if (operate_type_ == RELUGRAD) {