Browse Source

supplement new master ops

tags/v1.2.0-rc1
liuyu 4 years ago
parent
commit
c777c44e80
21 changed files with 790 additions and 2 deletions
  1. +52
    -0
      mindspore/core/ops/crop_and_resize.cc
  2. +48
    -0
      mindspore/core/ops/crop_and_resize.h
  3. +28
    -0
      mindspore/core/ops/erf.cc
  4. +42
    -0
      mindspore/core/ops/erf.h
  5. +30
    -1
      mindspore/core/ops/fusion/conv2d_transpose_fusion.cc
  6. +6
    -0
      mindspore/core/ops/fusion/conv2d_transpose_fusion.h
  7. +117
    -0
      mindspore/core/ops/gru.cc
  8. +77
    -0
      mindspore/core/ops/gru.h
  9. +28
    -0
      mindspore/core/ops/if.cc
  10. +42
    -0
      mindspore/core/ops/if.h
  11. +28
    -0
      mindspore/core/ops/invert_permutation.cc
  12. +42
    -0
      mindspore/core/ops/invert_permutation.h
  13. +28
    -0
      mindspore/core/ops/non_zero.cc
  14. +42
    -0
      mindspore/core/ops/non_zero.h
  15. +11
    -0
      mindspore/core/ops/op_utils.h
  16. +46
    -0
      mindspore/core/ops/random_standard_normal.cc
  17. +50
    -0
      mindspore/core/ops/random_standard_normal.h
  18. +1
    -1
      mindspore/core/ops/resize.cc
  19. +28
    -0
      mindspore/core/ops/size.cc
  20. +42
    -0
      mindspore/core/ops/size.h
  21. +2
    -0
      mindspore/core/utils/check_convert_utils.h

+ 52
- 0
mindspore/core/ops/crop_and_resize.cc View File

@@ -0,0 +1,52 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <set>
#include <vector>
#include <memory>
#include "ops/crop_and_resize.h"
#include "utils/check_convert_utils.h"
#include "ops/op_utils.h"

namespace mindspore {
namespace ops {
void CropAndResize::Init(const ResizeMethod method, const float extrapolation_value) {
this->set_method(method);
this->set_extrapolation_value(extrapolation_value);
}

void CropAndResize::set_method(const ResizeMethod method) {
auto swi = (int64_t)method;
this->AddAttr(kMethod, MakeValue(swi));
}

void CropAndResize::set_extrapolation_value(const float extrapolation_value) {
this->AddAttr(kExtrapolationValue, MakeValue(extrapolation_value));
}

ResizeMethod CropAndResize::get_method() const {
auto value_ptr = GetAttr(kMethod);
return ResizeMethod(GetValue<int64_t>(value_ptr));
}

float CropAndResize::get_extrapolation_value() const {
auto value_ptr = GetAttr(kExtrapolationValue);
return GetValue<float>(value_ptr);
}

REGISTER_PRIMITIVE_C(kNameCropAndResize, CropAndResize);
} // namespace ops
} // namespace mindspore

+ 48
- 0
mindspore/core/ops/crop_and_resize.h View File

@@ -0,0 +1,48 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CORE_OPS_CROP_AND_RESIZE_H_
#define MINDSPORE_CORE_OPS_CROP_AND_RESIZE_H_
#include <vector>
#include <memory>
#include "ops/primitive_c.h"
#include "abstract/abstract_value.h"
#include "utils/check_convert_utils.h"

namespace mindspore {
namespace ops {
constexpr auto kNameCropAndResize = "CropAndResize";
class CropAndResize : public PrimitiveC {
public:
CropAndResize() : PrimitiveC(kNameCropAndResize) { InitIOName({"x", "boxes", "box_index", "crop_size"}, {"y"}); }
~CropAndResize() = default;
MS_DECLARE_PARENT(CropAndResize, PrimitiveC);
void Init(const ResizeMethod method, const float extrapolation_value);

void set_method(const ResizeMethod method);
void set_extrapolation_value(const float extrapolation_value);

ResizeMethod get_method() const;
float get_extrapolation_value() const;
};

AbstractBasePtr CropAndResizeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args);
using PrimCropAndResizePtr = std::shared_ptr<CropAndResize>;
} // namespace ops
} // namespace mindspore

