Browse Source

code check of cpu ops

tags/v1.5.0-rc1
fan-jibin fanjibin 4 years ago
parent
commit
8dcc5d9c20
77 changed files with 442 additions and 176 deletions
  1. +3
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/fl/fused_pull_weight_kernel.h
  2. +3
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/fl/fused_push_weight_kernel.h
  3. +1
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/apply_momentum_ps_kernel.cc
  4. +1
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/apply_momentum_ps_kernel.h
  5. +7
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/embedding_look_up_proxy_kernel.cc
  6. +16
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/embedding_look_up_ps_kernel.cc
  7. +0
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/pserver_kernel.cc
  8. +19
    -4
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_adam_ps_kernel.cc
  9. +2
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_adam_ps_kernel.h
  10. +25
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_ftrl_ps_kernel.cc
  11. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_ftrl_ps_kernel.h
  12. +18
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_lazy_adam_ps_kernel.cc
  13. +6
    -3
      mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_scatter_cpu_kernel.cc
  14. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/reshape_cpu_kernel.cc
  15. +3
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/reshape_cpu_kernel.h
  16. +15
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/resize_bilinear_cpu_kernel.cc
  17. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/resize_bilinear_cpu_kernel.h
  18. +17
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/resize_bilinear_grad_cpu_kernel.cc
  19. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/resize_bilinear_grad_cpu_kernel.h
  20. +17
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/resize_nearest_neighbor_cpu_kernel.cc
  21. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/resize_nearest_neighbor_cpu_kernel.h
  22. +17
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/resize_nearest_neighbor_grad_cpu_kernel.cc
  23. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/resize_nearest_neighbor_grad_cpu_kernel.h
  24. +3
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/rmsprop_cpu_kernel.cc
  25. +7
    -7
      mindspore/ccsrc/backend/kernel_compiler/cpu/rmsprop_cpu_kernel.h
  26. +10
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_arithmetic_cpu_kernel.cc
  27. +5
    -5
      mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_arithmetic_cpu_kernel.h
  28. +12
    -12
      mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_cpu_kernel.cc
  29. +3
    -5
      mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_cpu_kernel.h
  30. +6
    -6
      mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.cc
  31. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.h
  32. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/select_cpu_kernel.cc
  33. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/select_cpu_kernel.h
  34. +3
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/sigmoid_cross_entropy_with_logits_cpu_kernel.cc
  35. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/sigmoid_cross_entropy_with_logits_grad_cpu_kernel.cc
  36. +1
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc
  37. +7
    -7
      mindspore/ccsrc/backend/kernel_compiler/cpu/slice_grad_cpu_kernel.cc
  38. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/smooth_l1_loss_cpu_kernel.cc
  39. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/smooth_l1_loss_cpu_kernel.h
  40. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/smooth_l1_loss_grad_cpu_kernel.cc
  41. +4
    -3
      mindspore/ccsrc/backend/kernel_compiler/cpu/smooth_l1_loss_grad_cpu_kernel.h
  42. +1
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/sort_cpu_kernel.cc
  43. +10
    -4
      mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_apply_adam_cpu_kernel.cc
  44. +11
    -4
      mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_apply_ftrl_cpu_kernel.cc
  45. +11
    -4
      mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_apply_lazy_adam_cpu_kernel.cc
  46. +10
    -4
      mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_apply_proximal_adagrad_cpu_kernel.cc
  47. +6
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_optimizer_cpu_kernel.h
  48. +14
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_tensor_dense_matmul_cpu_kernel.cc
  49. +8
    -3
      mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_to_dense_cpu_kernal.cc
  50. +4
    -3
      mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_to_dense_cpu_kernal.h
  51. +15
    -6
      mindspore/ccsrc/backend/kernel_compiler/cpu/split_cpu_kernel.cc
  52. +8
    -6
      mindspore/ccsrc/backend/kernel_compiler/cpu/split_cpu_kernel.h
  53. +1
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/strided_slice_grad_cpu_kernel.cc
  54. +1
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/stridedslice_cpu_kernel.cc
  55. +0
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/stridedslice_cpu_kernel.h
  56. +2
    -3
      mindspore/ccsrc/backend/kernel_compiler/cpu/sub_and_filter_cpu_kernel.cc
  57. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/sub_and_filter_cpu_kernel.h
  58. +1
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/tensor_copy_slices_cpu_kernel.cc
  59. +2
    -3
      mindspore/ccsrc/backend/kernel_compiler/cpu/tensor_copy_slices_cpu_kernel.h
  60. +1
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/tensoradd_cpu_kernel.cc
  61. +1
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/tensoradd_cpu_kernel.h
  62. +14
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/tile_cpu_kernel.cc
  63. +1
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/tile_cpu_kernel.h
  64. +6
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/topk_cpu_kernel.cc
  65. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/topk_cpu_kernel.h
  66. +1
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/transpose_cpu_kernel.cc
  67. +2
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/transpose_cpu_kernel.h
  68. +6
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/unique_cpu_kernel.cc
  69. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/unique_cpu_kernel.h
  70. +2
    -2
      mindspore/ccsrc/backend/kernel_compiler/cpu/unique_with_pad_cpu_kernel.cc
  71. +1
    -0
      mindspore/ccsrc/backend/kernel_compiler/cpu/unique_with_pad_cpu_kernel.h
  72. +2
    -4
      mindspore/ccsrc/backend/kernel_compiler/cpu/unpack_cpu_kernel.cc
  73. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/unpack_cpu_kernel.h
  74. +22
    -20
      mindspore/ccsrc/backend/kernel_compiler/cpu/unsorted_segment_sum_cpu_kernel.cc
  75. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/unsorted_segment_sum_cpu_kernel.h
  76. +9
    -12
      mindspore/ccsrc/backend/kernel_compiler/cpu/update_cache_cpu_kernel.cc
  77. +2
    -1
      mindspore/ccsrc/backend/kernel_compiler/cpu/update_cache_cpu_kernel.h

+ 3
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/fl/fused_pull_weight_kernel.h View File

