From 88513a223a8f76d692029babebe302dc308b5892 Mon Sep 17 00:00:00 2001 From: zhouyuanshen Date: Fri, 27 Nov 2020 11:32:51 +0800 Subject: [PATCH] fix-bot-warning --- .../gpu/arrays/pack_gpu_kernel.h | 5 +++-- .../gpu/arrays/unpack_gpu_kernel.h | 5 +++-- .../gpu/random/random_categorical_gpu_kernel.h | 18 +++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/pack_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/pack_gpu_kernel.h index 22de07f233..b0ad39b355 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/pack_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/pack_gpu_kernel.h @@ -41,8 +41,9 @@ class PackGpuFwdKernel : public GpuKernel { for (size_t i = 0; i < inputs.size(); i++) { inputs_host_[i] = GetDeviceAddress(inputs, i); } - CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(inputs_array, inputs_host_.get(), sizeof(T *) * input_num_, - cudaMemcpyHostToDevice, reinterpret_cast(stream_ptr)), + CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(inputs_array, // NOLINT + inputs_host_.get(), sizeof(T *) * input_num_, cudaMemcpyHostToDevice, + reinterpret_cast(stream_ptr)), "Pack opt cudaMemcpyAsync inputs failed"); PackKernel(SizeToInt(output_size_), input_num_, dims_behind_axis_, inputs_array, output, reinterpret_cast(stream_ptr)); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/unpack_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/unpack_gpu_kernel.h index 2da9629b7a..980cb619e6 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/unpack_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/unpack_gpu_kernel.h @@ -41,8 +41,9 @@ class UnpackGpuFwdKernel : public GpuKernel { for (size_t i = 0; i < outputs.size(); i++) { outputs_host_[i] = GetDeviceAddress(outputs, i); } - CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(outputs_array, outputs_host_.get(), sizeof(T *) * output_num_, - cudaMemcpyHostToDevice, reinterpret_cast(stream_ptr)), + CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(outputs_array, // NOLINT + outputs_host_.get(), sizeof(T *) * output_num_, cudaMemcpyHostToDevice, + reinterpret_cast(stream_ptr)), "Unpack opt cudaMemcpyAsync outputs failed"); UnpackKernel(SizeToInt(input_size_), output_num_, dims_after_axis_, outputs_array, input, reinterpret_cast(stream_ptr)); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/random/random_categorical_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/random/random_categorical_gpu_kernel.h index 18a7ce16f7..f4b5164b09 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/random/random_categorical_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/random/random_categorical_gpu_kernel.h @@ -47,8 +47,9 @@ class RandomCategoricalGpuKernel : public GpuKernel { host_cdf[i] = GetDeviceAddress(workspaces, i); } double **dev_cdf = GetDeviceAddress(workspaces, batch_size_); - CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(dev_cdf, host_cdf.get(), sizeof(double *) * batch_size_, - cudaMemcpyHostToDevice, reinterpret_cast(stream_ptr)), + CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(dev_cdf, // NOLINT + host_cdf.get(), sizeof(double *) * batch_size_, cudaMemcpyHostToDevice, + reinterpret_cast(stream_ptr)), "Random_categorica cudaMemcpyAsync dev_cdf failed"); std::unique_ptr host_rand; @@ -59,19 +60,22 @@ class RandomCategoricalGpuKernel : public GpuKernel { double **dev_rand = GetDeviceAddress(workspaces, batch_size_ * 2 + 1); for (int i = 0; i < batch_size_; i++) { - double *host_1d_rand = new double[num_samples_]; + std::unique_ptr host_1d_rand; + host_1d_rand = std::make_unique(num_samples_); + std::default_random_engine rng(seed_); std::uniform_real_distribution<> dist(0, 1); for (int j = 0; j < num_samples_; j++) { host_1d_rand[j] = dist(rng); } - CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(host_rand[i], host_1d_rand, sizeof(double) * num_samples_, + CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(host_rand[i], // NOLINT + host_1d_rand.get(), sizeof(double) * num_samples_, cudaMemcpyHostToDevice, reinterpret_cast(stream_ptr)), "Random_categorica cudaMemcpyAsync host_1d_rand failed"); - delete[] host_1d_rand; } - CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(dev_rand, host_rand.get(), sizeof(double *) * batch_size_, - cudaMemcpyHostToDevice, reinterpret_cast(stream_ptr)), + CHECK_CUDA_RET_WITH_EXCEPT(cudaMemcpyAsync(dev_rand, // NOLINT + host_rand.get(), sizeof(double *) * batch_size_, cudaMemcpyHostToDevice, + reinterpret_cast(stream_ptr)), "Random_categorica cudaMemcpyAsync dev_rand failed"); GetCdfKernel(logits_addr, dev_cdf, batch_size_, num_classes_, reinterpret_cast(stream_ptr));