#endif // MINDSPORE_CORE_OPS_CROP_AND_RESIZE_H_

+ 28
- 0
mindspore/core/ops/erf.cc View File

@@ -0,0 +1,28 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <set>
#include <vector>
#include <memory>
#include "ops/erf.h"
#include "utils/check_convert_utils.h"
#include "ops/op_utils.h"

namespace mindspore {
namespace ops {
REGISTER_PRIMITIVE_C(kNameErf, Erf);
} // namespace ops
} // namespace mindspore

+ 42
- 0
mindspore/core/ops/erf.h View File

@@ -0,0 +1,42 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CORE_OPS_ERF_H_
#define MINDSPORE_CORE_OPS_ERF_H_
#include <vector>
#include <memory>
#include "ops/primitive_c.h"
#include "abstract/abstract_value.h"
#include "utils/check_convert_utils.h"

namespace mindspore {
namespace ops {
constexpr auto kNameErf = "Erf";
class Erf : public PrimitiveC {
public:
Erf() : PrimitiveC(kNameErf) { InitIOName({"x"}, {"y"}); }
~Erf() = default;
MS_DECLARE_PARENT(Erf, PrimitiveC);
void Init() {}
};

AbstractBasePtr ErfInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args);
using PrimErfPtr = std::shared_ptr<Erf>;
} // namespace ops
} // namespace mindspore

#endif // MINDSPORE_CORE_OPS_ERF_H_

+ 30
- 1
mindspore/core/ops/fusion/conv2d_transpose_fusion.cc View File

@@ -23,7 +23,8 @@ void Conv2dTransposeFusion::Init(int64_t in_channel, int64_t out_channel, const
int64_t mode, const PadMode &pad_mode, const std::vector<int64_t> &pad,
const std::vector<int64_t> &stride, const std::vector<int64_t> &dilation,
int64_t group, const Format &format, const std::vector<int64_t> &pad_list,
const ActivationType activation_type) {
const std::vector<int64_t> &output_padding_h,
const std::vector<int64_t> &output_padding_w, const ActivationType activation_type) {
set_in_channel(in_channel);
set_out_channel(out_channel);
set_kernel_size(kernel_size);
@@ -35,6 +36,8 @@ void Conv2dTransposeFusion::Init(int64_t in_channel, int64_t out_channel, const
set_group(group);
set_format(format);
set_pad_list(pad_list);
set_output_padding_h(output_padding_h);
set_output_padding_w(output_padding_w);
set_activation_type(activation_type);
}

@@ -54,11 +57,37 @@ void Conv2dTransposeFusion::set_dilation(const std::vector<int64_t> &dilation) {
AddAttr(kDilation, MakeValue(dilation));
}

void Conv2dTransposeFusion::set_output_padding_h(const std::vector<int64_t> &output_padding_h) {
CheckAndConvertUtils::CheckInteger(koutputPaddingH, output_padding_h.size(), kGreaterEqual, 1, name());
for (int64_t item : output_padding_h) {
CheckAndConvertUtils::CheckInteger(koutputPaddingH, item, kGreaterEqual, 0, name());
}
AddAttr(kDilation, MakeValue(output_padding_h));
}

void Conv2dTransposeFusion::set_output_padding_w(const std::vector<int64_t> &output_padding_w) {
CheckAndConvertUtils::CheckInteger(koutputPaddingW, output_padding_w.size(), kGreaterEqual, 1, name());
for (int64_t item : output_padding_w) {
CheckAndConvertUtils::CheckInteger(koutputPaddingW, item, kGreaterEqual, 0, name());
}
AddAttr(kDilation, MakeValue(output_padding_w));
}

void Conv2dTransposeFusion::set_activation_type(const ActivationType activation_type) {
int64_t swi = activation_type;
this->AddAttr(kActivationType, MakeValue(swi));
}

std::vector<int64_t> Conv2dTransposeFusion::get_output_padding_h() const {
auto value_ptr = GetAttr(koutputPaddingH);
return GetValue<std::vector<int64_t>>(value_ptr);
}

std::vector<int64_t> Conv2dTransposeFusion::get_output_padding_w() const {
auto value_ptr = GetAttr(koutputPaddingW);
return GetValue<std::vector<int64_t>>(value_ptr);
}

ActivationType Conv2dTransposeFusion::get_activation_type() const {
auto value_ptr = GetAttr(kActivationType);
return ActivationType(GetValue<int64_t>(value_ptr));


+ 6
- 0
mindspore/core/ops/fusion/conv2d_transpose_fusion.h View File

@@ -36,10 +36,16 @@ class Conv2dTransposeFusion : public Conv2dTranspose {
const PadMode &pad_mode = VALID, const std::vector<int64_t> &pad = {0, 0, 0, 0},
const std::vector<int64_t> &stride = {1, 1}, const std::vector<int64_t> &dilation = {1, 1},
int64_t group = 1, const Format &format = NCHW, const std::vector<int64_t> &pad_list = {0, 0, 0, 0},
const std::vector<int64_t> &output_padding_h = {0}, const std::vector<int64_t> &output_padding_w = {0},
const ActivationType activation_type = NO_ACTIVATION);
void set_kernel_size(const std::vector<int64_t> &kernel_size);
void set_dilation(const std::vector<int64_t> &dilation);
void set_output_padding_h(const std::vector<int64_t> &output_padding_h);
void set_output_padding_w(const std::vector<int64_t> &output_padding_w);
void set_activation_type(const ActivationType activation_type);

std::vector<int64_t> get_output_padding_h() const;
std::vector<int64_t> get_output_padding_w() const;
ActivationType get_activation_type() const;
};
} // namespace ops


