diff --git a/mindspore/core/ops/crop_and_resize.cc b/mindspore/core/ops/crop_and_resize.cc new file mode 100644 index 0000000000..4daad56b1f --- /dev/null +++ b/mindspore/core/ops/crop_and_resize.cc @@ -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 +#include +#include +#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(value_ptr)); +} + +float CropAndResize::get_extrapolation_value() const { + auto value_ptr = GetAttr(kExtrapolationValue); + return GetValue(value_ptr); +} + +REGISTER_PRIMITIVE_C(kNameCropAndResize, CropAndResize); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/crop_and_resize.h b/mindspore/core/ops/crop_and_resize.h new file mode 100644 index 0000000000..f1c5025202 --- /dev/null +++ b/mindspore/core/ops/crop_and_resize.h @@ -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 +#include +#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 &input_args); +using PrimCropAndResizePtr = std::shared_ptr; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_CROP_AND_RESIZE_H_ diff --git a/mindspore/core/ops/erf.cc b/mindspore/core/ops/erf.cc new file mode 100644 index 0000000000..fdcd973024 --- /dev/null +++ b/mindspore/core/ops/erf.cc @@ -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 +#include +#include +#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 diff --git a/mindspore/core/ops/erf.h b/mindspore/core/ops/erf.h new file mode 100644 index 0000000000..166306136d --- /dev/null +++ b/mindspore/core/ops/erf.h @@ -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 +#include +#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 &input_args); +using PrimErfPtr = std::shared_ptr; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_ERF_H_ diff --git a/mindspore/core/ops/fusion/conv2d_transpose_fusion.cc b/mindspore/core/ops/fusion/conv2d_transpose_fusion.cc index db7dd32381..d367d31226 100644 --- a/mindspore/core/ops/fusion/conv2d_transpose_fusion.cc +++ b/mindspore/core/ops/fusion/conv2d_transpose_fusion.cc @@ -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 &pad, const std::vector &stride, const std::vector &dilation, int64_t group, const Format &format, const std::vector &pad_list, - const ActivationType activation_type) { + const std::vector &output_padding_h, + const std::vector &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 &dilation) { AddAttr(kDilation, MakeValue(dilation)); } +void Conv2dTransposeFusion::set_output_padding_h(const std::vector &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 &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 Conv2dTransposeFusion::get_output_padding_h() const { + auto value_ptr = GetAttr(koutputPaddingH); + return GetValue>(value_ptr); +} + +std::vector Conv2dTransposeFusion::get_output_padding_w() const { + auto value_ptr = GetAttr(koutputPaddingW); + return GetValue>(value_ptr); +} + ActivationType Conv2dTransposeFusion::get_activation_type() const { auto value_ptr = GetAttr(kActivationType); return ActivationType(GetValue(value_ptr)); diff --git a/mindspore/core/ops/fusion/conv2d_transpose_fusion.h b/mindspore/core/ops/fusion/conv2d_transpose_fusion.h index 6388212425..a9a761d491 100644 --- a/mindspore/core/ops/fusion/conv2d_transpose_fusion.h +++ b/mindspore/core/ops/fusion/conv2d_transpose_fusion.h @@ -36,10 +36,16 @@ class Conv2dTransposeFusion : public Conv2dTranspose { const PadMode &pad_mode = VALID, const std::vector &pad = {0, 0, 0, 0}, const std::vector &stride = {1, 1}, const std::vector &dilation = {1, 1}, int64_t group = 1, const Format &format = NCHW, const std::vector &pad_list = {0, 0, 0, 0}, + const std::vector &output_padding_h = {0}, const std::vector &output_padding_w = {0}, const ActivationType activation_type = NO_ACTIVATION); void set_kernel_size(const std::vector &kernel_size); void set_dilation(const std::vector &dilation); + void set_output_padding_h(const std::vector &output_padding_h); + void set_output_padding_w(const std::vector &output_padding_w); void set_activation_type(const ActivationType activation_type); + + std::vector get_output_padding_h() const; + std::vector get_output_padding_w() const; ActivationType get_activation_type() const; }; } // namespace ops diff --git a/mindspore/core/ops/gru.cc b/mindspore/core/ops/gru.cc new file mode 100644 index 0000000000..42258d88de --- /dev/null +++ b/mindspore/core/ops/gru.cc @@ -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(value_ptr); +} + +int64_t GRU::get_cell_depth() const { + auto value_ptr = this->GetAttr(kCellDepth); + return GetValue(value_ptr); +} + +float GRU::get_keep_prob() const { + auto value_ptr = this->GetAttr(kKeepProb); + return GetValue(value_ptr); +} + +float GRU::get_cell_clip() const { + auto value_ptr = this->GetAttr(kCellClip); + return GetValue(value_ptr); +} + +int64_t GRU::get_num_proj() const { + auto value_ptr = this->GetAttr(kNumProj); + return GetValue(value_ptr); +} + +bool GRU::get_time_major() const { + auto value_ptr = this->GetAttr(kTimeMajor); + return GetValue(value_ptr); +} + +bool GRU::get_reset_after() const { + auto value_ptr = this->GetAttr(kResetAfter); + return GetValue(value_ptr); +} + +bool GRU::get_is_training() const { + auto value_ptr = this->GetAttr(kIsTraining); + return GetValue(value_ptr); +} + +ActivationType GRU::get_activation() const { + auto value_ptr = this->GetAttr(kActivation); + return ActivationType(GetValue(value_ptr)); +} + +GateOrderMode GRU::get_gate_order() const { + auto value_ptr = this->GetAttr(kGateOrder); + return GateOrderMode(GetValue(value_ptr)); +} + +REGISTER_PRIMITIVE_C(kNameGRU, GRU); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/gru.h b/mindspore/core/ops/gru.h new file mode 100644 index 0000000000..74243e5f72 --- /dev/null +++ b/mindspore/core/ops/gru.h @@ -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 +#include +#include +#include +#include +#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 &input_args); +using PrimGRUPtr = std::shared_ptr; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_GRU_H_ diff --git a/mindspore/core/ops/if.cc b/mindspore/core/ops/if.cc new file mode 100644 index 0000000000..a0b6cb0f6f --- /dev/null +++ b/mindspore/core/ops/if.cc @@ -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 +#include +#include +#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 diff --git a/mindspore/core/ops/if.h b/mindspore/core/ops/if.h new file mode 100644 index 0000000000..c19a032882 --- /dev/null +++ b/mindspore/core/ops/if.h @@ -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 +#include +#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 &input_args); +using PrimIfPtr = std::shared_ptr; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_IF_H_ diff --git a/mindspore/core/ops/invert_permutation.cc b/mindspore/core/ops/invert_permutation.cc new file mode 100644 index 0000000000..cfb331e48f --- /dev/null +++ b/mindspore/core/ops/invert_permutation.cc @@ -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 +#include +#include +#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 diff --git a/mindspore/core/ops/invert_permutation.h b/mindspore/core/ops/invert_permutation.h new file mode 100644 index 0000000000..63c9d7613f --- /dev/null +++ b/mindspore/core/ops/invert_permutation.h @@ -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 +#include +#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 &input_args); +using PrimInvertPermutationPtr = std::shared_ptr; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_INVERT_PERMUTATION_H_ diff --git a/mindspore/core/ops/non_zero.cc b/mindspore/core/ops/non_zero.cc new file mode 100644 index 0000000000..b0bce4fc3c --- /dev/null +++ b/mindspore/core/ops/non_zero.cc @@ -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 +#include +#include +#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 diff --git a/mindspore/core/ops/non_zero.h b/mindspore/core/ops/non_zero.h new file mode 100644 index 0000000000..09104b6a94 --- /dev/null +++ b/mindspore/core/ops/non_zero.h @@ -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 +#include +#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 &input_args); +using PrimNonZeroPtr = std::shared_ptr; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_NON_ZERO_H_ diff --git a/mindspore/core/ops/op_utils.h b/mindspore/core/ops/op_utils.h index 8ebc43194b..3902e73e35 100644 --- a/mindspore/core/ops/op_utils.h +++ b/mindspore/core/ops/op_utils.h @@ -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"; diff --git a/mindspore/core/ops/random_standard_normal.cc b/mindspore/core/ops/random_standard_normal.cc new file mode 100644 index 0000000000..8772100b70 --- /dev/null +++ b/mindspore/core/ops/random_standard_normal.cc @@ -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 +#include +#include +#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(value_ptr); +} + +bool RandomStandardNormal::get_seed2() const { + auto value_ptr = GetAttr(kSeed2); + return GetValue(value_ptr); +} + +REGISTER_PRIMITIVE_C(kNameRandomStandardNormal, RandomStandardNormal); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/random_standard_normal.h b/mindspore/core/ops/random_standard_normal.h new file mode 100644 index 0000000000..de0f91abf7 --- /dev/null +++ b/mindspore/core/ops/random_standard_normal.h @@ -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 +#include +#include +#include +#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 &input_args); +using PrimRandomStandardNormalPtr = std::shared_ptr; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_RANDOM_STANDARD_NORMAL_H_ diff --git a/mindspore/core/ops/resize.cc b/mindspore/core/ops/resize.cc index 7af3f9aff6..f49acd71a1 100644 --- a/mindspore/core/ops/resize.cc +++ b/mindspore/core/ops/resize.cc @@ -118,7 +118,7 @@ int64_t Resize::get_exclude_outside() const { float Resize::get_extrapolation_value() const { auto value_ptr = GetAttr(kExtrapolationValue); - return GetValue(value_ptr); + return GetValue(value_ptr); } NearestMode Resize::get_nearest_mode() const { diff --git a/mindspore/core/ops/size.cc b/mindspore/core/ops/size.cc new file mode 100644 index 0000000000..4ff90a5b3e --- /dev/null +++ b/mindspore/core/ops/size.cc @@ -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 +#include +#include +#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 diff --git a/mindspore/core/ops/size.h b/mindspore/core/ops/size.h new file mode 100644 index 0000000000..be7b2315ea --- /dev/null +++ b/mindspore/core/ops/size.h @@ -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 +#include +#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 &input_args); +using PrimSizePtr = std::shared_ptr; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_SIZE_H_ diff --git a/mindspore/core/utils/check_convert_utils.h b/mindspore/core/utils/check_convert_utils.h index 758d55f8cc..4ad2a99c02 100644 --- a/mindspore/core/utils/check_convert_utils.h +++ b/mindspore/core/utils/check_convert_utils.h @@ -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 };