From fdc5173b77b2e0e28c21d04fe84b1e8f5394060c Mon Sep 17 00:00:00 2001 From: wangyanling Date: Thu, 1 Apr 2021 15:14:06 +0800 Subject: [PATCH] fix slice op bug --- .../ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc | 8 ++++++-- mindspore/nn/loss/loss.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc index 15e8174545..d1c1496287 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc @@ -191,8 +191,12 @@ void SliceCPUKernel::CopyDataToOutput(const std::vector &inp MS_LOG(EXCEPTION) << id << " output memory out of bounds."; } - auto ret = memcpy_s(output_addr + out_offset, out_buff_size - out_offset * sizeof(T), input_addr + in_offset, - copy_num * sizeof(T)); + size_t buff_size = out_buff_size - out_offset * sizeof(T); + size_t copy_size = copy_num * sizeof(T); + if (buff_size < copy_size) { + MS_LOG(EXCEPTION) << "output buffer is not enough. memcpy failed!"; + } + auto ret = memcpy_s(output_addr + out_offset, copy_size, input_addr + in_offset, copy_size); if (ret != EOK) { MS_LOG(EXCEPTION) << "memcpy failed. ret:" << ret; } diff --git a/mindspore/nn/loss/loss.py b/mindspore/nn/loss/loss.py index 5be62467e3..cb7c7d5396 100644 --- a/mindspore/nn/loss/loss.py +++ b/mindspore/nn/loss/loss.py @@ -814,7 +814,7 @@ class BCELoss(_Loss): ValueError: If shape of `inputs` is not the same as `labels` or `weight` (if given). Supported Platforms: - ``Ascend`` ``GPU`` + ``Ascend`` ``GPU`` ``CPU`` Examples: >>> weight = Tensor(np.array([[1.0, 2.0, 3.0], [4.0, 3.3, 2.2]]), mindspore.float32)