+ 117
- 0
mindspore/core/ops/gru.cc View File

@@ -0,0 +1,117 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ops/gru.h"

namespace mindspore {
namespace ops {
void GRU::Init(const bool bidirectional, const int64_t cell_depth, const float keep_prob, const float cell_clip,
const int64_t num_proj, const bool time_major, const bool reset_after, const bool is_training,
const ActivationType activation, const GateOrderMode gate_order) {
this->set_bidirectional(bidirectional);
this->set_cell_depth(cell_depth);
this->set_keep_prob(keep_prob);
this->set_cell_clip(cell_clip);
this->set_num_proj(num_proj);
this->set_time_major(time_major);
this->set_reset_after(reset_after);
this->set_is_training(is_training);
this->set_activation(activation);
this->set_gate_order(gate_order);
}

void GRU::set_bidirectional(const bool bidirectional) { AddAttr(kBidirectional, MakeValue(bidirectional)); }

void GRU::set_cell_depth(const int64_t cell_depth) { AddAttr(kCellDepth, MakeValue(cell_depth)); }

void GRU::set_keep_prob(const float keep_prob) { AddAttr(kKeepProb, MakeValue(keep_prob)); }

void GRU::set_cell_clip(const float cell_clip) { AddAttr(kCellClip, MakeValue(cell_clip)); }

void GRU::set_num_proj(const int64_t num_proj) {
CheckAndConvertUtils::CheckInteger(kNumProj, num_proj, kGreaterThan, 0, this->name());
AddAttr(kNumProj, MakeValue(num_proj));
}

void GRU::set_time_major(const bool time_major) { AddAttr(kTimeMajor, MakeValue(time_major)); }

void GRU::set_reset_after(const bool reset_after) { AddAttr(kResetAfter, MakeValue(reset_after)); }

void GRU::set_is_training(const bool is_training) { AddAttr(kIsTraining, MakeValue(is_training)); }

void GRU::set_activation(const ActivationType activation) {
int64_t swi = activation;
AddAttr(kActivation, MakeValue(swi));
}

void GRU::set_gate_order(const GateOrderMode gate_order) {
int64_t swi = gate_order;
AddAttr(kGateOrder, MakeValue(swi));
}

bool GRU::get_bidirectional() const {
auto value_ptr = this->GetAttr(kBidirectional);
return GetValue<bool>(value_ptr);
}

int64_t GRU::get_cell_depth() const {
auto value_ptr = this->GetAttr(kCellDepth);
return GetValue<int64_t>(value_ptr);
}

float GRU::get_keep_prob() const {
auto value_ptr = this->GetAttr(kKeepProb);
return GetValue<float>(value_ptr);
}

float GRU::get_cell_clip() const {
auto value_ptr = this->GetAttr(kCellClip);
return GetValue<float>(value_ptr);
}

int64_t GRU::get_num_proj() const {
auto value_ptr = this->GetAttr(kNumProj);
return GetValue<int64_t>(value_ptr);
}

bool GRU::get_time_major() const {
auto value_ptr = this->GetAttr(kTimeMajor);
return GetValue<bool>(value_ptr);
}

bool GRU::get_reset_after() const {
auto value_ptr = this->GetAttr(kResetAfter);
return GetValue<bool>(value_ptr);
}

bool GRU::get_is_training() const {
auto value_ptr = this->GetAttr(kIsTraining);
return GetValue<bool>(value_ptr);
}

ActivationType GRU::get_activation() const {
auto value_ptr = this->GetAttr(kActivation);
return ActivationType(GetValue<int64_t>(value_ptr));
}

GateOrderMode GRU::get_gate_order() const {
auto value_ptr = this->GetAttr(kGateOrder);
return GateOrderMode(GetValue<int64_t>(value_ptr));
}

REGISTER_PRIMITIVE_C(kNameGRU, GRU);
} // namespace ops
} // namespace mindspore