@@ -52,6 +52,9 @@ class FusedPullWeightKernel : public CPUKernel {

total_iteration_++;
uint64_t step_num_per_iteration = fl::worker::FLWorker::GetInstance().worker_step_num_per_iteration();
if (step_num_per_iteration == 0) {
MS_LOG(EXCEPTION) << "Step numbers of per iteration should not equal to 0";
}
// The worker has to train kWorkerTrainStepNum standalone iterations before it communicates with server.
MS_LOG(INFO) << "Try to pull weights. Local step number: " << total_iteration_
<< ", step number needs to run per iteration: " << step_num_per_iteration;


+ 3
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/fl/fused_push_weight_kernel.h View File

@@ -50,6 +50,9 @@ class FusedPushWeightKernel : public CPUKernel {

total_iteration_++;
uint64_t step_num_per_iteration = fl::worker::FLWorker::GetInstance().worker_step_num_per_iteration();
if (step_num_per_iteration == 0) {
MS_LOG(EXCEPTION) << "Step numbers of per iteration should not equal to 0";
}
// The worker has to train kWorkerTrainStepNum standalone iterations before it communicates with server.
MS_LOG(INFO) << "Try to push weights. Local step number: " << total_iteration_
<< ", step number needs to run per iteration: " << step_num_per_iteration;


+ 1
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/apply_momentum_ps_kernel.cc View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/ps/apply_momentum_ps_kernel.h"

namespace mindspore {


+ 1
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/apply_momentum_ps_kernel.h View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_APPLY_MOMENTUM_PS_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_APPLY_MOMENTUM_PS_KERNEL_H_



+ 7
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/embedding_look_up_proxy_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/ps/embedding_look_up_proxy_kernel.h"
#include <vector>
#include <algorithm>
@@ -28,6 +29,11 @@ void EmbeddingLookUpProxyKernel::InitKernel(const CNodePtr &kernel_node) {
auto indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1);
auto output_shape = AnfAlgo::GetOutputInferShape(kernel_node, 0);
size_t axis = kShape2dDims - input_shape.size();
if (input_shape.empty() || input_shape.size() > kShape2dDims) {
MS_LOG(EXCEPTION) << "Input shape should not empty or greater than " << kShape2dDims << "-D, but got "
<< input_shape.size();
}

for (auto dim : input_shape) {
input_dims_ *= dim;
}


+ 16
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/embedding_look_up_ps_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,10 +26,22 @@ namespace kernel {
namespace ps {
using mindspore::ps::Util;
constexpr int kAxis = 0;
constexpr size_t kEmbeddingLookUpPSInputSize = 3;

void EmbeddingLookUpPSKernel::InitKernel(
const std::shared_ptr<std::vector<std::shared_ptr<std::vector<size_t>>>> &shapes) {
const std::vector<std::shared_ptr<std::vector<size_t>>> &shape_vec = *shapes;
if (shape_vec.size() < kEmbeddingLookUpPSInputSize) {
MS_LOG(EXCEPTION) << "EmbeddingLookUpPSKernel needs " << kEmbeddingLookUpPSInputSize << " input shapes, but got "
<< shape_vec.size();
}
for (auto shape : shape_vec) {
MS_EXCEPTION_IF_NULL(shape);
}
input_shape_ = *(shape_vec[0]);
if (input_shape_.empty()) {
MS_LOG(EXCEPTION) << "Input shape should not empty";
}
first_dim_size_ = input_shape_[0];
for (size_t i = 1; i < input_shape_.size(); ++i) {
outer_dim_size_ *= input_shape_[i];
@@ -56,6 +68,9 @@ void EmbeddingLookUpPSKernel::InitKernel(
}

void EmbeddingLookUpPSKernel::ReInit(const std::vector<std::vector<size_t>> &shapes) {
if (shapes.empty() || shapes[0].empty()) {
MS_LOG(EXCEPTION) << "Shape should not empty";
}
const auto &indices_shape = shapes[0];
indices_lens_ = indices_shape[0];



+ 0
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/pserver_kernel.cc View File

@@ -23,7 +23,6 @@ void PServerKernel::Shard(std::vector<size_t> *shape, int axis) {
MS_EXCEPTION_IF_NULL(shape);
if ((*shape).size() <= IntToSize(axis)) {
MS_LOG(EXCEPTION) << "Shape size is invalid.";
return;
}
(*shape)[IntToSize(axis)] =
LongToSize(Util::LocalShard(SizeToLong((*shape)[IntToSize(axis)]), SizeToLong(rank_id_), SizeToLong(pserver_num_)));


+ 19
- 4
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_adam_ps_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/ps/sparse_apply_adam_ps_kernel.h"
#include <memory>
#include "backend/kernel_compiler/common_utils.h"
@@ -22,12 +23,14 @@
namespace mindspore {
namespace kernel {
namespace ps {
constexpr size_t kSparseApplyAdamPSInputsShapeSize = 11;

void SparseApplyAdamPSKernel::InitKernel(
const CNodePtr &cnode, const std::shared_ptr<std::vector<std::shared_ptr<std::vector<size_t>>>> &shapes) {
MS_EXCEPTION_IF_NULL(shapes);
const std::vector<std::shared_ptr<std::vector<size_t>>> &shape_vec = *shapes;
if (shape_vec.size() <= kSparseApplyAdamPSInputSize) {
if (shape_vec.size() < kSparseApplyAdamPSInputsShapeSize) {
MS_LOG(EXCEPTION) << "SparseApplyAdamPSKernel needs 10 input shapes, but got " << shape_vec.size();
return;
}
std::vector<size_t> &var_shape = *(shape_vec[0]);
std::vector<size_t> &m_shape = *(shape_vec[1]);
@@ -38,13 +41,18 @@ void SparseApplyAdamPSKernel::InitKernel(
Shard(&var_shape, 0);
Shard(&m_shape, 0);
Shard(&v_shape, 0);

if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
}
if (!IsSameShape(var_shape, m_shape)) {
MS_LOG(EXCEPTION) << "var and m should have the same shape";
}
if (!IsSameShape(var_shape, v_shape)) {
MS_LOG(EXCEPTION) << "var and v should have the same shape";
}
if (var_shape.size() != grad_shape.size()) {
MS_LOG(EXCEPTION) << "var and grad should have the same shape size";
}
var_first_dim_size_ = var_shape[0];
for (size_t i = 1; i < var_shape.size(); ++i) {
if (var_shape[i] != grad_shape[i]) {
@@ -70,6 +78,9 @@ void SparseApplyAdamPSKernel::InitKernel(
}

void SparseApplyAdamPSKernel::ReInit(const std::vector<std::vector<size_t>> &shapes) {
if (shapes.empty() || shapes[0].empty()) {
MS_LOG(EXCEPTION) << "Shape should not empty";
}
const std::vector<size_t> &indices_shape = shapes[0];
indices_size_ = indices_shape[0];
workspace_size_list_[0] = indices_size_ * var_outer_dim_size_ * sizeof(float) * worker_num_;
@@ -77,6 +88,10 @@ void SparseApplyAdamPSKernel::ReInit(const std::vector<std::vector<size_t>> &sha
}

void SparseApplyAdamPSKernel::ReInit(const std::vector<AddressPtr> &inputs) {
if (inputs.size() < kSparseApplyAdamPSInputsShapeSize) {
MS_LOG(EXCEPTION) << "Input numbers should not less to " << kSparseApplyAdamPSInputsShapeSize << ", but got "
<< inputs.size();
}
const auto &indices_addr = inputs[10];
indices_size_ = indices_addr->size / sizeof(int);
workspace_size_list_[0] = indices_size_ * var_outer_dim_size_ * sizeof(float);


+ 2
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_adam_ps_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_APPLY_ADAM_PS_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_APPLY_ADAM_PS_KERNEL_H_

@@ -25,7 +26,6 @@ namespace mindspore {
namespace kernel {
namespace ps {
using mindspore::kernel::SparseApplyAdamCPUKernel;
constexpr size_t kSparseApplyAdamPSInputSize = 10;
class SparseApplyAdamPSKernel : public SparseApplyAdamCPUKernel, public PServerKernel {
public:
SparseApplyAdamPSKernel(size_t rank_id, size_t pserver_num, size_t worker_num)


+ 25
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_ftrl_ps_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,15 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/ps/sparse_apply_ftrl_ps_kernel.h"
#include "runtime/device/cpu/cpu_device_address.h"

namespace mindspore {
namespace kernel {
namespace ps {
constexpr size_t kSparseApplyFtrlPSInputSize = 5;

void SparseApplyFtrlPSKernel::InitKernel(
const CNodePtr &cnode, const std::shared_ptr<std::vector<std::shared_ptr<std::vector<size_t>>>> &shapes) {
MS_EXCEPTION_IF_NULL(shapes);
const std::vector<std::shared_ptr<std::vector<size_t>>> &shape_vec = *shapes;
if (shape_vec.size() < kSparseApplyFtrlPSInputSize) {
MS_LOG(EXCEPTION) << "SparseApplyAdamPSKernel needs " << kSparseApplyFtrlPSInputSize << " input shapes, but got "
<< shape_vec.size();
}
std::vector<size_t> var_shape = *(shape_vec[0]);
std::vector<size_t> accum_shape = *(shape_vec[1]);
std::vector<size_t> linear_shape = *(shape_vec[2]);
@@ -32,7 +40,15 @@ void SparseApplyFtrlPSKernel::InitKernel(
Shard(&accum_shape, 0);
Shard(&linear_shape, 0);

var_first_dim_size_ = var_shape[0];
if (var_shape.size() != grad_shape.size()) {
MS_LOG(EXCEPTION) << "var and grad should have the same shape size";
}
if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
} else {
var_first_dim_size_ = var_shape[0];
}

for (size_t i = 1; i < var_shape.size(); ++i) {
if (var_shape[i] != grad_shape[i]) {
MS_LOG(EXCEPTION) << "The shape of var and grad must equal in dimension " << i;
@@ -73,6 +89,9 @@ void SparseApplyFtrlPSKernel::InitKernel(
}

void SparseApplyFtrlPSKernel::ReInit(const std::vector<std::vector<size_t>> &shapes) {
if (shapes.empty() || shapes[0].empty()) {
MS_LOG(EXCEPTION) << "Shape should not empty";
}
const std::vector<size_t> &indices_shape = shapes[0];
indices_size_ = indices_shape[0];
workspace_size_list_[0] = indices_size_ * var_outer_dim_size_ * sizeof(float) * worker_num_;
@@ -80,6 +99,10 @@ void SparseApplyFtrlPSKernel::ReInit(const std::vector<std::vector<size_t>> &sha
}

void SparseApplyFtrlPSKernel::ReInit(const std::vector<AddressPtr> &inputs) {
if (inputs.size() < kSparseApplyFtrlPSInputSize) {
MS_LOG(EXCEPTION) << "Input numbers should not less than " << kSparseApplyFtrlPSInputSize << ", but got "
<< inputs.size();
}
const auto &indices_addr = inputs[4];
indices_size_ = indices_addr->size / sizeof(int);
workspace_size_list_[0] = indices_size_ * var_outer_dim_size_ * sizeof(float) * worker_num_;


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_ftrl_ps_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_APPLY_FTRL_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_APPLY_FTRL_PS_KERNEL_H_



+ 18
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/ps/sparse_apply_lazy_adam_ps_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/ps/sparse_apply_lazy_adam_ps_kernel.h"
#include <memory>
#include "backend/kernel_compiler/common_utils.h"
@@ -22,9 +23,16 @@
namespace mindspore {
namespace kernel {
namespace ps {
constexpr size_t kSparseApplyLazyAdamPSInputSize = 5;

void SparseApplyLazyAdamPSKernel::InitKernel(
const CNodePtr &cnode, const std::shared_ptr<std::vector<std::shared_ptr<std::vector<size_t>>>> &shapes) {
MS_EXCEPTION_IF_NULL(shapes);
const std::vector<std::shared_ptr<std::vector<size_t>>> &shape_vec = *shapes;
if (shape_vec.size() < kSparseApplyLazyAdamPSInputSize) {
MS_LOG(EXCEPTION) << "SparseApplyLazyAdamPSKernel needs " << kSparseApplyLazyAdamPSInputSize
<< " input shapes, but got " << shape_vec.size();
}
std::vector<size_t> &var_shape = *(shape_vec[0]);
std::vector<size_t> &m_shape = *(shape_vec[1]);
std::vector<size_t> &v_shape = *(shape_vec[2]);
@@ -35,6 +43,12 @@ void SparseApplyLazyAdamPSKernel::InitKernel(
Shard(&m_shape, 0);
Shard(&v_shape, 0);

if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
}
if (var_shape.size() != grad_shape.size()) {
MS_LOG(EXCEPTION) << "var and grad should have the same shape size";
}
if (!IsSameShape(var_shape, m_shape)) {
MS_LOG(EXCEPTION) << "var and m should have the same shape";
}
@@ -65,6 +79,9 @@ void SparseApplyLazyAdamPSKernel::InitKernel(
}

void SparseApplyLazyAdamPSKernel::ReInit(const std::vector<std::vector<size_t>> &shapes) {
if (shapes.empty() || shapes[0].empty()) {
MS_LOG(EXCEPTION) << "Shape should not empty";
}
const std::vector<size_t> &indices_shape = shapes[0];
indices_size_ = indices_shape[0];
workspace_size_list_[0] = indices_size_ * var_outer_dim_size_ * sizeof(float) * worker_num_;


+ 6
- 3
mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_scatter_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,12 +27,15 @@ constexpr auto kRanksGroup = "group";
ReduceScatterCPUKernel::ReduceScatterCPUKernel() : op_type_(kMPIOpTypeSum) {}

void ReduceScatterCPUKernel::InitKernel(const CNodePtr &kernel_node) {
auto op = AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("op");
MS_EXCEPTION_IF_NULL(kernel_node);
auto primitive = AnfAlgo::GetCNodePrimitive(kernel_node);
MS_EXCEPTION_IF_NULL(primitive);
auto op = primitive->GetAttr("op");
if (op != nullptr) {
op_type_ = GetValue<std::string>(op);
}

auto ranks_group = AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr(kRanksGroup);
auto ranks_group = primitive->GetAttr(kRanksGroup);
if (ranks_group != nullptr) {
ranks_group_ = GetValue<std::vector<int>>(ranks_group);
} else {


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/reshape_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd
* Copyright 2019-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/reshape_cpu_kernel.h"
#include "runtime/device/cpu/cpu_device_address.h"



+ 3
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/reshape_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
* Copyright 2019-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESHAPE_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESHAPE_CPU_KERNEL_H_

#include <vector>
#include <memory>
#include "backend/kernel_compiler/cpu/cpu_kernel.h"


+ 15
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/resize_bilinear_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,12 +20,24 @@

namespace mindspore {
namespace kernel {
namespace {
constexpr size_t kResizeBilinearInputSize = 4;
constexpr size_t kResizeBilinearAttrSize = 2;
} // namespace
void ResizeBilinearCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
size_ = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, SIZE);
align_corners_ = AnfAlgo::GetNodeAttr<bool>(kernel_node, "align_corners");
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
if (shape_.size() < kResizeBilinearInputSize) {
MS_LOG(EXCEPTION) << "Input shape size should be " << kResizeBilinearInputSize << ", but got " << shape_.size();
}

if (size_.size() < kResizeBilinearAttrSize) {
MS_LOG(EXCEPTION) << "Attr SIZE shape size should be " << kResizeBilinearAttrSize << ", but got " << size_.size();
}

size_t in_height = shape_[2];
size_t in_width = shape_[3];
@@ -42,6 +54,8 @@ bool ResizeBilinearCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inpu
LaunchKernel<float16, float16>(inputs, outputs);
} else if (dtype_ == kNumberTypeFloat32) {
LaunchKernel<float, float>(inputs, outputs);
} else {
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return true;
}


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/resize_bilinear_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESIZE_BILINEAR_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESIZE_BILINEAR_CPU_KERNEL_H_

#include <memory>
#include <unordered_map>
#include <vector>


+ 17
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/resize_bilinear_grad_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,12 +20,26 @@

namespace mindspore {
namespace kernel {
namespace {
constexpr size_t kResizeBilinearGradInput0Size = 4;
constexpr size_t kResizeBilinearGradInput1Size = 4;
} // namespace
void ResizeBilinearGradCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
size_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1);
align_corners_ = AnfAlgo::GetNodeAttr<bool>(kernel_node, "align_corners");
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
if (shape_.size() < kResizeBilinearGradInput0Size) {
MS_LOG(EXCEPTION) << "Input_0 shape size should be " << kResizeBilinearGradInput0Size << ", but got "
<< shape_.size();
}

if (size_.size() < kResizeBilinearGradInput1Size) {
MS_LOG(EXCEPTION) << "Input_1 shape size should be " << kResizeBilinearGradInput1Size << ", but got "
<< size_.size();
}

size_t in_height = shape_[2];
size_t in_width = shape_[3];
@@ -43,6 +57,8 @@ bool ResizeBilinearGradCPUKernel::Launch(const std::vector<kernel::AddressPtr> &
LaunchKernel<float16>(inputs, outputs);
} else if (dtype_ == kNumberTypeFloat32) {
LaunchKernel<float>(inputs, outputs);
} else {
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return true;
}


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/resize_bilinear_grad_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESIZE_BILINEAR_GRAD_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESIZE_BILINEAR_GRAD_CPU_KERNEL_H_

#include <memory>
#include <unordered_map>
#include <vector>


+ 17
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/resize_nearest_neighbor_cpu_kernel.cc View File

@@ -20,12 +20,27 @@

namespace mindspore {
namespace kernel {
namespace {
constexpr size_t kResizeNearestNeighborInputSize = 4;
constexpr size_t kResizeNearestNeighborOutputSize = 2;
} // namespace
void ResizeNearestNeighborCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
std::vector<size_t> input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
std::vector<int64_t> output_size = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, SIZE);
align_corners_ = AnfAlgo::GetNodeAttr<bool>(kernel_node, "align_corners");
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
if (input_shape.size() < kResizeNearestNeighborInputSize) {
MS_LOG(EXCEPTION) << "Input_0 shape size should be " << kResizeNearestNeighborInputSize << ", but got "
<< input_shape.size();
}

if (output_size.size() < kResizeNearestNeighborOutputSize) {
MS_LOG(EXCEPTION) << "Output shape size should be " << kResizeNearestNeighborOutputSize << ", but got "
<< output_size.size();
}

batch_size_ = input_shape[0];
channel_ = input_shape[1];
in_height_ = input_shape[2];
@@ -50,6 +65,8 @@ bool ResizeNearestNeighborCPUKernel::Launch(const std::vector<kernel::AddressPtr
LaunchKernel<int32_t>(inputs, outputs);
} else if (dtype_ == kNumberTypeInt64) {
LaunchKernel<int64_t>(inputs, outputs);
} else {
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return true;
}


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/resize_nearest_neighbor_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESIZE_NEAREST_NEIGHBOR_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESIZE_NEAREST_NEIGHBOR_CPU_KERNEL_H_

#include <memory>
#include <unordered_map>
#include <vector>


+ 17
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/resize_nearest_neighbor_grad_cpu_kernel.cc View File

@@ -20,12 +20,27 @@

namespace mindspore {
namespace kernel {
namespace {
constexpr size_t kResizeNearestNeighborGradInputSize = 4;
constexpr size_t kResizeNearestNeighborGradOutputSize = 4;
} // namespace
void ResizeNearestNeighborGradCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
std::vector<size_t> input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
std::vector<size_t> output_size = AnfAlgo::GetOutputInferShape(kernel_node, 0);
align_corners_ = AnfAlgo::GetNodeAttr<bool>(kernel_node, "align_corners");
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
if (input_shape.size() < kResizeNearestNeighborGradInputSize) {
MS_LOG(EXCEPTION) << "Input_0 shape size should be " << kResizeNearestNeighborGradInputSize << ", but got "
<< input_shape.size();
}

if (output_size.size() < kResizeNearestNeighborGradOutputSize) {
MS_LOG(EXCEPTION) << "Output shape size should be " << kResizeNearestNeighborGradOutputSize << ", but got "
<< output_size.size();
}

batch_size_ = input_shape[0];
channel_ = input_shape[1];
in_height_ = input_shape[2];
@@ -49,6 +64,8 @@ bool ResizeNearestNeighborGradCPUKernel::Launch(const std::vector<kernel::Addres
LaunchKernel<int32_t>(inputs, outputs);
} else if (dtype_ == kNumberTypeInt64) {
LaunchKernel<int64_t>(inputs, outputs);
} else {
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return true;
}


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/resize_nearest_neighbor_grad_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESIZE_NEAREST_NEIGHBOR_GRAD_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_RESIZE_NEAREST_NEIGHBOR_GRAD_CPU_KERNEL_H_

#include <memory>
#include <unordered_map>
#include <vector>


+ 3
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/rmsprop_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "nnacl/errorcode.h"
#include "nnacl/fp32/rmsprop_fp32.h"
#include "utils/ms_utils.h"
@@ -69,6 +70,7 @@ void RMSPropCPUKernel<T>::LaunchRMSPropUseCenter(T *variable, T *mean_square, T

template <typename T>
void RMSPropCPUKernel<T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
auto node_name = AnfAlgo::GetCNodeName(kernel_node);
if (node_name == "ApplyCenteredRMSProp") {
use_center_ = true;


+ 7
- 7
mindspore/ccsrc/backend/kernel_compiler/cpu/rmsprop_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ namespace kernel {
template <typename T>
class RMSPropCPUKernel : public CPUKernel {
public:
RMSPropCPUKernel() : size_(1), use_center_(false), decay_(0.0), momentum_(0.9), epsilon_(1e-12) {}
RMSPropCPUKernel() {}
~RMSPropCPUKernel() override = default;

void InitKernel(const CNodePtr &kernel_node) override;
@@ -41,11 +41,11 @@ class RMSPropCPUKernel : public CPUKernel {
float *learning_rate, float *decay, float *epsilon);

private:
size_t size_;
bool use_center_;
float decay_;
float momentum_;
float epsilon_;
size_t size_{1};
bool use_center_{false};
float decay_{0.f};
float momentum_{0.9f};
float epsilon_{1e-12};
TypeId dtype_{kTypeUnknown};
};



+ 10
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_arithmetic_cpu_kernel.cc View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/scatter_arithmetic_cpu_kernel.h"
#include <map>
#include <limits>
@@ -20,13 +21,22 @@

namespace mindspore {
namespace kernel {
namespace {
constexpr size_t kInputNum = 3;
constexpr size_t kOutputNum = 1;
} // namespace
template <typename T>
void ScatterArithmeticCPUKernel<T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
kernel_name_ = AnfAlgo::GetCNodeName(kernel_node);
auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
input_size_ = 1;
inner_size_ = 1;
if (input_shape.empty()) {
MS_LOG(EXCEPTION) << "Input shape is empty";
}

for (size_t i = 1; i < input_shape.size(); i++) {
inner_size_ *= input_shape[i];
}


+ 5
- 5
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_arithmetic_cpu_kernel.h View File

@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SCATTER_ARITHMETIC_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SCATTER_ARITHMETIC_CPU_KERNEL_H_

#include <vector>
#include <string>
#include "backend/kernel_compiler/cpu/cpu_kernel.h"
@@ -22,8 +24,6 @@

namespace mindspore {
namespace kernel {
constexpr size_t kInputNum = 3;
constexpr size_t kOutputNum = 1;
template <typename T>
class ScatterArithmeticCPUKernel : public CPUKernel {
public:
@@ -53,9 +53,9 @@ class ScatterArithmeticCPUKernel : public CPUKernel {

void ScatterUpdate(T *input, const int *indices, const T *updates);

size_t input_size_{0};
size_t inner_size_{0};
size_t indices_size_{0};
size_t input_size_{1};
size_t inner_size_{1};
size_t indices_size_{1};
std::string kernel_name_;
enum input_list_ { INPUT, INDICES, UPDATES };
};


+ 12
- 12
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_cpu_kernel.cc View File

@@ -22,14 +22,16 @@
namespace mindspore {
namespace kernel {
namespace {
constexpr size_t kScatterNdInputSize = 2;
constexpr size_t kScatterNdOutputSize = 1;
constexpr size_t kMinIndiceRank = 2;

template <typename S, typename T>
void Compute(const ComputeParams<S, T> *params, const size_t start, const size_t end) {
MS_EXCEPTION_IF_NULL(params);
T *target = params->target_;
S *indices = params->indices_;
T *updates = params->updates_;
std::vector<int> *out_strides = params->out_strides_;
MS_EXCEPTION_IF_NULL(out_strides);

for (size_t i = start; i < end; ++i) {
int offset = 0;
@@ -52,6 +54,7 @@ void Compute(const ComputeParams<S, T> *params, const size_t start, const size_t

template <typename S, typename T>
void ScatterNdCPUKernel<S, T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
Check(kernel_node);
auto shape = AnfAlgo::GetOutputInferShape(kernel_node, 0);
auto indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
@@ -60,7 +63,7 @@ void ScatterNdCPUKernel<S, T>::InitKernel(const CNodePtr &kernel_node) {
if (indices_unit_rank > shape.size()) {
MS_LOG(EXCEPTION) << "Value of last dimension of indices is greater than shape rank";
}
if (indices_shape.size() < MIN_INDICE_RANK) {
if (indices_shape.size() < kMinIndiceRank) {
MS_LOG(EXCEPTION) << "Indices has dimension less than 2";
}
if (updates_shape.size() != indices_shape.size() - 1 + shape.size() - indices_unit_rank) {
@@ -72,20 +75,17 @@ void ScatterNdCPUKernel<S, T>::InitKernel(const CNodePtr &kernel_node) {
}
}
indices_unit_rank_ = SizeToInt(indices_unit_rank);
unit_size_ = 1;
for (size_t i = indices_shape.size() - 1; i < updates_shape.size(); ++i) {
unit_size_ *= SizeToInt(updates_shape[i]);
}
constexpr int TWO = 2;
constexpr int THREE = 3;
num_units_ = 1;
num_units_ *= updates_shape[indices_shape.size() - TWO];
for (int i = SizeToInt(indices_shape.size()) - THREE; i >= 0; i--) {

num_units_ *= updates_shape[indices_shape.size() - 2];
for (int i = SizeToInt(indices_shape.size()) - 3; i >= 0; i--) {
num_units_ *= updates_shape[IntToSize(i)];
}
int out_stride = 1;
out_strides_.push_back(out_stride);
for (int i = indices_unit_rank_ - TWO; i >= 0; i--) {
for (int i = indices_unit_rank_ - 2; i >= 0; i--) {
out_stride *= SizeToInt(shape[IntToSize(i + 1)]);
out_strides_.push_back(out_stride);
}
@@ -123,11 +123,11 @@ bool ScatterNdCPUKernel<S, T>::Launch(const std::vector<kernel::AddressPtr> &inp
template <typename S, typename T>
void ScatterNdCPUKernel<S, T>::Check(const CNodePtr &kernel_node) {
size_t input_num = AnfAlgo::GetInputTensorNum(kernel_node);
if (input_num != INPUT_NUM) {
if (input_num != kScatterNdInputSize) {
MS_LOG(EXCEPTION) << "Input number is " << input_num << ", but ScatterNd needs 2 input.";
}
size_t output_num = AnfAlgo::GetOutputTensorNum(kernel_node);
if (output_num != OUTPUT_NUM) {
if (output_num != kScatterNdOutputSize) {
MS_LOG(EXCEPTION) << "Output number is " << output_num << ", but ScatterNd needs 1 output.";
}
}


+ 3
- 5
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_cpu_kernel.h View File

@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SCATTER_ND_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SCATTER_ND_CPU_KERNEL_H_

#include <vector>
#include <unordered_map>
#include "backend/kernel_compiler/cpu/cpu_kernel.h"
@@ -23,9 +24,6 @@

namespace mindspore {
namespace kernel {
constexpr size_t INPUT_NUM = 2;
constexpr size_t OUTPUT_NUM = 1;
constexpr size_t MIN_INDICE_RANK = 2;
template <typename S, typename T>
struct ComputeParams {
T *target_{nullptr};
@@ -51,8 +49,8 @@ class ScatterNdCPUKernel : public CPUKernel {
private:
void Check(const CNodePtr &kernel_node);

int unit_size_{0};
size_t num_units_{0};
int unit_size_{1};
size_t num_units_{1};
int indices_unit_rank_{0};
std::vector<int> out_strides_;
};


+ 6
- 6
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,14 +22,14 @@
namespace mindspore {
namespace kernel {
namespace {
constexpr size_t kMinIndiceRank = 2;

template <typename T>
void Compute(const ComputeParams<T> *params, const size_t start, const size_t end) {
MS_EXCEPTION_IF_NULL(params);
T *x = params->x_;
int *indices = params->indices_;
T *updates = params->updates_;
std::vector<int> *out_strides = params->out_strides_;
MS_EXCEPTION_IF_NULL(out_strides);

for (int i = SizeToInt(start); i < SizeToInt(end); ++i) {
int offset = 0;
@@ -50,6 +50,7 @@ void Compute(const ComputeParams<T> *params, const size_t start, const size_t en
} // namespace

void ScatterNdUpdateCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
Check(kernel_node);
auto shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
auto indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1);
@@ -58,7 +59,7 @@ void ScatterNdUpdateCPUKernel::InitKernel(const CNodePtr &kernel_node) {
if (indices_unit_rank > shape.size()) {
MS_LOG(EXCEPTION) << "Value of last dimension of indices is greater than shape rank";
}
if (indices_shape.size() < 2) {
if (indices_shape.size() < kMinIndiceRank) {
MS_LOG(EXCEPTION) << "Indices dimension less than 2";
}
if (updates_shape.size() != indices_shape.size() - 1 + shape.size() - indices_unit_rank) {
@@ -97,8 +98,7 @@ bool ScatterNdUpdateCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inp
} else if (dtype_ == kNumberTypeFloat32) {
LaunchKernel<float>(inputs, outputs);
} else {
MS_LOG(ERROR) << "Only support float16, float32";
return false;
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return true;
}


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SCATTER_ND_UPDATE_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SCATTER_ND_UPDATE_CPU_KERNEL_H_

#include <vector>
#include <memory>
#include <unordered_map>


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/select_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ namespace mindspore {
namespace kernel {
template <typename T>
void SelectCPUKernel<T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
size_t input_num = AnfAlgo::GetInputTensorNum(kernel_node);
if (input_num != 3) {
MS_LOG(EXCEPTION) << "Input number is " << input_num << ", but SelectCpuKernel needs 3 input.";


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/select_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SELECT_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SELECT_CPU_KERNEL_H_



+ 3
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/sigmoid_cross_entropy_with_logits_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
namespace mindspore {
namespace kernel {
void SigmoidCrossEntropyWithLogitsCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
std::vector<size_t> x_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
@@ -36,7 +37,7 @@ bool SigmoidCrossEntropyWithLogitsCPUKernel::Launch(const std::vector<kernel::Ad
} else if (dtype_ == kNumberTypeFloat32 || dtype_ == kNumberTypeFloat64) {
LaunchKernel<float>(inputs, outputs);
} else {
MS_LOG(EXCEPTION) << "Input dtype only support float16, float32, float64!";
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return true;
}


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/sigmoid_cross_entropy_with_logits_grad_cpu_kernel.cc View File

@@ -20,6 +20,7 @@
namespace mindspore {
namespace kernel {
void SigmoidCrossEntropyWithLogitsGradCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
std::vector<size_t> x_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
@@ -36,7 +37,7 @@ bool SigmoidCrossEntropyWithLogitsGradCPUKernel::Launch(const std::vector<kernel
} else if (dtype_ == kNumberTypeFloat32 || dtype_ == kNumberTypeFloat64) {
LaunchKernel<float>(inputs, outputs);
} else {
MS_LOG(EXCEPTION) << "Input dtype only support float16, float32, float64!";
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return true;
}


+ 1
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/slice_cpu_kernel.cc View File

@@ -33,6 +33,7 @@ int NormalizeBeginPos(int begin_pos, int dim_len) {
}

void SliceCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
static const std::unordered_map<TypeId, int> type_size_map = {{kNumberTypeBool, sizeof(bool)},
{kNumberTypeInt32, sizeof(int)},
{kNumberTypeFloat32, sizeof(float)},


+ 7
- 7
mindspore/ccsrc/backend/kernel_compiler/cpu/slice_grad_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,12 +21,13 @@
namespace mindspore {
namespace kernel {
void SliceGradCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
output_shape_ = AnfAlgo::GetOutputInferShape(kernel_node, 0);
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
std::vector<int64_t> begin_me = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, BEGIN);
(void)std::transform(begin_me.begin(), begin_me.end(), std::back_inserter(begin_),
[](const int64_t &value) { return static_cast<int>(value); });
[](const int64_t &value) { return LongToInt(value); });
auto prim = AnfAlgo::GetCNodePrimitive(kernel_node);
MS_EXCEPTION_IF_NULL(prim);
auto strides = prim->GetAttr(STRIDES);
@@ -34,9 +35,9 @@ void SliceGradCPUKernel::InitKernel(const CNodePtr &kernel_node) {
std::vector<int64_t> strides_me = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, STRIDES);
std::vector<int64_t> end_me = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, END);
(void)std::transform(strides_me.begin(), strides_me.end(), std::back_inserter(strides_),
[](const int64_t &value) { return static_cast<int>(value); });
[](const int64_t &value) { return LongToInt(value); });
(void)std::transform(end_me.begin(), end_me.end(), std::back_inserter(end_),
[](const int64_t &value) { return static_cast<int>(value); });
[](const int64_t &value) { return LongToInt(value); });
if (strides_.size() != end_.size() || strides_.size() != output_shape_.size()) {
MS_LOG(EXCEPTION) << "stride|end|input size must be equal";
}
@@ -44,7 +45,7 @@ void SliceGradCPUKernel::InitKernel(const CNodePtr &kernel_node) {
} else {
std::vector<int64_t> size_me = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, SIZE);
(void)std::transform(size_me.begin(), size_me.end(), std::back_inserter(size_),
[](const int64_t &value) { return static_cast<int>(value); });
[](const int64_t &value) { return LongToInt(value); });
if (size_.size() != output_shape_.size() || begin_.size() != output_shape_.size()) {
MS_LOG(EXCEPTION) << "begin|size|input size must be equal";
}
@@ -88,8 +89,7 @@ bool SliceGradCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inputs, c
} else if (dtype_ == kNumberTypeFloat64) {
ret = LaunchKernel<double>(inputs, outputs);
} else {
MS_LOG(ERROR) << "Slice op only support input_x bool,int32,float32 and float64";
return false;
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return ret;
}


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/smooth_l1_loss_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ namespace mindspore {
namespace kernel {
template <typename T>
void SmoothL1LossCPUKernel<T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
beta_ = AnfAlgo::GetNodeAttr<float>(kernel_node, "beta");
CheckParam(kernel_node);
std::vector<size_t> x_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/smooth_l1_loss_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SMOOTH_L1_LOSS_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SMOOTH_L1_LOSS_CPU_KERNEL_H_

#include <memory>
#include <unordered_map>
#include <vector>


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/smooth_l1_loss_grad_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ namespace mindspore {
namespace kernel {
template <typename T>
void SmoothL1LossGradCPUKernel<T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
beta_ = AnfAlgo::GetNodeAttr<float>(kernel_node, "beta");
CheckParam(kernel_node);
std::vector<size_t> x_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);


+ 4
- 3
mindspore/ccsrc/backend/kernel_compiler/cpu/smooth_l1_loss_grad_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SMOOTH_L1_LOSS_GRAD_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SMOOTH_L1_LOSS_GRAD_CPU_KERNEL_H_

#include <memory>
#include <unordered_map>
#include <vector>
@@ -37,8 +38,8 @@ class SmoothL1LossGradCPUKernel : public CPUKernel {

private:
void CheckParam(const CNodePtr &kernel_node);
float beta_ = 1.0;
uint64_t tensor_size_ = 1;
float beta_{1.0};
uint64_t tensor_size_{1};
};

MS_REG_CPU_KERNEL_T(SmoothL1LossGrad,


+ 1
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/sort_cpu_kernel.cc View File

@@ -22,6 +22,7 @@ namespace kernel {

template <typename T>
void SortCpuKernel<T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
size_t input_count = AnfAlgo::GetInputTensorNum(kernel_node);
if (input_count != 1) {
MS_LOG(EXCEPTION) << input_count << " inputs were provided, but Sort expects 1.";


+ 10
- 4
mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_apply_adam_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/sparse_apply_adam_cpu_kernel.h"
#include "backend/kernel_compiler/common_utils.h"
#include "runtime/device/cpu/cpu_device_address.h"
@@ -104,14 +105,17 @@ void SparseApplyAdamCPUKernel::InitKernel(const CNodePtr &kernel_node) {
std::vector<size_t> v_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 2);
std::vector<size_t> grad_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 9);
std::vector<size_t> indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 10);
if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
}
if (!IsSameShape(var_shape, m_shape)) {
MS_LOG(EXCEPTION) << "var and m should have the same shape";
}
if (!IsSameShape(var_shape, v_shape)) {
MS_LOG(EXCEPTION) << "var and v should have the same shape";
}
if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
if (var_shape.size() != grad_shape.size()) {
MS_LOG(EXCEPTION) << "var and grad should have the same shape size";
}
var_first_dim_size_ = var_shape[0];
for (size_t i = 1; i < var_shape.size(); ++i) {
@@ -201,8 +205,10 @@ bool SparseApplyAdamCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inp
}
if (indices_data_type_ == kNumberTypeInt32) {
LaunchKernel<int>(inputs, workspace);
} else {
} else if (indices_data_type_ == kNumberTypeInt64) {
LaunchKernel<int64_t>(inputs, workspace);
} else {
MS_LOG(EXCEPTION) << "Unsupported indices data type: " << indices_data_type_;
}
return true;
}


+ 11
- 4
mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_apply_ftrl_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/sparse_apply_ftrl_cpu_kernel.h"
#include "backend/kernel_compiler/common_utils.h"
#include "runtime/device/cpu/cpu_device_address.h"
@@ -85,15 +86,19 @@ void SparseApplyFtrlCPUKernel::InitKernel(const CNodePtr &kernel_node) {
std::vector<size_t> linear_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 2);
std::vector<size_t> grad_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 3);
std::vector<size_t> indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 4);
if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
}
if (!IsSameShape(var_shape, accum_shape)) {
MS_LOG(EXCEPTION) << "var and accum should have the same shape";
}
if (!IsSameShape(var_shape, linear_shape)) {
MS_LOG(EXCEPTION) << "var and linear should have the same shape";
}
if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
if (var_shape.size() != grad_shape.size()) {
MS_LOG(EXCEPTION) << "var and grad should have the same shape size";
}

var_first_dim_size_ = var_shape[0];
for (size_t i = 1; i < var_shape.size(); ++i) {
if (var_shape[i] != grad_shape[i]) {
@@ -174,8 +179,10 @@ bool SparseApplyFtrlCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inp

if (indices_data_type_ == kNumberTypeInt32) {
LaunchKernel<int>(inputs, workspace);
} else {
} else if (indices_data_type_ == kNumberTypeInt64) {
LaunchKernel<int64_t>(inputs, workspace);
} else {
MS_LOG(EXCEPTION) << "Unsupported indices data type: " << indices_data_type_;
}
return true;
}


+ 11
- 4
mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_apply_lazy_adam_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/sparse_apply_lazy_adam_cpu_kernel.h"
#include "backend/kernel_compiler/common_utils.h"
#include "runtime/device/cpu/cpu_device_address.h"
@@ -81,15 +82,19 @@ void SparseApplyLazyAdamCPUKernel::InitKernel(const CNodePtr &kernel_node) {
std::vector<size_t> v_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 2);
std::vector<size_t> grad_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 9);
std::vector<size_t> indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 10);
if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
}
if (!IsSameShape(var_shape, m_shape)) {
MS_LOG(EXCEPTION) << "var and m should have the same shape";
}
if (!IsSameShape(var_shape, v_shape)) {
MS_LOG(EXCEPTION) << "var and v should have the same shape";
}
if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
if (var_shape.size() != grad_shape.size()) {
MS_LOG(EXCEPTION) << "var and grad should have the same shape size";
}

var_first_dim_size_ = var_shape[0];
for (size_t i = 1; i < var_shape.size(); ++i) {
if (var_shape[i] != grad_shape[i]) {
@@ -168,8 +173,10 @@ bool SparseApplyLazyAdamCPUKernel::Launch(const std::vector<kernel::AddressPtr>

if (indices_data_type_ == kNumberTypeInt32) {
LaunchKernel<int>(inputs, workspace);
} else {
} else if (indices_data_type_ == kNumberTypeInt64) {
LaunchKernel<int64_t>(inputs, workspace);
} else {
MS_LOG(EXCEPTION) << "Unsupported indices data type: " << indices_data_type_;
}
return true;
}


+ 10
- 4
mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_apply_proximal_adagrad_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/sparse_apply_proximal_adagrad_cpu_kernel.h"
#include "backend/kernel_compiler/common_utils.h"
#include "runtime/device/cpu/cpu_device_address.h"
@@ -83,11 +84,14 @@ void SparseApplyProximalAdagradCPUKernel::InitKernel(const CNodePtr &kernel_node
std::vector<size_t> l2_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 4);
std::vector<size_t> grad_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 5);
std::vector<size_t> indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 6);
if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
}
if (!IsSameShape(var_shape, accum_shape)) {
MS_LOG(EXCEPTION) << "var and accum should have the same shape";
}
if (var_shape.empty()) {
MS_LOG(EXCEPTION) << "var must be at least 1D";
if (var_shape.size() != grad_shape.size()) {
MS_LOG(EXCEPTION) << "var and grad should have the same shape size";
}
var_first_dim_size_ = var_shape[0];
for (size_t i = 1; i < var_shape.size(); ++i) {
@@ -161,8 +165,10 @@ bool SparseApplyProximalAdagradCPUKernel::Launch(const std::vector<kernel::Addre
}
if (indices_data_type_ == kNumberTypeInt32) {
LaunchKernel<int>(inputs, workspace);
} else {
} else if (indices_data_type_ == kNumberTypeInt64) {
LaunchKernel<int64_t>(inputs, workspace);
} else {
MS_LOG(EXCEPTION) << "Unsupported indices data type: " << indices_data_type_;
}
return true;
}


+ 6
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_optimizer_cpu_kernel.h View File

@@ -145,6 +145,9 @@ class SparseOptimizerCPUKernel : public CPUKernel {
MS_EXCEPTION_IF_NULL(sparse_grad->indices_);
MS_EXCEPTION_IF_NULL(each_bucket_size);
size_t bucket_num = each_bucket_size->size();
if (bucket_num < 1) {
MS_LOG(EXCEPTION) << "Bucket num must > 0!";
}
for (size_t i = 0; i < sparse_grad->indices_size_; ++i) {
T index = sparse_grad->indices_[i];
if (index >= 0 && LongToSize(index) < max_index) {
@@ -202,6 +205,9 @@ class SparseOptimizerCPUKernel : public CPUKernel {
MS_LOG(DEBUG) << "Start";
MS_EXCEPTION_IF_NULL(segment);
MS_EXCEPTION_IF_NULL(segment->indices_);
if (param.thread_num_ < 1) {
MS_EXCEPTION(ArgumentError) << "Input param thread num must > 0!";
}
std::vector<size_t> bucket_data_num(param.thread_num_, 0);
for (size_t i = 0; i < segment->indices_size_; ++i) {
T index = segment->indices_[i];


+ 14
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_tensor_dense_matmul_cpu_kernel.cc View File

@@ -14,14 +14,18 @@
* limitations under the License.
*/

#include <functional>

#include "backend/kernel_compiler/cpu/sparse_tensor_dense_matmul_cpu_kernel.h"
#include <functional>

namespace mindspore {
namespace kernel {
namespace {
constexpr size_t kSparseTensorDenseMatmulOutputShapeSize = 2;
constexpr size_t kSparseTensorDenseMatmulDenseShapeSize = 2;
} // namespace
template <typename I, typename T>
void SparseTensorDenseMatmulCPUKernel<I, T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
adj_st_ = AnfAlgo::GetNodeAttr<bool>(kernel_node, ADJ_ST);
adj_dt_ = AnfAlgo::GetNodeAttr<bool>(kernel_node, ADJ_dT);
auto indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, INDICES);
@@ -41,6 +45,14 @@ void SparseTensorDenseMatmulCPUKernel<I, T>::InitKernel(const CNodePtr &kernel_n
output_shape_ = AnfAlgo::GetOutputInferShape(kernel_node, 0);
values_size_ = values_shape[0];
b_shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, DENSE);
if (b_shape_.size() != kSparseTensorDenseMatmulDenseShapeSize) {
MS_LOG(EXCEPTION) << "Dense shape size should equal to " << kSparseTensorDenseMatmulDenseShapeSize << ", but got "
<< b_shape_.size();
}
if (output_shape_.size() != kSparseTensorDenseMatmulOutputShapeSize) {
MS_LOG(EXCEPTION) << "Output shape size not equal to " << kSparseTensorDenseMatmulOutputShapeSize << ", but got "
<< output_shape_.size();
}
}

template <typename I, typename T>


+ 8
- 3
mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_to_dense_cpu_kernal.cc View File

@@ -20,13 +20,18 @@

namespace mindspore {
namespace kernel {
namespace {
constexpr size_t kIndicesShapeSize = 2;
} // namespace

template <typename I, typename T>
void SparseToDenseCPUKernel<I, T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
auto indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
if (indices_shape.size() != 2) {
MS_LOG(EXCEPTION) << "SparseToDense requires 'indices' should be a 2-D Tensor, but got " << indices_shape.size()
<< "-D";
if (indices_shape.size() != kIndicesShapeSize) {
MS_LOG(EXCEPTION) << "SparseToDense requires 'indices' should be a " << kIndicesShapeSize << "-D Tensor, but got "
<< indices_shape.size() << "-D";
}
auto values_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1);
if (values_shape.size() != 1 || values_shape[0] != indices_shape[0]) {


+ 4
- 3
mindspore/ccsrc/backend/kernel_compiler/cpu/sparse_to_dense_cpu_kernal.h View File

@@ -14,8 +14,9 @@
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSETODENSE_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSETODENSE_CPU_KERNEL_H_
#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_TO_DENSE_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_TO_DENSE_CPU_KERNEL_H_

#include <memory>
#include <unordered_map>
#include <vector>
@@ -139,4 +140,4 @@ MS_REG_CPU_KERNEL_T_S(SparseToDense,

} // namespace kernel
} // namespace mindspore
#endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSETODENSE_CPU_KERNEL_H_
#endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPARSE_TO_DENSE_CPU_KERNEL_H_

+ 15
- 6
mindspore/ccsrc/backend/kernel_compiler/cpu/split_cpu_kernel.cc View File

@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <algorithm>
#include "backend/kernel_compiler/cpu/split_cpu_kernel.h"
#include <algorithm>
#include "runtime/device/cpu/cpu_device_address.h"
#include "common/thread_pool.h"

@@ -22,18 +23,26 @@ namespace mindspore {
namespace kernel {
template <typename T>
void SplitCPUKernel<T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
axis_ = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, "axis");
output_num_ = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, "output_num");
if (output_num_ == 0) {
MS_LOG(EXCEPTION) << "Attr output_num is equal to 0";
}
auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
(void)std::transform(input_shape.begin(), input_shape.end(), std::back_inserter(input_shape_),
[](const int &value) { return static_cast<int>(value); });
[](const size_t &value) { return SizeToInt(value); });
if (input_shape_.size() < 1 || input_shape_.size() > SPLIT_STRIDES_SIZE) {
MS_LOG(EXCEPTION) << "Inpu shape size should not less than 1 or greater than " << SPLIT_STRIDES_SIZE << ", but got "
<< input_shape_.size();
}
CheckParam(kernel_node);
}

template <typename T>
void SplitCPUKernel<T>::InitInputOutputSize(const CNodePtr &kernel_node) {
CPUKernel::InitInputOutputSize(kernel_node);
(void)workspace_size_list_.emplace_back((sizeof(T *) * static_cast<size_t>(output_num_)));
(void)workspace_size_list_.emplace_back((sizeof(T *) * LongToSize(output_num_)));
}

template <typename T>
@@ -47,8 +56,8 @@ bool SplitCPUKernel<T>::Launch(const std::vector<kernel::AddressPtr> &inputs,
template <typename T>
void SplitCPUKernel<T>::LaunchSplit(T *input, T **output, size_t /* size */) {
SplitParameter param;
param.num_split_ = static_cast<int>(output_num_);
param.split_dim_ = static_cast<int>(axis_);
param.num_split_ = LongToInt(output_num_);
param.split_dim_ = LongToInt(axis_);
param.strides_[input_shape_.size() - 1] = 1;
for (int i = SizeToInt(input_shape_.size()) - 2; i >= 0; i--) { // from -2 to 0 dim
param.strides_[i] = param.strides_[i + 1] * input_shape_[i + 1];
@@ -94,7 +103,7 @@ void SplitCPUKernel<T>::CheckParam(const CNodePtr &kernel_node) {
if (input_num != 1) {
MS_LOG(EXCEPTION) << "Input number is " << input_num << ", but Split needs 1 input.";
}
if (dims == 0) {
if (dims == 0 || dims > SPLIT_STRIDES_SIZE) {
MS_LOG(EXCEPTION) << "Input dims is " << dims << ", scalar is not supported.";
}
if (axis_ < -dims || axis_ >= dims) {


+ 8
- 6
mindspore/ccsrc/backend/kernel_compiler/cpu/split_cpu_kernel.h View File

@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPLIT_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SPLIT_CPU_KERNEL_H_

#include <vector>
#include <memory>
#include <thread>
@@ -43,13 +45,13 @@ class SplitCPUKernel : public CPUKernel {
private:
void CheckParam(const CNodePtr &kernel_node);
void LaunchSplit(T *input, T **output, size_t size);
int64_t axis_;
int64_t output_num_;
int64_t axis_step_;
int64_t axis_{1};
int64_t output_num_{1};
int64_t axis_step_{1};

size_t input_size_;
size_t dims_after_axis_;
size_t dims_current_after_axis_;
size_t input_size_{1};
size_t dims_after_axis_{1};
size_t dims_current_after_axis_{1};

std::vector<std::vector<size_t>> output_shape_list_;
std::vector<int> input_shape_;


+ 1
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/strided_slice_grad_cpu_kernel.cc View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/strided_slice_grad_cpu_kernel.h"
#include <algorithm>
#include <functional>


+ 1
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/stridedslice_cpu_kernel.cc View File

@@ -15,12 +15,10 @@
*/

#include "backend/kernel_compiler/cpu/stridedslice_cpu_kernel.h"

#include <utility>
#include <functional>
#include <algorithm>
#include <unordered_map>

#include "common/thread_pool.h"
#include "runtime/device/cpu/cpu_device_address.h"

@@ -40,6 +38,7 @@ int NormalizePos(int pos, int dim_len, PosType pos_type) {
}

void StridedSliceCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
input_shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
output_shape_ = AnfAlgo::GetOutputInferShape(kernel_node, 0);
if (input_shape_.size() > DIMENSION_8D || input_shape_.empty()) {


+ 0
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/stridedslice_cpu_kernel.h View File

@@ -19,7 +19,6 @@

#include <vector>
#include <memory>

#include "backend/kernel_compiler/cpu/cpu_kernel.h"
#include "backend/kernel_compiler/cpu/cpu_kernel_factory.h"
#include "nnacl/fp32/strided_slice_fp32.h"


+ 2
- 3
mindspore/ccsrc/backend/kernel_compiler/cpu/sub_and_filter_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,7 @@ bool SubAndFilterCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inputs
} else if (input_x_dtype_ == kNumberTypeInt64) {
LaunchKernel<int64_t>(inputs, outputs);
} else {
MS_LOG(ERROR) << "input x dtype only support int32, int64";
return false;
MS_LOG(EXCEPTION) << "Unsupported input data type: " << input_x_dtype_;
}
return true;
}


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/sub_and_filter_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SUB_AND_FILTER_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_SUB_AND_FILTER_CPU_KERNEL_H_



+ 1
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/tensor_copy_slices_cpu_kernel.cc View File

@@ -15,7 +15,6 @@
*/

#include "backend/kernel_compiler/cpu/tensor_copy_slices_cpu_kernel.h"

#include <functional>
#include <unordered_map>
#include "abstract/utils.h"
@@ -25,6 +24,7 @@
namespace mindspore {
namespace kernel {
void TensorCopySlicesCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
auto update_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1);
auto output_shape = AnfAlgo::GetOutputInferShape(kernel_node, 0);


+ 2
- 3
mindspore/ccsrc/backend/kernel_compiler/cpu/tensor_copy_slices_cpu_kernel.h View File

@@ -19,7 +19,6 @@

#include <vector>
#include <memory>

#include "backend/kernel_compiler/cpu/cpu_kernel.h"
#include "backend/kernel_compiler/cpu/cpu_kernel_factory.h"
#include "nnacl/fp32/strided_slice_fp32.h"
@@ -37,8 +36,8 @@ class TensorCopySlicesCPUKernel : public CPUKernel {

private:
TypeId data_type_;
size_t offset_;
size_t copy_size_;
size_t offset_{0};
size_t copy_size_{0};
std::vector<int64_t> input_shape_;
std::vector<int64_t> update_shape_;
std::vector<int64_t> output_shape_;


+ 1
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/tensoradd_cpu_kernel.cc View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "backend/kernel_compiler/cpu/tensoradd_cpu_kernel.h"
#include <functional>
#include <vector>


+ 1
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/tensoradd_cpu_kernel.h View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_TENSORADD_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_TENSORADD_CPU_KERNEL_H_



+ 14
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/tile_cpu_kernel.cc View File

@@ -37,6 +37,9 @@ void TileCPUKernel::TileMultipleCompute(void) {
if (one_dim_tile_) {
tile_parameter_.fast_multiple_ = static_cast<size_t>(multiple);
tile_parameter_.fast_stride_ = static_cast<size_t>(x_shape_[mul_index] * tile_parameter_.in_strides_[mul_index]);
if (tile_parameter_.fast_stride_ == 0) {
MS_LOG(EXCEPTION) << "Fast stride is equal to 0";
}
tile_parameter_.fast_outer_size_ = static_cast<size_t>(input_size_ / tile_parameter_.fast_stride_);
}
}
@@ -46,7 +49,7 @@ void TileCPUKernel::TileTensorParamrInit(const CNodePtr &kernel_node) {
y_shape_ = AnfAlgo::GetOutputInferShape(kernel_node, 0);
std::vector<int64_t> multiples_me = AnfAlgo::GetNodeAttr<std::vector<int64_t>>(kernel_node, "multiples");
(void)std::transform(multiples_me.begin(), multiples_me.end(), std::back_inserter(multiples_),
[](const int64_t &value) { return static_cast<int>(value); });
[](const int64_t &value) { return LongToInt(value); });
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
size_t ones = multiples_.size() - x_shape_.size();
if (ones > 0) {
@@ -54,6 +57,14 @@ void TileCPUKernel::TileTensorParamrInit(const CNodePtr &kernel_node) {
x_shape_.insert(x_shape_.begin(), 1);
}
}
if (x_shape_.size() > MAX_TILE_DIM_SIZE) {
MS_LOG(EXCEPTION) << "Input shape size should not greater than " << MAX_TILE_DIM_SIZE << ", but got "
<< x_shape_.size();
}
if (y_shape_.size() < x_shape_.size()) {
MS_LOG(EXCEPTION) << "Output shape size should not less than input shape size, but got output shape: " << y_shape_
<< ", input shape: " << x_shape_;
}

input_size_ = 1;
tile_parameter_.in_dim_ = x_shape_.size();
@@ -76,6 +87,7 @@ void TileCPUKernel::TileTensorParamrInit(const CNodePtr &kernel_node) {
}

void TileCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
TileTensorParamrInit(kernel_node);

@@ -94,7 +106,7 @@ void TileCPUKernel::InitKernel(const CNodePtr &kernel_node) {
if (iter != launch_map_.end()) {
launch_func_ = iter->second;
} else {
MS_LOG(EXCEPTION) << "Input data type: " << dtype_ << "is not supported for Tile kernel on CPU.";
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
}



+ 1
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/tile_cpu_kernel.h View File

@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_TILE_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_TILE_CPU_KERNEL_H_

#include <memory>
#include <unordered_map>
#include <vector>


+ 6
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/topk_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,6 +87,9 @@ void TopKCPUKernel::LaunchKernel(const std::vector<AddressPtr> &inputs, const st
void TopKCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
auto x_shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
if (x_shape_.size() < 1) {
MS_LOG(EXCEPTION) << "Input shape size should not less than 1";
}
for (size_t i = 0; i < x_shape_.size() - 1; ++i) {
outer_size_ *= x_shape_[i];
}
@@ -98,7 +101,6 @@ void TopKCPUKernel::InitKernel(const CNodePtr &kernel_node) {
void TopKCPUKernel::InitInputOutputSize(const CNodePtr &kernel_node) {
CPUKernel::InitInputOutputSize(kernel_node);
size_t element_size = outer_size_ * inner_size_;
// id
(void)workspace_size_list_.emplace_back((sizeof(size_t) * element_size));
}

@@ -109,6 +111,8 @@ bool TopKCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inputs,
LaunchKernel<float16>(inputs, workspaces, outputs);
} else if (dtype_ == kNumberTypeFloat32) {
LaunchKernel<float>(inputs, workspaces, outputs);
} else {
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return true;
}


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/topk_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_TOPK_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_TOPK_CPU_KERNEL_H_
#include <vector>


+ 1
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/transpose_cpu_kernel.cc View File

@@ -64,7 +64,7 @@ void TransposeCPUFwdKernel::InitKernel(const CNodePtr &kernel_node) {
if (iter != launch_map_.end()) {
launch_func_ = iter->second;
} else {
MS_LOG(EXCEPTION) << "Input data type: " << dtype_ << "is not supported for Transpose kernel on CPU.";
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
}



+ 2
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/transpose_cpu_kernel.h View File

@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_TRANSPOSE_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_TRANSPOSE_CPU_KERNEL_H_

#include <vector>
#include <unordered_map>
#include <memory>


+ 6
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/unique_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,9 +21,13 @@ namespace mindspore {
namespace kernel {
constexpr size_t kBucketSortThreshold = 100000;
void UniqueCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
node_wpt_ = kernel_node;
CheckParam(kernel_node);
auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
if (input_shape.empty()) {
MS_LOG(EXCEPTION) << "Input shape is empty";
}
input_size_ = input_shape[0];
dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
if (AnfAlgo::HasNodeAttr(SORTED, kernel_node)) {
@@ -48,7 +52,7 @@ bool UniqueCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inputs,
} else if (dtype_ == kNumberTypeFloat32 || dtype_ == kNumberTypeFloat16) {
LaunchKernel<float, int>(inputs, workspace, outputs);
} else {
MS_LOG(EXCEPTION) << "Not support type: " << dtype_;
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
if (!node_wpt_.expired()) {
auto node_ = node_wpt_.lock();


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/unique_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UNIQUE_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UNIQUE_CPU_KERNEL_H_

#include <algorithm>
#include <memory>
#include <thread>


+ 2
- 2
mindspore/ccsrc/backend/kernel_compiler/cpu/unique_with_pad_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ bool UniqueWithPadCPUKernel::Launch(const std::vector<kernel::AddressPtr> &input
UniqueCPUKernel::LaunchKernel<float, int>(inputs, workspace, outputs);
PadOutput<float>(inputs, outputs);
} else {
MS_LOG(EXCEPTION) << "Not support data type: " << dtype_;
MS_LOG(EXCEPTION) << "Unsupported input data type: " << dtype_;
}
return true;
}


+ 1
- 0
mindspore/ccsrc/backend/kernel_compiler/cpu/unique_with_pad_cpu_kernel.h View File

@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UNIQUE_WITH_PAD_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UNIQUE_WITH_PAD_CPU_KERNEL_H_

#include <memory>
#include <unordered_map>
#include <vector>


+ 2
- 4
mindspore/ccsrc/backend/kernel_compiler/cpu/unpack_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ namespace mindspore {
namespace kernel {
template <typename T>
void UnpackCPUKernel<T>::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
CheckParam(kernel_node);
int64_t axis_tmp = AnfAlgo::GetNodeAttr<int64_t>(kernel_node, "axis");
auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
@@ -65,9 +66,7 @@ void UnpackCPUKernel<T>::LaunchKernel(const std::vector<AddressPtr> &inputs,
const std::vector<kernel::AddressPtr> &workspace,
const std::vector<AddressPtr> &outputs) {
const void *input = reinterpret_cast<void *>(inputs[0]->addr);
MS_EXCEPTION_IF_NULL(input);
void **outputs_host = reinterpret_cast<void **>(workspace[0]->addr);
MS_EXCEPTION_IF_NULL(outputs_host);
for (size_t i = 0; i < outputs.size(); i++) {
outputs_host[i] = reinterpret_cast<T *>(outputs[i]->addr);
MS_EXCEPTION_IF_NULL(outputs_host[i]);
@@ -78,7 +77,6 @@ void UnpackCPUKernel<T>::LaunchKernel(const std::vector<AddressPtr> &inputs,

template <typename T>
void UnpackCPUKernel<T>::CheckParam(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
size_t input_num = AnfAlgo::GetInputTensorNum(kernel_node);
if (input_num != 1) {
MS_LOG(EXCEPTION) << "Input number is " << input_num << ", but UnpackCPUKernel needs 1 input.";


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/unpack_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UNPACK_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UNPACK_CPU_KERNEL_H_

#include <algorithm>
#include <memory>
#include <thread>


+ 22
- 20
mindspore/ccsrc/backend/kernel_compiler/cpu/unsorted_segment_sum_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,9 @@ void UnsortedSegmentSumCPUKernel::InitKernel(const CNodePtr &kernel_node) {
auto input_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0);
auto segment_ids_shape = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1);
auto output_shape = AnfAlgo::GetOutputInferShape(kernel_node, 0);
if (output_shape.empty()) {
MS_LOG(EXCEPTION) << "Output shape size is 0";
}
for (size_t i = 0; i < input_shape.size(); ++i) {
unit_num_ *= input_shape[i];
if (i >= segment_ids_shape.size()) {
@@ -50,43 +53,42 @@ void UnsortedSegmentSumCPUKernel::InitKernel(const CNodePtr &kernel_node) {
bool UnsortedSegmentSumCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inputs,
const std::vector<kernel::AddressPtr> &,
const std::vector<kernel::AddressPtr> &outputs) {
bool ret{true};
void *input_addr = inputs[0]->addr;
void *indices_addr = inputs[1]->addr;
void *output_addr = outputs[0]->addr;
auto ret1 = memset_s(output_addr, outputs[0]->size, 0, outputs[0]->size);
if (ret1 != EOK) {
MS_LOG(ERROR) << "Output buff memset fail. ret:" << ret1;
auto ret = memset_s(output_addr, outputs[0]->size, 0, outputs[0]->size);
if (ret != EOK) {
MS_LOG(ERROR) << "Output buff memset fail. ret:" << ret;
return false;
}

if (dtype_ == kNumberTypeInt32 && segment_ids_dtype_ == kNumberTypeInt32) {
ret1 = UnsortedSegmentSum(int, int, static_cast<const int *>(input_addr), SizeToInt(unit_num_),
SizeToInt(input_dim1_), static_cast<const int *>(indices_addr),
static_cast<int *>(output_addr), SizeToInt(output_dim0_), SizeToInt(output_dim1_));
ret = UnsortedSegmentSum(int, int, static_cast<const int *>(input_addr), SizeToInt(unit_num_),
SizeToInt(input_dim1_), static_cast<const int *>(indices_addr),
static_cast<int *>(output_addr), SizeToInt(output_dim0_), SizeToInt(output_dim1_));
} else if (dtype_ == kNumberTypeFloat32 && segment_ids_dtype_ == kNumberTypeInt32) {
ret1 = UnsortedSegmentSum(float, int, static_cast<const float *>(input_addr), SizeToInt(unit_num_),
SizeToInt(input_dim1_), static_cast<const int *>(indices_addr),
static_cast<float *>(output_addr), SizeToInt(output_dim0_), SizeToInt(output_dim1_));
ret = UnsortedSegmentSum(float, int, static_cast<const float *>(input_addr), SizeToInt(unit_num_),
SizeToInt(input_dim1_), static_cast<const int *>(indices_addr),
static_cast<float *>(output_addr), SizeToInt(output_dim0_), SizeToInt(output_dim1_));
} else if (dtype_ == kNumberTypeInt32 && segment_ids_dtype_ == kNumberTypeInt64) {
ret1 = UnsortedSegmentSum(int, int64_t, static_cast<const int *>(input_addr), SizeToInt(unit_num_),
SizeToInt(input_dim1_), static_cast<const int64_t *>(indices_addr),
static_cast<int *>(output_addr), SizeToInt(output_dim0_), SizeToInt(output_dim1_));
ret = UnsortedSegmentSum(int, int64_t, static_cast<const int *>(input_addr), SizeToInt(unit_num_),
SizeToInt(input_dim1_), static_cast<const int64_t *>(indices_addr),
static_cast<int *>(output_addr), SizeToInt(output_dim0_), SizeToInt(output_dim1_));
} else if (dtype_ == kNumberTypeFloat32 && segment_ids_dtype_ == kNumberTypeInt64) {
ret1 = UnsortedSegmentSum(float, int64_t, static_cast<const float *>(input_addr), SizeToInt(unit_num_),
SizeToInt(input_dim1_), static_cast<const int64_t *>(indices_addr),
static_cast<float *>(output_addr), SizeToInt(output_dim0_), SizeToInt(output_dim1_));
ret = UnsortedSegmentSum(float, int64_t, static_cast<const float *>(input_addr), SizeToInt(unit_num_),
SizeToInt(input_dim1_), static_cast<const int64_t *>(indices_addr),
static_cast<float *>(output_addr), SizeToInt(output_dim0_), SizeToInt(output_dim1_));
} else {
MS_LOG(ERROR) << "Only support input_x int32 and float32, indices int32 and int64";
return false;
}

if (ret1 != EOK) {
MS_LOG(ERROR) << "unsortedSegmentSum failed. ret:" << ret1;
if (ret != EOK) {
MS_LOG(ERROR) << "unsortedSegmentSum failed. ret:" << ret;
return false;
}

return ret;
return true;
}
} // namespace kernel
} // namespace mindspore

+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/unsorted_segment_sum_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UNSORTED_SEGMENT_SUM_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UNSORTED_SEGMENT_SUM_CPU_KERNEL_H_

#include <vector>
#include <memory>
#include <unordered_map>


+ 9
- 12
mindspore/ccsrc/backend/kernel_compiler/cpu/update_cache_cpu_kernel.cc View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ namespace kernel {
void UpdateCacheCPUKernel::InitKernel(const CNodePtr &kernel_node) {
MS_EXCEPTION_IF_NULL(kernel_node);
node_wpt_ = kernel_node;

input_x_dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 0);
indices_dtype_ = AnfAlgo::GetInputDeviceDataType(kernel_node, 1);

@@ -44,8 +43,7 @@ bool UpdateCacheCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inputs,
} else if (indices_dtype_ == kNumberTypeInt64) {
LaunchKernel<int64_t>(inputs, outputs);
} else {
MS_LOG(ERROR) << "indices dtype only support int32, int64";
return false;
MS_LOG(EXCEPTION) << "Unsupported indices data type: " << indices_dtype_;
}
return true;
}
@@ -54,7 +52,7 @@ template <typename T>
void UpdateCacheCPUKernel::LaunchKernel(const std::vector<AddressPtr> &inputs,
const std::vector<kernel::AddressPtr> &outputs) {
auto node_ = node_wpt_.lock();
if (!node_) {
if (node_ == nullptr) {
MS_LOG(EXCEPTION) << "node_wpt_ is expired.";
}
auto indices_shape = AnfAlgo::GetPrevNodeOutputInferShape(node_, 1);
@@ -81,15 +79,14 @@ void UpdateCacheCPUKernel::LaunchKernel(const std::vector<AddressPtr> &inputs,
if (indices[i] < 0 || indices[i] >= max_num_) continue;

char *tmp = update + i * one_length_size;
if (static_cast<size_t>(indices[i]) * one_length_size + one_length_size <= max_size) {
int ret = memcpy_s(input_x + static_cast<size_t>(indices[i]) * one_length_size,
max_size - static_cast<size_t>(indices[i]) * one_length_size, tmp, one_length_size);
if (ret != 0) {
MS_LOG(EXCEPTION) << "memcpy_s error, errorno" << ret;
}
} else {
if (static_cast<size_t>(indices[i]) * one_length_size + one_length_size > max_size) {
MS_LOG(EXCEPTION) << "Memcpy out of size";
}
int ret = memcpy_s(input_x + static_cast<size_t>(indices[i]) * one_length_size,
max_size - static_cast<size_t>(indices[i]) * one_length_size, tmp, one_length_size);
if (ret != 0) {
MS_LOG(EXCEPTION) << "memcpy_s error, errorno" << ret;
}
}
}
} // namespace kernel


+ 2
- 1
mindspore/ccsrc/backend/kernel_compiler/cpu/update_cache_cpu_kernel.h View File

@@ -1,5 +1,5 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
* Copyright 2020-2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UPDATE_CACHE_CPU_KERNEL_H_
#define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_CPU_UPDATE_CACHE_CPU_KERNEL_H_



Loading…
Cancel
Save