+ 77
- 0
mindspore/core/ops/gru.h View File

@@ -0,0 +1,77 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CORE_OPS_GRU_H_
#define MINDSPORE_CORE_OPS_GRU_H_

#include <map>
#include <vector>
#include <string>
#include <memory>
#include <algorithm>
#include "ops/op_utils.h"
#include "ops/primitive_c.h"
#include "abstract/primitive_infer_map.h"
#include "abstract/abstract_value.h"
#include "utils/check_convert_utils.h"

namespace mindspore {
namespace ops {
constexpr auto kNameGRU = "GRU";
class GRU : public PrimitiveC {
public:
GRU() : PrimitiveC(kNameGRU) {
InitIOName({"x", "weight_input", "weight_hidden", "bias_input", "bias_hidden", "seq_length", "init_h"},
{"output", "output_h", "update", "reset", "new", "hidden_new"});
}
~GRU() = default;
MS_DECLARE_PARENT(GRU, PrimitiveC);
void Init(const bool bidirectional = false, const int64_t cell_depth = 1, const float keep_prob = 1.0,
const float cell_clip = -1.0, const int64_t num_proj = 0, const bool time_major = true,
const bool reset_after = true, const bool is_training = true,
const ActivationType activation = ActivationType::TANH,
const GateOrderMode gate_order = GateOrderMode::RZH);

void set_bidirectional(const bool bidirectional);
void set_cell_depth(const int64_t cell_depth);
void set_keep_prob(const float keep_prob);
void set_cell_clip(const float cell_clip);
void set_num_proj(const int64_t num_proj);
void set_time_major(const bool time_major);
void set_reset_after(const bool reset_after);
void set_is_training(const bool is_training);
void set_activation(const ActivationType activation);
void set_gate_order(const GateOrderMode gate_order);

bool get_bidirectional() const;
int64_t get_cell_depth() const;
float get_keep_prob() const;
float get_cell_clip() const;
int64_t get_num_proj() const;
bool get_time_major() const;
bool get_reset_after() const;
bool get_is_training() const;
ActivationType get_activation() const;
GateOrderMode get_gate_order() const;
};

AbstractBasePtr GRUInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args);
using PrimGRUPtr = std::shared_ptr<GRU>;
} // namespace ops
} // namespace mindspore

#endif // MINDSPORE_CORE_OPS_GRU_H_

+ 28
- 0
mindspore/core/ops/if.cc View File

@@ -0,0 +1,28 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <set>
#include <vector>
#include <memory>
#include "ops/if.h"
#include "utils/check_convert_utils.h"
#include "ops/op_utils.h"

namespace mindspore {
namespace ops {
REGISTER_PRIMITIVE_C(kNameIf, If);
} // namespace ops
} // namespace mindspore

+ 42
- 0
mindspore/core/ops/if.h View File

@@ -0,0 +1,42 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CORE_OPS_IF_H_
#define MINDSPORE_CORE_OPS_IF_H_
#include <vector>
#include <memory>
#include "ops/primitive_c.h"
#include "abstract/abstract_value.h"
#include "utils/check_convert_utils.h"

namespace mindspore {
namespace ops {
constexpr auto kNameIf = "If";
class If : public PrimitiveC {
public:
If() : PrimitiveC(kNameIf) {}
~If() = default;
MS_DECLARE_PARENT(If, PrimitiveC);
void Init() {}
};

AbstractBasePtr IfInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args);
using PrimIfPtr = std::shared_ptr<If>;
} // namespace ops
} // namespace mindspore

#endif // MINDSPORE_CORE_OPS_IF_H_

+ 28
- 0
mindspore/core/ops/invert_permutation.cc View File

@@ -0,0 +1,28 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <set>
#include <vector>
#include <memory>
#include "ops/invert_permutation.h"
#include "utils/check_convert_utils.h"
#include "ops/op_utils.h"

namespace mindspore {
namespace ops {
REGISTER_PRIMITIVE_C(kNameInvertPermutation, InvertPermutation);
} // namespace ops
} // namespace mindspore

+ 42
- 0
mindspore/core/ops/invert_permutation.h View File

@@ -0,0 +1,42 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CORE_OPS_INVERT_PERMUTATION_H_
#define MINDSPORE_CORE_OPS_INVERT_PERMUTATION_H_
#include <vector>
#include <memory>
#include "ops/primitive_c.h"
#include "abstract/abstract_value.h"
#include "utils/check_convert_utils.h"

namespace mindspore {
namespace ops {
constexpr auto kNameInvertPermutation = "InvertPermutation";
class InvertPermutation : public PrimitiveC {
public:
InvertPermutation() : PrimitiveC(kNameInvertPermutation) {}
~InvertPermutation() = default;
MS_DECLARE_PARENT(InvertPermutation, PrimitiveC);
void Init() {}
};

AbstractBasePtr InvertPermutationInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args);
using PrimInvertPermutationPtr = std::shared_ptr<InvertPermutation>;
} // namespace ops
} // namespace mindspore

#endif // MINDSPORE_CORE_OPS_INVERT_PERMUTATION_H_

+ 28
- 0
mindspore/core/ops/non_zero.cc View File

@@ -0,0 +1,28 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <set>
#include <vector>
#include <memory>
#include "ops/non_zero.h"
#include "utils/check_convert_utils.h"
#include "ops/op_utils.h"

namespace mindspore {
namespace ops {
REGISTER_PRIMITIVE_C(kNameNonZero, NonZero);
} // namespace ops
} // namespace mindspore

+ 42
- 0
mindspore/core/ops/non_zero.h View File

@@ -0,0 +1,42 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CORE_OPS_NON_ZERO_H_
#define MINDSPORE_CORE_OPS_NON_ZERO_H_
#include <vector>
#include <memory>
#include "ops/primitive_c.h"
#include "abstract/abstract_value.h"
#include "utils/check_convert_utils.h"

namespace mindspore {
namespace ops {
constexpr auto kNameNonZero = "NonZero";
class NonZero : public PrimitiveC {
public:
NonZero() : PrimitiveC(kNameNonZero) {}
~NonZero() = default;
MS_DECLARE_PARENT(NonZero, PrimitiveC);
void Init() {}
};

AbstractBasePtr NonZeroInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args);
using PrimNonZeroPtr = std::shared_ptr<NonZero>;
} // namespace ops
} // namespace mindspore

#endif // MINDSPORE_CORE_OPS_NON_ZERO_H_

+ 11
- 0
mindspore/core/ops/op_utils.h View File

@@ -27,6 +27,7 @@
namespace mindspore {
namespace ops {
constexpr auto kAlpha = "alpha";
constexpr auto kActivation = "activation";
constexpr auto kActivationType = "activation_type";
constexpr auto kAddress = "address";
constexpr auto kAlignCorners = "align_corners";
@@ -45,6 +46,8 @@ constexpr auto kBidirectional = "bidirectional";
constexpr auto kBlockSize = "block_size";
constexpr auto kBlockShape = "block_shape";
constexpr auto kBodySubgraphIndex = "body_subgraph_index";
constexpr auto kCellClip = "cell_clip";
constexpr auto kCellDepth = "cell_depth";
constexpr auto kCenterPointBox = "center_point_box";
constexpr auto kClip = "clip";
constexpr auto kCondition = "condition";
@@ -75,6 +78,7 @@ constexpr auto kFormat = "format";
constexpr auto kFreqLowerLimit = "freq_lower_limit";
constexpr auto kFreqUpperLimit = "freq_upper_limit";
constexpr auto kFreezeBn = "freeze_bn";
constexpr auto kGateOrder = "gate_order";
constexpr auto kGlobal = "global";
constexpr auto kGrad = "grad";
constexpr auto kGradientScale = "gradient_scale";
@@ -120,6 +124,7 @@ constexpr auto kNumLayers = "num_layers";
constexpr auto kNumElements = "num_elements";
constexpr auto kNumBits = "num_bits";
constexpr auto kNumDirections = "num_directions";
constexpr auto kNumProj = "num_proj";
constexpr auto kOffset = "offset";
constexpr auto kNmsIouThreshold = "nms_iou_threshold";
constexpr auto kNmsScoreThreshold = "nms_score_threshold";
@@ -131,6 +136,8 @@ constexpr auto kOutChannel = "out_channel";
constexpr auto kOutMaxValue = "out_max_value";
constexpr auto kOutputChannel = "output_channel";
constexpr auto kOutputNum = "output_num";
constexpr auto koutputPaddingH = "outputPaddingH";
constexpr auto koutputPaddingW = "outputPaddingW";
constexpr auto kOutputType = "output_type";
constexpr auto kOutQuantized = "out_quantized";
constexpr auto kP = "p";
@@ -155,6 +162,8 @@ constexpr auto kRootRank = "root_rank";
constexpr auto kRoundMode = "round_mode";
constexpr auto kSame = "same";
constexpr auto kScale = "scale";
constexpr auto kSeed = "seed";
constexpr auto kSeed2 = "seed2";
constexpr auto kSeqDim = "seq_dim";
constexpr auto kSetattrFlag = "setattr_flag";
constexpr auto kShape = "shape";
@@ -172,6 +181,7 @@ constexpr auto kStrides = "strides";
constexpr auto kShapeType = "shape_type";
constexpr auto kSubGraphIndex = "sub_graph_index";
constexpr auto kSummarize = "summarize";
constexpr auto kTimeMajor = "time_major";
constexpr auto kTopK = "top_k";
constexpr auto kTransposeA = "transpose_a";
constexpr auto kTransposeB = "transpose_b";
@@ -213,6 +223,7 @@ constexpr auto kExcludeOutside = "exclude_outside";
constexpr auto kExtrapolationValue = "extrapolation_value";
constexpr auto kNearestMode = "nearest_mode";
constexpr auto kReduceToEnd = "reduce_to_end";
constexpr auto kResetAfter = "reset_after";
constexpr auto kCoeff = "coeff";
constexpr auto kIsDepthWise = "is_depth_wise";
constexpr auto kIsDepthWiseNative = "is_depth_wise_native";


+ 46
- 0
mindspore/core/ops/random_standard_normal.cc View File

@@ -0,0 +1,46 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ops/random_standard_normal.h"
#include <string>
#include <memory>
#include <vector>
#include "ops/op_utils.h"
#include "utils/check_convert_utils.h"

namespace mindspore {
namespace ops {
void RandomStandardNormal::Init(const int64_t seed, const int64_t seed2) {
this->set_seed(seed);
this->set_seed2(seed2);
}

void RandomStandardNormal::set_seed(const int64_t seed) { this->AddAttr(kSeed, MakeValue(seed)); }

void RandomStandardNormal::set_seed2(const int64_t seed2) { this->AddAttr(kSeed2, MakeValue(seed2)); }

bool RandomStandardNormal::get_seed() const {
auto value_ptr = GetAttr(kSeed);
return GetValue<bool>(value_ptr);
}

bool RandomStandardNormal::get_seed2() const {
auto value_ptr = GetAttr(kSeed2);
return GetValue<bool>(value_ptr);
}

REGISTER_PRIMITIVE_C(kNameRandomStandardNormal, RandomStandardNormal);
} // namespace ops
} // namespace mindspore

+ 50
- 0
mindspore/core/ops/random_standard_normal.h View File

@@ -0,0 +1,50 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CORE_OPS_RANDOM_STANDARD_NORMAL_H_
#define MINDSPORE_CORE_OPS_RANDOM_STANDARD_NORMAL_H_
#include <map>
#include <vector>
#include <string>
#include <memory>
#include "ops/primitive_c.h"
#include "abstract/abstract_value.h"
#include "utils/check_convert_utils.h"

namespace mindspore {
namespace ops {
constexpr auto kNameRandomStandardNormal = "RandomStandardNormal";
class RandomStandardNormal : public PrimitiveC {
public:
RandomStandardNormal() : PrimitiveC(kNameRandomStandardNormal) {}
~RandomStandardNormal() = default;
MS_DECLARE_PARENT(RandomStandardNormal, PrimitiveC);
void Init(const int64_t seed, const int64_t seed2);

void set_seed(const int64_t seed);
void set_seed2(const int64_t seed2);

bool get_seed() const;
bool get_seed2() const;
};

AbstractBasePtr RandomStandardNormalInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args);
using PrimRandomStandardNormalPtr = std::shared_ptr<RandomStandardNormal>;
} // namespace ops
} // namespace mindspore

#endif // MINDSPORE_CORE_OPS_RANDOM_STANDARD_NORMAL_H_

+ 1
- 1
mindspore/core/ops/resize.cc View File

@@ -118,7 +118,7 @@ int64_t Resize::get_exclude_outside() const {

float Resize::get_extrapolation_value() const {
auto value_ptr = GetAttr(kExtrapolationValue);
return GetValue<int64_t>(value_ptr);
return GetValue<float>(value_ptr);
}

NearestMode Resize::get_nearest_mode() const {


+ 28
- 0
mindspore/core/ops/size.cc View File

@@ -0,0 +1,28 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <set>
#include <vector>
#include <memory>
#include "ops/size.h"
#include "utils/check_convert_utils.h"
#include "ops/op_utils.h"

namespace mindspore {
namespace ops {
REGISTER_PRIMITIVE_C(kNameSize, Size);
} // namespace ops
} // namespace mindspore

+ 42
- 0
mindspore/core/ops/size.h View File

@@ -0,0 +1,42 @@
/**
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_CORE_OPS_SIZE_H_
#define MINDSPORE_CORE_OPS_SIZE_H_
#include <vector>
#include <memory>
#include "ops/primitive_c.h"
#include "abstract/abstract_value.h"
#include "utils/check_convert_utils.h"

namespace mindspore {
namespace ops {
constexpr auto kNameSize = "Size";
class Size : public PrimitiveC {
public:
Size() : PrimitiveC(kNameSize) {}
~Size() = default;
MS_DECLARE_PARENT(Size, PrimitiveC);
void Init() {}
};

AbstractBasePtr SizeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args);
using PrimSizePtr = std::shared_ptr<Size>;
} // namespace ops
} // namespace mindspore

#endif // MINDSPORE_CORE_OPS_SIZE_H_

+ 2
- 0
mindspore/core/utils/check_convert_utils.h View File

@@ -120,6 +120,8 @@ enum PoolMode : int64_t {
MEAN_POOLING = 1,
};

enum GateOrderMode : int64_t { RZH = 0, ZRH = 1 };

enum class LshProjectionType : int64_t { UNKNOWN = 0, SPARSE = 1, DENSE = 2 };

enum PaddingMode : int64_t { CONSTANT = 0, REFLECT = 1, SYMMETRIC = 2, MODE_RESERVED = 3 };


Loading…
Cancel
Save