diff --git a/mindspore/core/base/core_ops.h b/mindspore/core/base/core_ops.h index 706f1efe59..8f433a324c 100644 --- a/mindspore/core/base/core_ops.h +++ b/mindspore/core/base/core_ops.h @@ -125,7 +125,7 @@ inline const PrimitivePtr kPrimSequenceMask = std::make_shared("Seque // NN inline const PrimitivePtr kPrimFlatten = std::make_shared("Flatten"); -inline const PrimitivePtr kPrimSoftmax = std::make_shared("Softmax"); +inline const PrimitivePtr kPrimSoftMax = std::make_shared("SoftMax"); inline const PrimitivePtr kPrimLogSoftmax = std::make_shared("LogSoftmax"); inline const PrimitivePtr kPrimLogSoftmaxGrad = std::make_shared("LogSoftmaxGrad"); inline const PrimitivePtr kPrimTanh = std::make_shared("Tanh"); diff --git a/mindspore/core/c_ops/abs.cc b/mindspore/core/c_ops/abs.cc new file mode 100644 index 0000000000..df65c135dd --- /dev/null +++ b/mindspore/core/c_ops/abs.cc @@ -0,0 +1,19 @@ +/** + * 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 "c_ops/abs.h" +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameAbs, Abs); +} // namespace mindspore diff --git a/mindspore/core/c_ops/abs.h b/mindspore/core/c_ops/abs.h new file mode 100644 index 0000000000..1c9e72e41b --- /dev/null +++ b/mindspore/core/c_ops/abs.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_ABS_H_ +#define MINDSPORE_CORE_C_OPS_ABS_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameAbs = "Abs"; +class Abs : public PrimitiveC { + public: + Abs() : PrimitiveC(kNameAbs) { InitIOName({"input_x"}, {"output"}); } + ~Abs() = default; + MS_DECLARE_PARENT(Abs, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_ABS_H_ diff --git a/mindspore/core/c_ops/adam.cc b/mindspore/core/c_ops/adam.cc new file mode 100644 index 0000000000..315505285c --- /dev/null +++ b/mindspore/core/c_ops/adam.cc @@ -0,0 +1,40 @@ +/** + * 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 "c_ops/adam.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +void Adam::set_use_locking(const bool &use_locking) { this->AddAttr(kUseLocking, MakeValue(use_locking)); } + +bool Adam::get_use_locking() const { + auto value_ptr = GetAttr(kUseLocking); + return GetValue(value_ptr); +} + +void Adam::set_use_nesteroy(const bool &use_nesteroy) { this->AddAttr(kUseNesteroy, MakeValue(use_nesteroy)); } + +bool Adam::get_use_nesteroy() const { + auto value_ptr = GetAttr(kUseNesteroy); + return GetValue(value_ptr); +} +void Adam::Init(const bool &use_locking, const bool &use_nesteroy) { + this->set_use_locking(use_locking); + this->set_use_nesteroy(use_nesteroy); +} +REGISTER_PRIMITIVE_C(kNameAdam, Adam); +} // namespace mindspore diff --git a/mindspore/core/c_ops/adam.h b/mindspore/core/c_ops/adam.h new file mode 100644 index 0000000000..89d25d167c --- /dev/null +++ b/mindspore/core/c_ops/adam.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_C_OPS_ADAM_H_ +#define MINDSPORE_CORE_C_OPS_ADAM_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameAdam = "Adam"; +class Adam : public PrimitiveC { + public: + Adam() : PrimitiveC(kNameAdam) {} + ~Adam() = default; + MS_DECLARE_PARENT(Adam, PrimitiveC); + void Init(const bool &use_locking = false, const bool &use_nesteroy = false); + void set_use_locking(const bool &use_locking); + void set_use_nesteroy(const bool &use_nesteroy); + bool get_use_locking() const; + bool get_use_nesteroy() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_ADAM_H_ diff --git a/mindspore/core/c_ops/add.cc b/mindspore/core/c_ops/add.cc index 66aa7b86f3..e3b3eca615 100644 --- a/mindspore/core/c_ops/add.cc +++ b/mindspore/core/c_ops/add.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -15,19 +15,18 @@ */ #include "c_ops/add.h" -#include #include #include -#include #include #include "c_ops/op_utils.h" #include "utils/check_convert_utils.h" #include "abstract/primitive_infer_map.h" namespace mindspore { +namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - auto add_prim = primitive->cast(); + auto add_prim = primitive->cast(); MS_EXCEPTION_IF_NULL(add_prim); auto op_name = add_prim->name(); return BroadCastInferShape(op_name, input_args); @@ -43,12 +42,13 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & auto infer_type = CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim->name()); return TypeIdToType(infer_type); } +} // namespace -AbstractBasePtr TensorAddInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { +AbstractBasePtr AddInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args) { return std::make_shared(InferType(primitive, input_args), InferShape(primitive, input_args)->shape()); } -REGISTER_PRIMITIVE_EVAL_IMPL(TensorAdd, prim::kPrimTensorAdd, TensorAddInfer); -REGISTER_PRIMITIVE_C(kNameTensorAdd, TensorAdd); +REGISTER_PRIMITIVE_EVAL_IMPL(Add, prim::kPrimTensorAdd, AddInfer); +REGISTER_PRIMITIVE_C(kNameAdd, Add); } // namespace mindspore diff --git a/mindspore/core/c_ops/add.h b/mindspore/core/c_ops/add.h index 3921d33d72..be4528a5f9 100644 --- a/mindspore/core/c_ops/add.h +++ b/mindspore/core/c_ops/add.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -25,18 +25,18 @@ #include "utils/check_convert_utils.h" namespace mindspore { -constexpr auto kNameTensorAdd = "TensorAdd"; -class TensorAdd : public PrimitiveC { +constexpr auto kNameAdd = "Add"; +class Add : public PrimitiveC { public: - TensorAdd() : PrimitiveC(kNameTensorAdd) { InitIOName({"x", "y"}, {"output"}); } - ~TensorAdd() = default; - MS_DECLARE_PARENT(TensorAdd, PrimitiveC); + Add() : PrimitiveC(kNameAdd) { InitIOName({"x", "y"}, {"output"}); } + ~Add() = default; + MS_DECLARE_PARENT(Add, PrimitiveC); void Init() {} }; -AbstractBasePtr TensorAddInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args); -using PrimTensorAddPtr = std::shared_ptr; +AbstractBasePtr AddInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimAddPtr = std::shared_ptr; } // namespace mindspore #endif // MINDSPORE_CORE_C_OPS_ADD_H_ diff --git a/mindspore/core/c_ops/add_fold.cc b/mindspore/core/c_ops/add_fold.cc new file mode 100644 index 0000000000..e24fff7d03 --- /dev/null +++ b/mindspore/core/c_ops/add_fold.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/add_fold.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameAddFold, AddFold); +} // namespace mindspore diff --git a/mindspore/core/c_ops/add_fold.h b/mindspore/core/c_ops/add_fold.h new file mode 100644 index 0000000000..8f0f5c9397 --- /dev/null +++ b/mindspore/core/c_ops/add_fold.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_ADDFOLD_H_ +#define MINDSPORE_CORE_C_OPS_ADDFOLD_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameAddFold = "AddFold"; +class AddFold : public PrimitiveC { + public: + AddFold() : PrimitiveC(kNameAddFold) {} + ~AddFold() = default; + MS_DECLARE_PARENT(AddFold, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_ADDFOLD_H_ diff --git a/mindspore/core/c_ops/addn.cc b/mindspore/core/c_ops/addn.cc new file mode 100644 index 0000000000..b8071c5c8c --- /dev/null +++ b/mindspore/core/c_ops/addn.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/addn.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameAddN, AddN); +} // namespace mindspore diff --git a/mindspore/core/c_ops/addn.h b/mindspore/core/c_ops/addn.h new file mode 100644 index 0000000000..2a171ae06b --- /dev/null +++ b/mindspore/core/c_ops/addn.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_ADDN_H_ +#define MINDSPORE_CORE_C_OPS_ADDN_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameAddN = "AddN"; +class AddN : public PrimitiveC { + public: + AddN() : PrimitiveC(kNameAddN) { InitIOName({"inputs"}, {"sum"}); } + ~AddN() = default; + MS_DECLARE_PARENT(AddN, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_ADDN_H_ diff --git a/mindspore/core/c_ops/apply_momentum.cc b/mindspore/core/c_ops/apply_momentum.cc new file mode 100644 index 0000000000..5b5da739be --- /dev/null +++ b/mindspore/core/c_ops/apply_momentum.cc @@ -0,0 +1,51 @@ +/** + * 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 "c_ops/apply_momentum.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +void ApplyMomentum::Init(bool use_nesterov, bool use_locking, float gradient_scale) { + this->set_use_nesterov(use_nesterov); + this->set_use_locking(use_locking); + this->set_gradient_scale(gradient_scale); +} + +void ApplyMomentum::set_use_nesterov(bool use_nesterov) { this->AddAttr(kUseNesterov, MakeValue(use_nesterov)); } + +void ApplyMomentum::set_use_locking(bool use_locking) { this->AddAttr(kUseLocking, MakeValue(use_locking)); } + +void ApplyMomentum::set_gradient_scale(float gradient_scale) { + this->AddAttr(kGradientScale, MakeValue(gradient_scale)); +} + +bool ApplyMomentum::get_use_nesterov() const { + auto value_ptr = GetAttr(kUseNesterov); + return GetValue(value_ptr); +} + +bool ApplyMomentum::get_use_locking() const { + auto value_ptr = GetAttr(kUseLocking); + return GetValue(value_ptr); +} + +float ApplyMomentum::get_gradient_scale() { + auto value_ptr = GetAttr(kGradientScale); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameApplyMomentum, ApplyMomentum); +} // namespace mindspore diff --git a/mindspore/core/c_ops/apply_momentum.h b/mindspore/core/c_ops/apply_momentum.h new file mode 100644 index 0000000000..c14cfc2479 --- /dev/null +++ b/mindspore/core/c_ops/apply_momentum.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_C_OPS_APPLYMOMENTUM_H_ +#define MINDSPORE_CORE_C_OPS_APPLYMOMENTUM_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameApplyMomentum = "ApplyMomentum"; +class ApplyMomentum : public PrimitiveC { + public: + ApplyMomentum() : PrimitiveC(kNameApplyMomentum) { + InitIOName({"variable", "accumulation", "learning_rate", "gradient", "momentum"}, {"output"}); + } + ~ApplyMomentum() = default; + MS_DECLARE_PARENT(ApplyMomentum, PrimitiveC); + void Init(bool use_nesterov, bool use_locking, float gradient_scale); + void set_use_nesterov(bool use_nesterov); + void set_use_locking(bool use_locking); + void set_gradient_scale(float gradient_scale); + bool get_use_nesterov() const; + bool get_use_locking() const; + float get_gradient_scale(); +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_APPLYMOMENTUM_H_ diff --git a/mindspore/core/c_ops/arg_min.cc b/mindspore/core/c_ops/arg_min.cc new file mode 100644 index 0000000000..b7f112cae8 --- /dev/null +++ b/mindspore/core/c_ops/arg_min.cc @@ -0,0 +1,38 @@ +/** + * 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 "c_ops/arg_min.h" + +namespace mindspore { +void ArgMin::Init(bool keep_dims, int64_t axis) { + set_axis(axis); + set_keep_dims(keep_dims); +} + +void ArgMin::set_axis(int64_t axis) { this->AddAttr(kAxis, MakeValue(axis)); } +void ArgMin::set_keep_dims(bool keep_dims) { this->AddAttr(kOutputType, MakeValue(keep_dims)); } + +int64_t ArgMin::get_axis() { + auto value_ptr = GetAttr(kAxis); + return GetValue(value_ptr); +} + +bool ArgMin::get_keep_dims() { + auto value_ptr = GetAttr(kKeepDims); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameArgMin, ArgMin); +} // namespace mindspore diff --git a/mindspore/core/c_ops/arg_min.h b/mindspore/core/c_ops/arg_min.h new file mode 100644 index 0000000000..622ebc024b --- /dev/null +++ b/mindspore/core/c_ops/arg_min.h @@ -0,0 +1,45 @@ +/** + * 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_C_OPS_ARGMIN_H_ +#define MINDSPORE_CORE_C_OPS_ARGMIN_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameArgMin = "ArgMin"; +class ArgMin : public PrimitiveC { + public: + ArgMin() : PrimitiveC(kNameArgMin) { InitIOName({"x"}, {"output"}); } + ~ArgMin() = default; + MS_DECLARE_PARENT(ArgMin, PrimitiveC); + void Init(bool keep_dims, int64_t axis = -1); + void set_axis(int64_t axis); + void set_keep_dims(bool keep_dims); + int64_t get_axis(); + bool get_keep_dims(); +}; +AbstractBasePtr ArgMinInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimArgMin = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_ARGMIN_H_ diff --git a/mindspore/core/c_ops/asin.cc b/mindspore/core/c_ops/asin.cc new file mode 100644 index 0000000000..a2e228e0dc --- /dev/null +++ b/mindspore/core/c_ops/asin.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/asin.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameAsin, Asin); +} // namespace mindspore diff --git a/mindspore/core/c_ops/asin.h b/mindspore/core/c_ops/asin.h new file mode 100644 index 0000000000..53bb610c88 --- /dev/null +++ b/mindspore/core/c_ops/asin.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_ASIN_H_ +#define MINDSPORE_CORE_C_OPS_ASIN_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameAsin = "Asin"; +class Asin : public PrimitiveC { + public: + Asin() : PrimitiveC(kNameAsin) {} + ~Asin() = default; + MS_DECLARE_PARENT(Asin, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_ASIN_H_ diff --git a/mindspore/core/c_ops/assign.cc b/mindspore/core/c_ops/assign.cc new file mode 100644 index 0000000000..4ea267ac54 --- /dev/null +++ b/mindspore/core/c_ops/assign.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/assign.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameAssign, Assign); +} // namespace mindspore diff --git a/mindspore/core/c_ops/assign.h b/mindspore/core/c_ops/assign.h new file mode 100644 index 0000000000..87b5f0761e --- /dev/null +++ b/mindspore/core/c_ops/assign.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_ASSIGN_H_ +#define MINDSPORE_CORE_C_OPS_ASSIGN_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameAssign = "Assign"; +class Assign : public PrimitiveC { + public: + Assign() : PrimitiveC(kNameAssign) { InitIOName({"ref", "value"}, {"output"}); } + ~Assign() = default; + MS_DECLARE_PARENT(Assign, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_ASSIGN_H_ diff --git a/mindspore/core/c_ops/assign_add.cc b/mindspore/core/c_ops/assign_add.cc new file mode 100644 index 0000000000..0810b2cc85 --- /dev/null +++ b/mindspore/core/c_ops/assign_add.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/assign_add.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameAssignAdd, AssignAdd); +} // namespace mindspore diff --git a/mindspore/core/c_ops/assign_add.h b/mindspore/core/c_ops/assign_add.h new file mode 100644 index 0000000000..b6713a6662 --- /dev/null +++ b/mindspore/core/c_ops/assign_add.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_ASSIGNADD_H_ +#define MINDSPORE_CORE_C_OPS_ASSIGNADD_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameAssignAdd = "AssignAdd"; +class AssignAdd : public PrimitiveC { + public: + AssignAdd() : PrimitiveC(kNameAssignAdd) { InitIOName({"ref", "value"}, {"output"}); } + ~AssignAdd() = default; + MS_DECLARE_PARENT(AssignAdd, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_ASSIGNADD_H_ diff --git a/mindspore/core/c_ops/atan.cc b/mindspore/core/c_ops/atan.cc new file mode 100644 index 0000000000..97f56784d2 --- /dev/null +++ b/mindspore/core/c_ops/atan.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/atan.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameAtan, Atan); +} // namespace mindspore diff --git a/mindspore/core/c_ops/atan.h b/mindspore/core/c_ops/atan.h new file mode 100644 index 0000000000..ea670a813f --- /dev/null +++ b/mindspore/core/c_ops/atan.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_ATAN_H_ +#define MINDSPORE_CORE_C_OPS_ATAN_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameAtan = "Atan"; +class Atan : public PrimitiveC { + public: + Atan() : PrimitiveC(kNameAtan) {} + ~Atan() = default; + MS_DECLARE_PARENT(Atan, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_ATAN_H_ diff --git a/mindspore/core/c_ops/audio_spectrogram.cc b/mindspore/core/c_ops/audio_spectrogram.cc new file mode 100644 index 0000000000..f9a30c58c3 --- /dev/null +++ b/mindspore/core/c_ops/audio_spectrogram.cc @@ -0,0 +1,54 @@ +/** + * 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 "c_ops/audio_spectrogram.h" +#include +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { + +void AudioSpectrogram::set_window_size(const int64_t &window_size) { + this->AddAttr(kWindowSize, MakeValue(window_size)); +} +int64_t AudioSpectrogram::get_window_size() const { + auto value_ptr = GetAttr(kWindowSize); + return GetValue(value_ptr); +} + +void AudioSpectrogram::set_stride(const int64_t &stride) { this->AddAttr(kStride, MakeValue(stride)); } +int64_t AudioSpectrogram::get_stride() const { + auto value_ptr = GetAttr(kStride); + return GetValue(value_ptr); +} + +void AudioSpectrogram::set_mag_square(const bool &mag_square) { this->AddAttr(kMagSquare, MakeValue(mag_square)); } +bool AudioSpectrogram::get_mag_square() const { + auto value_ptr = GetAttr(kMagSquare); + return GetValue(value_ptr); +} +void AudioSpectrogram::Init(const int64_t &window_size, const int64_t &stride, const bool &mag_square) { + this->set_window_size(window_size); + this->set_stride(stride); + this->set_mag_square(mag_square); +} +REGISTER_PRIMITIVE_C(kNameAudioSpectrogram, AudioSpectrogram); +} // namespace mindspore diff --git a/mindspore/core/c_ops/audio_spectrogram.h b/mindspore/core/c_ops/audio_spectrogram.h new file mode 100644 index 0000000000..54059385ba --- /dev/null +++ b/mindspore/core/c_ops/audio_spectrogram.h @@ -0,0 +1,44 @@ +/** + * 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_C_OPS_AUDIOSPECTROGRAM_H_ +#define MINDSPORE_CORE_C_OPS_AUDIOSPECTROGRAM_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameAudioSpectrogram = "AudioSpectrogram"; +class AudioSpectrogram : public PrimitiveC { + public: + AudioSpectrogram() : PrimitiveC(kNameAudioSpectrogram) {} + ~AudioSpectrogram() = default; + MS_DECLARE_PARENT(AudioSpectrogram, PrimitiveC); + void Init(const int64_t &window_size, const int64_t &stride, const bool &mag_square); + void set_window_size(const int64_t &window_size); + void set_stride(const int64_t &stride); + void set_mag_square(const bool &mag_square); + int64_t get_window_size() const; + int64_t get_stride() const; + bool get_mag_square() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_AUDIOSPECTROGRAM_H_ diff --git a/mindspore/core/c_ops/avg_pool.cc b/mindspore/core/c_ops/avg_pool.cc index a13aca7773..a6cd65defc 100644 --- a/mindspore/core/c_ops/avg_pool.cc +++ b/mindspore/core/c_ops/avg_pool.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "c_ops/avg_pool.h" #include #include @@ -24,36 +25,73 @@ #include "abstract/primitive_infer_map.h" namespace mindspore { -void AvgPool::set_padding(const std::string &pad) { this->AddAttr("padding", MakeValue(pad)); } +void AvgPool::set_padding(const std::string &padding) { + CheckAndConvertUtils::CheckString(kPadding, padding, {kValid, kSame}, this->name()); + this->AddAttr(kPadding, MakeValue(padding)); +} std::string AvgPool::get_padding() const { - auto value_ptr = GetAttr("padding"); + auto value_ptr = GetAttr(kPadding); return GetValue(value_ptr); } void AvgPool::set_kernel_size(const std::vector &kernel_size) { - this->AddAttr("k_size", MakeValue(kernel_size)); + this->AddAttr(kKernelSize, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kKernelSize, kernel_size, this->name(), + false, true))); } std::vector AvgPool::get_kernel_size() const { - auto value_ptr = GetAttr("k_size"); + auto value_ptr = GetAttr(kKernelSize); return GetValue>(value_ptr); } -void AvgPool::set_strides(const std::vector &strides) { this->AddAttr("strides", MakeValue(strides)); } +void AvgPool::set_strides(const std::vector &strides) { + this->AddAttr(kStride, + MakeValue(CheckAndConvertUtils::CheckPositiveVector(kStride, strides, this->name(), false, true))); +} std::vector AvgPool::get_strides() const { - auto value_ptr = GetAttr("strides"); + auto value_ptr = GetAttr(kStride); return GetValue>(value_ptr); } +void AvgPool::set_format(const Format &format) { + int64_t f = format; + this->AddAttr(kFormat, MakeValue(f)); +} + +Format AvgPool::get_format() const { + auto value_ptr = GetAttr(kFormat); + return Format(GetValue(value_ptr)); +} + +void AvgPool::set_pad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } + +std::vector AvgPool::get_pad() const { + auto value_ptr = GetAttr(kPad); + return GetValue>(value_ptr); +} + +void AvgPool::set_round_mode(const int64_t &round_mode) { + CheckAndConvertUtils::CheckInRange(kRoundMode, round_mode, kIncludeBoth, {0, 1}, this->name()); + this->AddAttr(kRoundMode, MakeValue(round_mode)); +} + +int64_t AvgPool::get_round_mode() const { + auto value_ptr = GetAttr(kRoundMode); + return GetValue(value_ptr); +} + void AvgPool::Init(const std::vector &kernel_size, const std::vector &stride, - const std::string &padding) { - auto prim_name = this->name(); - this->AddAttr("data_format", MakeValue("NCHW")); - this->set_padding(CheckAndConvertUtils::CheckString("padding", padding, {"valid", "same"}, prim_name)); - this->set_kernel_size(CheckAndConvertUtils::CheckPositiveVector("k_size", kernel_size, prim_name, false, true)); - this->set_strides(CheckAndConvertUtils::CheckPositiveVector("strides", stride, this->name(), false, true)); + const std::string &padding, const Format &format, const std::vector &pad, + const int64_t &round_mode) { + this->set_padding(padding); + this->set_kernel_size(kernel_size); + this->set_strides(stride); + this->set_format(format); + this->set_pad(pad); + this->set_round_mode(round_mode); } +namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto pool_prim = primitive->cast(); @@ -83,7 +121,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector out_shape = {batch, channel, out_h, out_w}; - if (std::any_of(out_shape.begin(), out_shape.end(), [](int a) { return a <= 0; })) { + if (std::any_of(out_shape.begin(), out_shape.end(), [](int64_t a) { return a <= 0; })) { MS_LOG(EXCEPTION) << "Kernel size is not valid."; } return std::make_shared(out_shape); @@ -95,6 +133,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & } return input_args[0]->BuildType(); } +} // namespace AbstractBasePtr AvgPoolInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { diff --git a/mindspore/core/c_ops/avg_pool.h b/mindspore/core/c_ops/avg_pool.h index 372c2037f4..866f3927da 100644 --- a/mindspore/core/c_ops/avg_pool.h +++ b/mindspore/core/c_ops/avg_pool.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -33,13 +33,21 @@ class AvgPool : public PrimitiveC { ~AvgPool() = default; MS_DECLARE_PARENT(AvgPool, PrimitiveC); void Init(const std::vector &kernel_size = {1}, const std::vector &stride = {1}, - const std::string &padding = "valid"); - void set_padding(const std::string &pad); + const std::string &padding = "valid", const Format &format = NCHW, + const std::vector &pad = {0, 0, 0, 0}, const int64_t &round_mode = 0); + void set_padding(const std::string &padding); void set_kernel_size(const std::vector &kernel_size); void set_strides(const std::vector &strides); + void set_format(const Format &format); + void set_pad(const std::vector &pad); + void set_round_mode(const int64_t &round_mode); + std::vector get_kernel_size() const; std::vector get_strides() const; std::string get_padding() const; + Format get_format() const; + std::vector get_pad() const; + int64_t get_round_mode() const; }; AbstractBasePtr AvgPoolInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, diff --git a/mindspore/core/c_ops/batch_norm.cc b/mindspore/core/c_ops/batch_norm.cc new file mode 100644 index 0000000000..de912feb42 --- /dev/null +++ b/mindspore/core/c_ops/batch_norm.cc @@ -0,0 +1,59 @@ +/** + * 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 +#include +#include "c_ops/batch_norm.h" +#include "abstract/primitive_infer_map.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +void BatchNorm::Init(bool is_training, float epsilon, const Format &format) { + set_is_training(is_training); + set_epsilon(epsilon); + set_format(format); +} + +void BatchNorm::set_is_training(bool is_training) { this->AddAttr(kIsTraining, MakeValue(is_training)); } + +void BatchNorm::set_epsilon(float epsilon) { + CheckAndConvertUtils::CheckInRange(kEpsilon, epsilon, kIncludeBoth, {0.0, 1.0}, this->name()); + this->AddAttr(kEpsilon, MakeValue(epsilon)); +} + +void BatchNorm::set_format(const Format &format) { + int64_t f = format; + this->AddAttr(kFormat, MakeValue(f)); +} + +bool BatchNorm::get_is_trainging() { + auto value_ptr = GetAttr(kIsTraining); + return GetValue(value_ptr); +} + +float BatchNorm::get_epsilon() { + auto value_ptr = GetAttr(kEpsilon); + return GetValue(value_ptr); +} + +Format BatchNorm::get_format() const { + auto value_ptr = GetAttr(kFormat); + return Format(GetValue(value_ptr)); +} +REGISTER_PRIMITIVE_C(kNameBatchNorm, BatchNorm); +} // namespace mindspore diff --git a/mindspore/core/c_ops/batch_norm.h b/mindspore/core/c_ops/batch_norm.h new file mode 100644 index 0000000000..2aa093a216 --- /dev/null +++ b/mindspore/core/c_ops/batch_norm.h @@ -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. + */ + +#ifndef MINDSPORE_CORE_C_OPS_BATCH_NORMAL_H_ +#define MINDSPORE_CORE_C_OPS_BATCH_NORMAL_H_ +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" + +namespace mindspore { +constexpr auto kNameBatchNorm = "BatchNorm"; +class BatchNorm : public PrimitiveC { + public: + BatchNorm() : PrimitiveC(kNameBatchNorm) { + InitIOName({"x", "scale", "offset", "mean", "variance"}, + {"y", "batch_mean", "batch_variance", "reserve_space_1", "reserve_space_2"}); + } + ~BatchNorm() = default; + MS_DECLARE_PARENT(BatchNorm, PrimitiveC); + void Init(bool is_training = false, float epsilon = 1e-5, const Format &format = NCHW); + void set_is_training(bool is_training); + void set_epsilon(float epsilon); + void set_format(const Format &format); + bool get_is_trainging(); + float get_epsilon(); + Format get_format() const; +}; + +AbstractBasePtr BatchNormInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimBatchNormPtr = std::shared_ptr; + +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_BatchNorm_H_ diff --git a/mindspore/core/c_ops/batch_norm_fold.cc b/mindspore/core/c_ops/batch_norm_fold.cc new file mode 100644 index 0000000000..df6483f50c --- /dev/null +++ b/mindspore/core/c_ops/batch_norm_fold.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/batch_norm_fold.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameBatchNormFold, BatchNormFold); +} // namespace mindspore diff --git a/mindspore/core/c_ops/batch_norm_fold.h b/mindspore/core/c_ops/batch_norm_fold.h new file mode 100644 index 0000000000..db0fa14970 --- /dev/null +++ b/mindspore/core/c_ops/batch_norm_fold.h @@ -0,0 +1,37 @@ +/** + * 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_C_OPS_BATCHNORMFOLD_H_ +#define MINDSPORE_CORE_C_OPS_BATCHNORMFOLD_H_ +#include + +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameBatchNormFold = "BatchNormFold"; +class BatchNormFold : public PrimitiveC { + public: + BatchNormFold() : PrimitiveC(kNameBatchNormFold) {} + ~BatchNormFold() = default; + MS_DECLARE_PARENT(BatchNormFold, PrimitiveC); + void Init() {} +}; + +using PrimBatchNormFoldPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_BATCHNORMFOLD_H_ diff --git a/mindspore/core/c_ops/bias_add.cc b/mindspore/core/c_ops/bias_add.cc new file mode 100644 index 0000000000..358a146ed5 --- /dev/null +++ b/mindspore/core/c_ops/bias_add.cc @@ -0,0 +1,33 @@ +/** + * 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 "c_ops/bias_add.h" +#include +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +void BiasAdd::set_format(const Format &format) { + int64_t f = format; + this->AddAttr(kFormat, MakeValue(f)); +} +Format BiasAdd::get_format() const { + auto value_ptr = GetAttr(kFormat); + return Format(GetValue(value_ptr)); +} +void BiasAdd::Init(const Format &format) { this->set_format(format); } +REGISTER_PRIMITIVE_C(kNameBiasAdd, BiasAdd); +} // namespace mindspore diff --git a/mindspore/core/c_ops/bias_add.h b/mindspore/core/c_ops/bias_add.h new file mode 100644 index 0000000000..6fd4733380 --- /dev/null +++ b/mindspore/core/c_ops/bias_add.h @@ -0,0 +1,40 @@ +/** + * 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_C_OPS_BIASADD_H_ +#define MINDSPORE_CORE_C_OPS_BIASADD_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameBiasAdd = "BiasAdd"; +class BiasAdd : public PrimitiveC { + public: + BiasAdd() : PrimitiveC(kNameBiasAdd) { InitIOName({"x", "b"}, {"output"}); } + ~BiasAdd() = default; + MS_DECLARE_PARENT(BiasAdd, PrimitiveC); + void Init(const Format &format = NCHW); + void set_format(const Format &format); + Format get_format() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_BIASADD_H_ diff --git a/mindspore/core/c_ops/bias_grad.cc b/mindspore/core/c_ops/bias_grad.cc new file mode 100644 index 0000000000..b3e98fd8d0 --- /dev/null +++ b/mindspore/core/c_ops/bias_grad.cc @@ -0,0 +1,37 @@ +/** + * 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 "c_ops/bias_grad.h" +#include +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +void BiasGrad::set_axis(const std::vector &axis) { this->AddAttr(kAxis, MakeValue(axis)); } + +std::vector BiasGrad::get_axis() const { + auto value_ptr = GetAttr(kAxis); + return GetValue>(value_ptr); +} + +void BiasGrad::Init(const std::vector &axis) { this->set_axis(axis); } +REGISTER_PRIMITIVE_C(kNameBiasGrad, BiasGrad); +} // namespace mindspore diff --git a/mindspore/core/c_ops/bias_grad.h b/mindspore/core/c_ops/bias_grad.h new file mode 100644 index 0000000000..db6c284a03 --- /dev/null +++ b/mindspore/core/c_ops/bias_grad.h @@ -0,0 +1,40 @@ +/** + * 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_C_OPS_BIASGRAD_H_ +#define MINDSPORE_CORE_C_OPS_BIASGRAD_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameBiasGrad = "BiasGrad"; +class BiasGrad : public PrimitiveC { + public: + BiasGrad() : PrimitiveC(kNameBiasGrad) {} + ~BiasGrad() = default; + MS_DECLARE_PARENT(BiasGrad, PrimitiveC); + void Init(const std::vector &axis); + void set_axis(const std::vector &axis); + std::vector get_axis() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_BIASGRAD_H_ diff --git a/mindspore/core/c_ops/binary_cross_entropy.cc b/mindspore/core/c_ops/binary_cross_entropy.cc new file mode 100644 index 0000000000..fd28d92d82 --- /dev/null +++ b/mindspore/core/c_ops/binary_cross_entropy.cc @@ -0,0 +1,40 @@ +/** + * 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 "c_ops/binary_cross_entropy.h" +#include +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { + +void BinaryCrossEntropy::set_reduction(const std::string &reduction) { + CheckAndConvertUtils::CheckString(kReduction, reduction, {"none", "mean", "sum"}, this->name()); + this->AddAttr(kReduction, MakeValue(reduction)); +} +std::string BinaryCrossEntropy::get_reduction() const { + auto value_ptr = GetAttr(kReduction); + return GetValue(value_ptr); +} + +void BinaryCrossEntropy::Init(const std::string &reduction) { this->set_reduction(reduction); } +REGISTER_PRIMITIVE_C(kNameBinaryCrossEntropy, BinaryCrossEntropy); +} // namespace mindspore diff --git a/mindspore/core/c_ops/binary_cross_entropy.h b/mindspore/core/c_ops/binary_cross_entropy.h new file mode 100644 index 0000000000..900c949f33 --- /dev/null +++ b/mindspore/core/c_ops/binary_cross_entropy.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_BINARY_CROSS_ENTROPY_GRAD_H_ +#define MINDSPORE_CORE_C_OPS_BINARY_CROSS_ENTROPY_GRAD_H_ +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameBinaryCrossEntropy = "BinaryCrossEntropy"; +class BinaryCrossEntropy : public PrimitiveC { + public: + BinaryCrossEntropy() : PrimitiveC(kNameBinaryCrossEntropy) {} + ~BinaryCrossEntropy() = default; + MS_DECLARE_PARENT(BinaryCrossEntropy, PrimitiveC); + void Init(const std::string &reduction = "mean"); + void set_reduction(const std::string &reduction); + std::string get_reduction() const; +}; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_BINARY_CROSS_ENTROPY_GRAD_H_ diff --git a/mindspore/core/c_ops/binary_cross_entropy_grad.cc b/mindspore/core/c_ops/binary_cross_entropy_grad.cc new file mode 100644 index 0000000000..54a641a9e9 --- /dev/null +++ b/mindspore/core/c_ops/binary_cross_entropy_grad.cc @@ -0,0 +1,31 @@ +/** + * 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 "c_ops/binary_cross_entropy_grad.h" + +namespace mindspore { +void BinaryCrossEntropyGrad::Init(const std::string &reduction) { set_reduction(reduction); } + +void BinaryCrossEntropyGrad::set_reduction(const std::string &reduction) { + CheckAndConvertUtils::CheckString(kReduction, reduction, {"none", "mean", "sum"}, name()); + this->AddAttr(kReduction, MakeValue(reduction)); +} +std::string BinaryCrossEntropyGrad::get_reduction() const { + auto value_ptr = GetAttr(kReduction); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameBinaryCrossEntropyGrad, BinaryCrossEntropyGrad); +} // namespace mindspore diff --git a/mindspore/core/c_ops/binary_cross_entropy_grad.h b/mindspore/core/c_ops/binary_cross_entropy_grad.h new file mode 100644 index 0000000000..af35b0d346 --- /dev/null +++ b/mindspore/core/c_ops/binary_cross_entropy_grad.h @@ -0,0 +1,43 @@ +/** + * 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_C_OPS_BINARY_CROSS_ENTROPY_GRAD_H_ +#define MINDSPORE_CORE_C_OPS_BINARY_CROSS_ENTROPY_GRAD_H_ +#include +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameBinaryCrossEntropyGrad = "BinaryCrossEntropyGrad"; +class BinaryCrossEntropyGrad : public PrimitiveC { + public: + BinaryCrossEntropyGrad() : PrimitiveC(kNameBinaryCrossEntropyGrad) {} + ~BinaryCrossEntropyGrad() = default; + MS_DECLARE_PARENT(BinaryCrossEntropyGrad, PrimitiveC); + void Init(const std::string &reduction = "mean"); + void set_reduction(const std::string &reduction); + std::string get_reduction() const; +}; +AbstractBasePtr BinaryCrossEntropyGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimBinaryCrossEntropyGrad = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_BINARY_CROSS_ENTROPY_GRAD_H_ diff --git a/mindspore/core/c_ops/black_box.cc b/mindspore/core/c_ops/black_box.cc new file mode 100644 index 0000000000..3d4ce946d3 --- /dev/null +++ b/mindspore/core/c_ops/black_box.cc @@ -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. + */ + +#include "c_ops/black_box.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +void BlackBox::Init(const std::string &id, int64_t size, const std::vector &address) { + this->set_id(id); + this->set_size(size); + this->set_address(address); +} + +void BlackBox::set_id(const std::string &id) { this->AddAttr(kId, MakeValue(id)); } + +std::string BlackBox::get_id() const { + auto value_ptr = this->GetAttr(kId); + return GetValue(value_ptr); +} + +void BlackBox::set_size(int64_t size) { this->AddAttr(kSize, MakeValue(size)); } + +int64_t BlackBox::get_size() const { + auto value_ptr = this->GetAttr(kSize); + return GetValue(value_ptr); +} + +void BlackBox::set_address(const std::vector &address) { this->AddAttr(kAddress, MakeValue(address)); } + +std::vector BlackBox::get_address() const { + auto value_ptr = this->GetAttr(kAddress); + return GetValue>(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameBlackBox, BlackBox); +} // namespace mindspore diff --git a/mindspore/core/c_ops/black_box.h b/mindspore/core/c_ops/black_box.h new file mode 100644 index 0000000000..d2d41e583f --- /dev/null +++ b/mindspore/core/c_ops/black_box.h @@ -0,0 +1,45 @@ +/** + * 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_C_OPS_BLACKBOX_H_ +#define MINDSPORE_CORE_C_OPS_BLACKBOX_H_ +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameBlackBox = "BlackBox"; +class BlackBox : public PrimitiveC { + public: + BlackBox() : PrimitiveC(kNameBlackBox) {} + ~BlackBox() = default; + MS_DECLARE_PARENT(BlackBox, PrimitiveC); + void Init(const std::string &id, int64_t size, const std::vector &address); + void set_id(const std::string &id); + void set_size(int64_t size); + void set_address(const std::vector &address); + std::string get_id() const; + int64_t get_size() const; + std::vector get_address() const; +}; + +using PrimBlackBoxPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_BLACKBOX_H_ diff --git a/mindspore/core/c_ops/broadcast.cc b/mindspore/core/c_ops/broadcast.cc new file mode 100644 index 0000000000..b113c9ea2f --- /dev/null +++ b/mindspore/core/c_ops/broadcast.cc @@ -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. + */ + +#include "c_ops/broadcast.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +void Broadcast::Init(int64_t root_rank, const std::string &group) { + this->set_root_rank(root_rank); + this->set_group(group); +} +void Broadcast::set_root_rank(int64_t root_rank) { this->AddAttr(kKeepProb, MakeValue(root_rank)); } + +void Broadcast::set_group(const std::string &group) { + CheckAndConvertUtils::CheckString(kGroup, group, {"hccl_world_group", "hccl_world_group"}, this->name()); + this->AddAttr(kGroup, MakeValue(group)); +} +int64_t Broadcast::get_root_rank() { + auto value_ptr = this->GetAttr(kRootRank); + return GetValue(value_ptr); +} + +std::string Broadcast::get_group() const { + auto value_ptr = this->GetAttr(kGroup); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameBroadcast, Broadcast); +} // namespace mindspore diff --git a/mindspore/core/c_ops/broadcast.h b/mindspore/core/c_ops/broadcast.h new file mode 100644 index 0000000000..e9a864f72d --- /dev/null +++ b/mindspore/core/c_ops/broadcast.h @@ -0,0 +1,40 @@ +/** + * 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_C_OPS_BROADCAST_H_ +#define MINDSPORE_CORE_C_OPS_BROADCAST_H_ +#include + +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameBroadcast = "Broadcast"; +class Broadcast : public PrimitiveC { + public: + Broadcast() : PrimitiveC(kNameBroadcast) {} + ~Broadcast() = default; + MS_DECLARE_PARENT(Broadcast, PrimitiveC); + void Init(int64_t root_rank, const std::string &group = "hccl_world_group"); + void set_root_rank(int64_t root_rank); + void set_group(const std::string &group); + int64_t get_root_rank(); + std::string get_group() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_BROADCAST_H_ diff --git a/mindspore/core/c_ops/broadcast_to.cc b/mindspore/core/c_ops/broadcast_to.cc new file mode 100644 index 0000000000..04a967746b --- /dev/null +++ b/mindspore/core/c_ops/broadcast_to.cc @@ -0,0 +1,33 @@ +/** + * 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 "c_ops/broadcast_to.h" + +namespace mindspore { +void BroadcastTo::Init(const std::vector &shape) { set_shape(shape); } + +void BroadcastTo::set_shape(const std::vector &shape) { + CheckAndConvertUtils::CheckInteger(kShapeSize, shape.size(), kGreaterThan, 0, name()); + CheckAndConvertUtils::CheckPositiveVector(kShape, shape, name(), false, true); + AddAttr(kShape, MakeValue(shape)); +} + +std::vector BroadcastTo::get_shape() const { + auto value_ptr = GetAttr(kShape); + return GetValue>(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameBroadcastTo, BroadcastTo); +} // namespace mindspore diff --git a/mindspore/core/c_ops/broadcast_to.h b/mindspore/core/c_ops/broadcast_to.h new file mode 100644 index 0000000000..a411b97467 --- /dev/null +++ b/mindspore/core/c_ops/broadcast_to.h @@ -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. + */ + +#ifndef MINDSPORE_CORE_C_OPS_BROADCAST_H_ +#define MINDSPORE_CORE_C_OPS_BROADCAST_H_ +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameBroadcastTo = "BroadcastTo"; +class BroadcastTo : public PrimitiveC { + public: + BroadcastTo() : PrimitiveC(kNameBroadcastTo) {} + ~BroadcastTo() = default; + MS_DECLARE_PARENT(BroadcastTo, PrimitiveC); + void Init(const std::vector &shape); + void set_shape(const std::vector &shape); + std::vector get_shape() const; +}; + +AbstractBasePtr BroadcastToInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimBroadcastToPtr = std::shared_ptr; + +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_BROADCAST_H_ diff --git a/mindspore/core/c_ops/cast.cc b/mindspore/core/c_ops/cast.cc new file mode 100644 index 0000000000..43180a6969 --- /dev/null +++ b/mindspore/core/c_ops/cast.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/cast.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameCast, Cast); +} diff --git a/mindspore/core/c_ops/cast.h b/mindspore/core/c_ops/cast.h new file mode 100644 index 0000000000..795c4a9fad --- /dev/null +++ b/mindspore/core/c_ops/cast.h @@ -0,0 +1,39 @@ +/** + * 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_C_OPS_CAST_H_ +#define MINDSPORE_CORE_C_OPS_CAST_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameCast = "Cast"; +class Cast : public PrimitiveC { + public: + Cast() : PrimitiveC(kNameCast) { InitIOName({"x", "dst_type"}, {"output"}); } + ~Cast() = default; + MS_DECLARE_PARENT(Cast, PrimitiveC); +}; +AbstractBasePtr CastInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimCast = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_CAST_H_ diff --git a/mindspore/core/c_ops/ceil.cc b/mindspore/core/c_ops/ceil.cc new file mode 100644 index 0000000000..3932883f82 --- /dev/null +++ b/mindspore/core/c_ops/ceil.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/ceil.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameCeil, Ceil); +} diff --git a/mindspore/core/c_ops/ceil.h b/mindspore/core/c_ops/ceil.h new file mode 100644 index 0000000000..c532aeed4f --- /dev/null +++ b/mindspore/core/c_ops/ceil.h @@ -0,0 +1,39 @@ +/** + * 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_C_OPS_CEIL_H_ +#define MINDSPORE_CORE_C_OPS_CEIL_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" + +namespace mindspore { +constexpr auto kNameCeil = "Ceil"; +class Ceil : public PrimitiveC { + public: + Ceil() : PrimitiveC(kNameCeil) { InitIOName({"x"}, {"y"}); } + ~Ceil() = default; + MS_DECLARE_PARENT(Ceil, PrimitiveC); +}; + +AbstractBasePtr CeilInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimCeil = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_CEIL_H_ diff --git a/mindspore/core/c_ops/clip.cc b/mindspore/core/c_ops/clip.cc new file mode 100644 index 0000000000..f982f6299a --- /dev/null +++ b/mindspore/core/c_ops/clip.cc @@ -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. + */ + +#include "c_ops/clip.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" +#include "c_ops/op_utils.h" + +namespace mindspore { +void Clip::Init(const float max, const float min) { + this->set_max(max); + this->set_min(min); +} + +void Clip::set_max(const float max) { this->AddAttr(kMax, MakeValue(max)); } + +float Clip::get_max() const { + auto value_ptr = this->GetAttr(kMax); + return GetValue(value_ptr); +} + +void Clip::set_min(const float min) { this->AddAttr(kMin, MakeValue(min)); } + +float Clip::get_min() const { + auto value_ptr = this->GetAttr(kMin); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameClip, Clip); +} // namespace mindspore diff --git a/mindspore/core/c_ops/clip.h b/mindspore/core/c_ops/clip.h new file mode 100644 index 0000000000..e90a9d17d4 --- /dev/null +++ b/mindspore/core/c_ops/clip.h @@ -0,0 +1,41 @@ +/** + * 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_C_OPS_CLIP_H_ +#define MINDSPORE_CORE_C_OPS_CLIP_H_ +#include + +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameClip = "Clip"; +class Clip : public PrimitiveC { + public: + Clip() : PrimitiveC(kNameClip) {} + ~Clip() = default; + MS_DECLARE_PARENT(Clip, PrimitiveC); + void Init(const float max, const float min); + void set_max(const float max); + void set_min(const float min); + float get_max() const; + float get_min() const; +}; + +using PrimClipPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_CLIP_H_ diff --git a/mindspore/core/c_ops/concat.cc b/mindspore/core/c_ops/concat.cc new file mode 100644 index 0000000000..a64d117f82 --- /dev/null +++ b/mindspore/core/c_ops/concat.cc @@ -0,0 +1,32 @@ +/** + * 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 "c_ops/concat.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +namespace mindspore { + +void Concat::Init(int64_t axis) { this->set_axis(axis); } +int64_t Concat::get_axis() const { + auto value_ptr = this->GetAttr(kAxis); + return GetValue(value_ptr); +} + +void Concat::set_axis(int64_t axis) { + this->AddAttr(kAxis, MakeValue(CheckAndConvertUtils::CheckInteger(kAxis, axis, kGreaterEqual, 0, this->name()))); +} +REGISTER_PRIMITIVE_C(kNameConcat, Concat); +} // namespace mindspore diff --git a/mindspore/core/c_ops/concat.h b/mindspore/core/c_ops/concat.h new file mode 100644 index 0000000000..fafffd2445 --- /dev/null +++ b/mindspore/core/c_ops/concat.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_C_OPS_CONCAT_H_ +#define MINDSPORE_CORE_C_OPS_CONCAT_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameConcat = "Concat"; +class Concat : public PrimitiveC { + public: + Concat() : PrimitiveC(kNameConcat) {} + ~Concat() = default; + MS_DECLARE_PARENT(Concat, PrimitiveC); + void Init(int64_t axis = 0); + void set_axis(int64_t axis); + int64_t get_axis() const; +}; +AbstractBasePtr ConcatInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimConcatPtr = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_CONCAT_H_ diff --git a/mindspore/core/c_ops/constant_of_shape.cc b/mindspore/core/c_ops/constant_of_shape.cc new file mode 100644 index 0000000000..5c2e079daf --- /dev/null +++ b/mindspore/core/c_ops/constant_of_shape.cc @@ -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. + */ + +#include "c_ops/constant_of_shape.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +void ConstantOfShape::Init(int64_t data_type, const std::vector &value) { + this->set_data_type(data_type); + this->set_value(value); +} + +void ConstantOfShape::set_data_type(int64_t data_type) { this->AddAttr(kDataType, MakeValue(data_type)); } + +int64_t ConstantOfShape::get_data_type() const { + auto value_ptr = this->GetAttr(kDataType); + return GetValue(value_ptr); +} + +void ConstantOfShape::set_value(const std::vector &value) { this->AddAttr(kValue, MakeValue(value)); } + +std::vector ConstantOfShape::get_value() const { + auto value_ptr = this->GetAttr(kValue); + return GetValue>(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameConstantOfShape, ConstantOfShape); +} // namespace mindspore diff --git a/mindspore/core/c_ops/constant_of_shape.h b/mindspore/core/c_ops/constant_of_shape.h new file mode 100644 index 0000000000..082573c22a --- /dev/null +++ b/mindspore/core/c_ops/constant_of_shape.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_C_OPS_CONSTANTOFSHAPE_H_ +#define MINDSPORE_CORE_C_OPS_CONSTANTOFSHAPE_H_ +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameConstantOfShape = "ConstantOfShape"; +class ConstantOfShape : public PrimitiveC { + public: + ConstantOfShape() : PrimitiveC(kNameConstantOfShape) {} + ~ConstantOfShape() = default; + MS_DECLARE_PARENT(ConstantOfShape, PrimitiveC); + void Init(int64_t data_type, const std::vector &value); + void set_data_type(int64_t data_type); + void set_value(const std::vector &value); + int64_t get_data_type() const; + std::vector get_value() const; +}; + +using PrimConstantOfShapePtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_CONSTANTOFSHAPE_H_ diff --git a/mindspore/core/c_ops/control_depend.cc b/mindspore/core/c_ops/control_depend.cc new file mode 100644 index 0000000000..28872727e7 --- /dev/null +++ b/mindspore/core/c_ops/control_depend.cc @@ -0,0 +1,32 @@ +/** + * 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 "c_ops/control_depend.h" + +namespace mindspore { +void ControlDepend::Init(int64_t depend_mode) { this->set_depend_mode(depend_mode); } + +void ControlDepend::set_depend_mode(int64_t depend_mode) { + CheckAndConvertUtils::CheckInRange(kDependMode, depend_mode, kIncludeBoth, {0, 1}, name()); + AddAttr(kDependMode, MakeValue(depend_mode)); +} + +int64_t ControlDepend::get_depend_mode() { + auto value_ptr = GetAttr(kDependMode); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameControlDepend, ControlDepend); +} // namespace mindspore diff --git a/mindspore/core/c_ops/control_depend.h b/mindspore/core/c_ops/control_depend.h new file mode 100644 index 0000000000..db2c5cc054 --- /dev/null +++ b/mindspore/core/c_ops/control_depend.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_C_OPS_CONTROL_DEPEND_H_ +#define MINDSPORE_CORE_C_OPS_CONTROL_DEPEND_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameControlDepend = "ControlDepend"; +class ControlDepend : public PrimitiveC { + public: + ControlDepend() : PrimitiveC(kNameControlDepend) {} + ~ControlDepend() = default; + MS_DECLARE_PARENT(ControlDepend, PrimitiveC); + void Init(int64_t depend_mode); + void set_depend_mode(int64_t depend_mode); + int64_t get_depend_mode(); +}; +AbstractBasePtr ControlDependInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimControlDepend = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_CONTROl_DEPEND_H_ diff --git a/mindspore/core/c_ops/cos.cc b/mindspore/core/c_ops/cos.cc new file mode 100644 index 0000000000..8dd5db035e --- /dev/null +++ b/mindspore/core/c_ops/cos.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/cos.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameCos, Cos); +} diff --git a/mindspore/core/c_ops/cos.h b/mindspore/core/c_ops/cos.h new file mode 100644 index 0000000000..a9dbc89774 --- /dev/null +++ b/mindspore/core/c_ops/cos.h @@ -0,0 +1,39 @@ +/** + * 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_C_OPS_COS_H_ +#define MINDSPORE_CORE_C_OPS_COS_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" + +namespace mindspore { +constexpr auto kNameCos = "Cos"; +class Cos : public PrimitiveC { + public: + Cos() : PrimitiveC(kNameCos) {} + ~Cos() = default; + MS_DECLARE_PARENT(Cos, PrimitiveC); + void Init(float alpha = 0.0); +}; +AbstractBasePtr CosInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimCos = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_COS_H_ diff --git a/mindspore/core/c_ops/custom.cc b/mindspore/core/c_ops/custom.cc new file mode 100644 index 0000000000..2a2f529f59 --- /dev/null +++ b/mindspore/core/c_ops/custom.cc @@ -0,0 +1,32 @@ +/** + * 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 "c_ops/custom.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" +#include "c_ops/op_utils.h" + +namespace mindspore { +void Custom::Init(const std::vector &custom) { this->set_custom(custom); } + +void Custom::set_custom(const std::vector &custom) { this->AddAttr(kCustom, MakeValue(custom)); } + +std::vector Custom::get_custom() const { + auto value_ptr = this->GetAttr(kCustom); + return GetValue>(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameCustom, Custom); +} // namespace mindspore diff --git a/mindspore/core/c_ops/custom.h b/mindspore/core/c_ops/custom.h new file mode 100644 index 0000000000..23ee2231bf --- /dev/null +++ b/mindspore/core/c_ops/custom.h @@ -0,0 +1,41 @@ +/** + * 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_C_OPS_CUSTOM_H_ +#define MINDSPORE_CORE_C_OPS_CUSTOM_H_ +#include + +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameCustom = "Custom"; +class Custom : public PrimitiveC { + public: + Custom() : PrimitiveC(kNameCustom) {} + ~Custom() = default; + MS_DECLARE_PARENT(Custom, PrimitiveC); + void Init(const std::vector &custom); + void set_custom(const std::vector &custom); + std::vector get_custom() const; +}; + +using PrimCustomPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_CUSTOM_H_ diff --git a/mindspore/core/c_ops/custom_normalize.cc b/mindspore/core/c_ops/custom_normalize.cc new file mode 100644 index 0000000000..f205ef2b21 --- /dev/null +++ b/mindspore/core/c_ops/custom_normalize.cc @@ -0,0 +1,23 @@ +/** + * 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 "c_ops/custom_normalize.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameCustomNormalize, CustomNormalize); +} // namespace mindspore diff --git a/mindspore/core/c_ops/custom_normalize.h b/mindspore/core/c_ops/custom_normalize.h new file mode 100644 index 0000000000..7cce4efcb0 --- /dev/null +++ b/mindspore/core/c_ops/custom_normalize.h @@ -0,0 +1,37 @@ +/** + * 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_C_OPS_CUSTOMNORMALIZE_H_ +#define MINDSPORE_CORE_C_OPS_CUSTOMNORMALIZE_H_ +#include + +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameCustomNormalize = "CustomNormalize"; +class CustomNormalize : public PrimitiveC { + public: + CustomNormalize() : PrimitiveC(kNameCustomNormalize) {} + ~CustomNormalize() = default; + MS_DECLARE_PARENT(CustomNormalize, PrimitiveC); + void Init() {} +}; + +using PrimCustomNormalizePtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_CUSTOMNORMALIZE_H_ diff --git a/mindspore/core/c_ops/custom_predict.cc b/mindspore/core/c_ops/custom_predict.cc new file mode 100644 index 0000000000..0873abf029 --- /dev/null +++ b/mindspore/core/c_ops/custom_predict.cc @@ -0,0 +1,44 @@ +/** + * 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 "c_ops/custom_predict.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +void CustomPredict::Init(int64_t outputNum, float weight_threshold) { + this->set_outputNum(outputNum); + this->set_weight_threshold(weight_threshold); +} + +void CustomPredict::set_outputNum(int64_t outputNum) { this->AddAttr(kOutputNum, MakeValue(outputNum)); } + +int64_t CustomPredict::get_outputNum() const { + auto value_ptr = this->GetAttr(kOutputNum); + return GetValue(value_ptr); +} + +void CustomPredict::set_weight_threshold(float weight_threshold) { + this->AddAttr(kWeightThreshold, MakeValue(weight_threshold)); +} + +float CustomPredict::get_weight_threshold() const { + auto value_ptr = this->GetAttr(kWeightThreshold); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameCustomPredict, CustomPredict); +} // namespace mindspore diff --git a/mindspore/core/c_ops/custom_predict.h b/mindspore/core/c_ops/custom_predict.h new file mode 100644 index 0000000000..02b4c1bd83 --- /dev/null +++ b/mindspore/core/c_ops/custom_predict.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_C_OPS_CUSTOMPREDICT_H_ +#define MINDSPORE_CORE_C_OPS_CUSTOMPREDICT_H_ +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameCustomPredict = "CustomPredict"; +class CustomPredict : public PrimitiveC { + public: + CustomPredict() : PrimitiveC(kNameCustomPredict) {} + ~CustomPredict() = default; + MS_DECLARE_PARENT(CustomPredict, PrimitiveC); + void Init(int64_t outputNum, float weight_threshold); + void set_outputNum(int64_t outputNum); + void set_weight_threshold(float weight_threshold); + int64_t get_outputNum() const; + float get_weight_threshold() const; +}; + +using PrimCustomPredictPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_CUSTOMPREDICT_H_ diff --git a/mindspore/core/c_ops/depend.cc b/mindspore/core/c_ops/depend.cc new file mode 100644 index 0000000000..cbe7f52037 --- /dev/null +++ b/mindspore/core/c_ops/depend.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/depend.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameDepend, Depend); +} diff --git a/mindspore/core/c_ops/depend.h b/mindspore/core/c_ops/depend.h new file mode 100644 index 0000000000..5a1d8d8d7f --- /dev/null +++ b/mindspore/core/c_ops/depend.h @@ -0,0 +1,39 @@ +/** + * 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_C_OPS_DEPEND_H_ +#define MINDSPORE_CORE_C_OPS_DEPEND_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" + +namespace mindspore { +constexpr auto kNameDepend = "Depend"; +class Depend : public PrimitiveC { + public: + Depend() : PrimitiveC(kNameDepend) {} + ~Depend() = default; + MS_DECLARE_PARENT(Depend, PrimitiveC); + void Init(); +}; +AbstractBasePtr DependInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimDepend = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_DEPEND_H_ diff --git a/mindspore/core/c_ops/depth_to_space.cc b/mindspore/core/c_ops/depth_to_space.cc new file mode 100644 index 0000000000..1c20a6c951 --- /dev/null +++ b/mindspore/core/c_ops/depth_to_space.cc @@ -0,0 +1,51 @@ +/** + * 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 "c_ops/depth_to_space.h" +#include +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +void DepthToSpace::set_block_size(const int64_t &block_size) { + CheckAndConvertUtils::Check(kBlockSize, block_size, kGreaterEqual, "", 2, this->name()); + this->AddAttr(kBlockSize, MakeValue(block_size)); +} + +int64_t DepthToSpace::get_block_size() const { + auto value_ptr = GetAttr(kBlockSize); + return GetValue(value_ptr); +} +void DepthToSpace::set_format(const Format &format) { + int64_t f = format; + this->AddAttr(kFormat, MakeValue(f)); +} + +Format DepthToSpace::get_format() const { + auto value_ptr = GetAttr(kFormat); + return Format(GetValue(value_ptr)); +} + +void DepthToSpace::Init(const int64_t &block_size, const Format &format) { + this->set_block_size(block_size); + this->set_format(format); +} +REGISTER_PRIMITIVE_C(kNameDepthToSpace, DepthToSpace); +} // namespace mindspore diff --git a/mindspore/core/c_ops/depth_to_space.h b/mindspore/core/c_ops/depth_to_space.h new file mode 100644 index 0000000000..7dcd733017 --- /dev/null +++ b/mindspore/core/c_ops/depth_to_space.h @@ -0,0 +1,43 @@ +/** + * 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_C_OPS_DEPTH_TO_SPACE_H_ +#define MINDSPORE_CORE_C_OPS_DEPTH_TO_SPACE_H_ + +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameDepthToSpace = "DepthToSpace"; +class DepthToSpace : public PrimitiveC { + public: + DepthToSpace() : PrimitiveC(kNameDepthToSpace) { InitIOName({"x"}, {"y"}); } + ~DepthToSpace() = default; + MS_DECLARE_PARENT(DepthToSpace, PrimitiveC); + void Init(const int64_t &block_size, const Format &format = NCHW); + void set_block_size(const int64_t &block_size); + int64_t get_block_size() const; + void set_format(const Format &format); + Format get_format() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_DEPTH_TO_SPACE_H_ diff --git a/mindspore/core/c_ops/depthwise_conv2d.cc b/mindspore/core/c_ops/depthwise_conv2d.cc index b03e8df710..a5ce87f431 100644 --- a/mindspore/core/c_ops/depthwise_conv2d.cc +++ b/mindspore/core/c_ops/depthwise_conv2d.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -24,11 +24,11 @@ #include "abstract/primitive_infer_map.h" namespace mindspore { -void DepthWiseConv2D::Init(int channel_multiplier, const std::vector &kernel_size, int mode, +void DepthWiseConv2D::Init(int64_t channel_multiplier, const std::vector &kernel_size, int64_t mode, const std::string &pad_mode, const std::vector &pad, - const std::vector &stride, const std::vector &dilation, int group) { + const std::vector &stride, const std::vector &dilation, int64_t group) { auto prim_name = this->name(); - this->AddAttr("data_format", MakeValue("NCHW")); + this->set_format(NCHW); this->AddAttr("offset_a", MakeValue(0)); this->set_mode(CheckAndConvertUtils::CheckInteger("mode", mode, kEqual, 3, prim_name)); @@ -88,18 +88,18 @@ std::vector DepthWiseConv2D::get_pads() const { return GetValue>(value_ptr); } -int DepthWiseConv2D::get_mode() const { +int64_t DepthWiseConv2D::get_mode() const { auto value_ptr = this->GetAttr(kMode); - return GetValue(value_ptr); + return GetValue(value_ptr); } -int DepthWiseConv2D::get_group() const { +int64_t DepthWiseConv2D::get_group() const { auto value_ptr = this->GetAttr(kGroup); - return GetValue(value_ptr); + return GetValue(value_ptr); } -int DepthWiseConv2D::get_output_channel() const { - auto value_ptr = this->GetAttr(kOutputChannel); - return GetValue(value_ptr); +int64_t DepthWiseConv2D::get_out_channel() const { + auto value_ptr = this->GetAttr(kOutChannel); + return GetValue(value_ptr); } void DepthWiseConv2D::set_kernel_size(const std::vector &kernel_size) { @@ -112,11 +112,20 @@ void DepthWiseConv2D::set_dilation(const std::vector &dilation) { } void DepthWiseConv2D::set_pad_mode(const std::string &pad_mode) { this->AddAttr(kPadMode, MakeValue(pad_mode)); } void DepthWiseConv2D::set_pad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } -void DepthWiseConv2D::set_mode(int mode) { this->AddAttr(kMode, MakeValue(mode)); } -void DepthWiseConv2D::set_group(int group) { this->AddAttr(kGroup, MakeValue(group)); } -void DepthWiseConv2D::set_out_channel(int output_channel) { this->AddAttr(kOutputChannel, MakeValue(output_channel)); } +void DepthWiseConv2D::set_mode(int64_t mode) { this->AddAttr(kMode, MakeValue(mode)); } +void DepthWiseConv2D::set_group(int64_t group) { this->AddAttr(kGroup, MakeValue(group)); } +void DepthWiseConv2D::set_out_channel(int64_t out_channel) { this->AddAttr(kOutChannel, MakeValue(out_channel)); } void DepthWiseConv2D::set_pads(const std::vector &pad_list) { this->AddAttr(kPads, MakeValue(pad_list)); } +void DepthWiseConv2D::set_format(const Format &format) { + int64_t f = format; + this->AddAttr(kFormat, MakeValue(f)); +} + +Format DepthWiseConv2D::get_format() const { + auto value_ptr = GetAttr(kFormat); + return Format(GetValue(value_ptr)); +} abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto conv_prim = primitive->cast(); @@ -129,7 +138,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vectorname()); - auto out_channel = conv_prim->get_output_channel(); + auto out_channel = conv_prim->get_out_channel(); std::vector temp_w; std::copy(w_shape.begin() + 2, w_shape.end(), std::back_inserter(temp_w)); @@ -148,8 +157,8 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector pad_list(4, 0); auto pad_mode = conv_prim->get_pad_mode(); if (pad_mode == "valid") { diff --git a/mindspore/core/c_ops/depthwise_conv2d.h b/mindspore/core/c_ops/depthwise_conv2d.h index 42e165c360..2780b76ab6 100644 --- a/mindspore/core/c_ops/depthwise_conv2d.h +++ b/mindspore/core/c_ops/depthwise_conv2d.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -31,28 +31,30 @@ class DepthWiseConv2D : public PrimitiveC { DepthWiseConv2D() : PrimitiveC(kNameDepthWiseConv2D) { InitIOName({"x", "w"}, {"output"}); } ~DepthWiseConv2D() = default; MS_DECLARE_PARENT(DepthWiseConv2D, PrimitiveC); - void Init(int out_channel, const std::vector &kernel_size, int mode = 1, + void Init(int64_t out_channel, const std::vector &kernel_size, int64_t mode = 1, const std::string &pad_mode = "valid", const std::vector &pad = {0, 0, 0, 0}, const std::vector &stride = {1, 1, 1, 1}, const std::vector &dilation = {1, 1, 1, 1}, - int group = 1); + int64_t group = 1); std::vector get_kernel_size() const; std::vector get_stride() const; std::vector get_dilation() const; std::string get_pad_mode() const; std::vector get_pad() const; std::vector get_pads() const; - int get_mode() const; - int get_group() const; - int get_output_channel() const; + int64_t get_mode() const; + int64_t get_group() const; + int64_t get_out_channel() const; void set_kernel_size(const std::vector &kernel_size); void set_stride(const std::vector &stride); void set_dilation(const std::vector &dilation); void set_pad_mode(const std::string &pad_mode); void set_pad(const std::vector &pad); - void set_mode(int mode); - void set_group(int group); - void set_out_channel(int output_channel); + void set_mode(int64_t mode); + void set_group(int64_t group); + void set_out_channel(int64_t out_channel); void set_pads(const std::vector &pad_list); + void set_format(const Format &format); + Format get_format() const; }; AbstractBasePtr DepthWiseConv2DInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args); diff --git a/mindspore/core/c_ops/div.cc b/mindspore/core/c_ops/div.cc new file mode 100644 index 0000000000..8e5356b6cb --- /dev/null +++ b/mindspore/core/c_ops/div.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/div.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameDiv, Div); +} // namespace mindspore diff --git a/mindspore/core/c_ops/div.h b/mindspore/core/c_ops/div.h new file mode 100644 index 0000000000..be624080ad --- /dev/null +++ b/mindspore/core/c_ops/div.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_DIV_H_ +#define MINDSPORE_CORE_C_OPS_DIV_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameDiv = "Div"; +class Div : public PrimitiveC { + public: + Div() : PrimitiveC(kNameDiv) { InitIOName({"x", "y"}, {"output"}); } + ~Div() = default; + MS_DECLARE_PARENT(Div, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_DIV_H_ diff --git a/mindspore/core/c_ops/dropout.cc b/mindspore/core/c_ops/dropout.cc new file mode 100644 index 0000000000..a149128acf --- /dev/null +++ b/mindspore/core/c_ops/dropout.cc @@ -0,0 +1,32 @@ +/** + * 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 "c_ops/dropout.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +void Dropout::Init(float keep_prob) { this->set_keep_prob(keep_prob); } +void Dropout::set_keep_prob(float keep_prob) { + CheckAndConvertUtils::CheckInRange(kKeepProb, keep_prob, kIncludeRight, {0.0, 1.0}, this->name()); + this->AddAttr(kKeepProb, MakeValue(keep_prob)); +} +float Dropout::get_keep_prob() { + auto value_ptr = this->GetAttr(kKeepProb); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameDropout, Dropout); +} // namespace mindspore diff --git a/mindspore/core/c_ops/dropout.h b/mindspore/core/c_ops/dropout.h new file mode 100644 index 0000000000..c28368deee --- /dev/null +++ b/mindspore/core/c_ops/dropout.h @@ -0,0 +1,35 @@ +/** + * 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_C_OPS_DROPOUT_H_ +#define MINDSPORE_CORE_C_OPS_DROPOUT_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameDropout = "Dropout"; +class Dropout : public PrimitiveC { + public: + Dropout() : PrimitiveC(kNameDropout) {} + ~Dropout() = default; + MS_DECLARE_PARENT(Dropout, PrimitiveC); + void Init(float keep_prob = 0.5); + void set_keep_prob(float keep_prob); + float get_keep_prob(); +}; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_DROPOUT_H_ diff --git a/mindspore/core/c_ops/embedding_lookup.cc b/mindspore/core/c_ops/embedding_lookup.cc new file mode 100644 index 0000000000..f7e08acdcd --- /dev/null +++ b/mindspore/core/c_ops/embedding_lookup.cc @@ -0,0 +1,33 @@ +/** + * 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 "c_ops/embedding_lookup.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { + +void EmbeddingLookup::set_setattr_flag(const bool &setattr_flag) { + this->AddAttr(kSetattrFlag, MakeValue(setattr_flag)); +} + +bool EmbeddingLookup::get_setattr_flag() const { + auto value_ptr = GetAttr(kSetattrFlag); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameEmbeddingLookup, EmbeddingLookup); +} // namespace mindspore diff --git a/mindspore/core/c_ops/embedding_lookup.h b/mindspore/core/c_ops/embedding_lookup.h new file mode 100644 index 0000000000..9c358d3e16 --- /dev/null +++ b/mindspore/core/c_ops/embedding_lookup.h @@ -0,0 +1,40 @@ +/** + * 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_C_OPS_EMBEDDINGLOOKUP_H_ +#define MINDSPORE_CORE_C_OPS_EMBEDDINGLOOKUP_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameEmbeddingLookup = "EmbeddingLookup"; +class EmbeddingLookup : public PrimitiveC { + public: + EmbeddingLookup() : PrimitiveC(kNameEmbeddingLookup) { InitIOName({"params", "indices"}, {"offset"}); } + ~EmbeddingLookup() = default; + MS_DECLARE_PARENT(EmbeddingLookup, PrimitiveC); + void set_setattr_flag(const bool &setattr_flag = true); + bool get_setattr_flag() const; + // void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_EMBEDDINGLOOKUP_H_ diff --git a/mindspore/core/c_ops/equal.cc b/mindspore/core/c_ops/equal.cc new file mode 100644 index 0000000000..c6cd04fb67 --- /dev/null +++ b/mindspore/core/c_ops/equal.cc @@ -0,0 +1,20 @@ +/** + * 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 "c_ops/equal.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameEqual, Equal); +} // namespace mindspore diff --git a/mindspore/core/c_ops/equal.h b/mindspore/core/c_ops/equal.h new file mode 100644 index 0000000000..57009213ae --- /dev/null +++ b/mindspore/core/c_ops/equal.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_EQUAL_H_ +#define MINDSPORE_CORE_C_OPS_EQUAL_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameEqual = "Equal"; +class Equal : public PrimitiveC { + public: + Equal() : PrimitiveC(kNameEqual) { InitIOName({"x", "y"}, {"output"}); } + ~Equal() = default; + MS_DECLARE_PARENT(Equal, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_EQUAL_H_ diff --git a/mindspore/core/c_ops/exp.cc b/mindspore/core/c_ops/exp.cc new file mode 100644 index 0000000000..15076dcf94 --- /dev/null +++ b/mindspore/core/c_ops/exp.cc @@ -0,0 +1,20 @@ +/** + * 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 "c_ops/exp.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameExp, Exp); +} // namespace mindspore diff --git a/mindspore/core/c_ops/exp.h b/mindspore/core/c_ops/exp.h new file mode 100644 index 0000000000..0236997bf0 --- /dev/null +++ b/mindspore/core/c_ops/exp.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_EXP_H_ +#define MINDSPORE_CORE_C_OPS_EXP_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameExp = "Exp"; +class Exp : public PrimitiveC { + public: + Exp() : PrimitiveC(kNameExp) { InitIOName({"x"}, {"y"}); } + ~Exp() = default; + MS_DECLARE_PARENT(Exp, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_EXP_H_ diff --git a/mindspore/core/c_ops/expand_dims.cc b/mindspore/core/c_ops/expand_dims.cc new file mode 100644 index 0000000000..66cc5addf3 --- /dev/null +++ b/mindspore/core/c_ops/expand_dims.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/expand_dims.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameExpandDims, ExpandDims); +} // namespace mindspore diff --git a/mindspore/core/c_ops/expand_dims.h b/mindspore/core/c_ops/expand_dims.h new file mode 100644 index 0000000000..ba935122ac --- /dev/null +++ b/mindspore/core/c_ops/expand_dims.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_EXPANDDIMS_H_ +#define MINDSPORE_CORE_C_OPS_EXPANDDIMS_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameExpandDims = "ExpandDims"; +class ExpandDims : public PrimitiveC { + public: + ExpandDims() : PrimitiveC(kNameExpandDims) { InitIOName({"x", "axis"}, {"output"}); } + ~ExpandDims() = default; + MS_DECLARE_PARENT(ExpandDims, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_EXPANDDIMS_H_ diff --git a/mindspore/core/c_ops/fake_quant_with_min_max_vars.cc b/mindspore/core/c_ops/fake_quant_with_min_max_vars.cc new file mode 100644 index 0000000000..2e8b029b0a --- /dev/null +++ b/mindspore/core/c_ops/fake_quant_with_min_max_vars.cc @@ -0,0 +1,44 @@ +/** + * 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 "c_ops/fake_quant_with_min_max_vars.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +void FakeQuantWithMinMaxVars::Init(const bool &narrow_range, int64_t num_bits) { + this->set_narrow_range(narrow_range); + this->set_num_bits(num_bits); +} + +void FakeQuantWithMinMaxVars::set_narrow_range(const bool &narrow_range) { + this->AddAttr(kNarrowRange, MakeValue(narrow_range)); +} + +bool FakeQuantWithMinMaxVars::get_narrow_range() const { + auto value_ptr = this->GetAttr(kNarrowRange); + return GetValue(value_ptr); +} + +void FakeQuantWithMinMaxVars::set_num_bits(int64_t num_bits) { this->AddAttr(kNumBits, MakeValue(num_bits)); } + +int64_t FakeQuantWithMinMaxVars::get_num_bits() const { + auto value_ptr = this->GetAttr(kNumBits); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameFakeQuantWithMinMaxVars, FakeQuantWithMinMaxVars); +} // namespace mindspore diff --git a/mindspore/core/c_ops/fake_quant_with_min_max_vars.h b/mindspore/core/c_ops/fake_quant_with_min_max_vars.h new file mode 100644 index 0000000000..7af9f959a2 --- /dev/null +++ b/mindspore/core/c_ops/fake_quant_with_min_max_vars.h @@ -0,0 +1,41 @@ +/** + * 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_C_OPS_FAKEQUANTWITHMINMAXVARS_H_ +#define MINDSPORE_CORE_C_OPS_FAKEQUANTWITHMINMAXVARS_H_ +#include + +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameFakeQuantWithMinMaxVars = "FakeQuantWithMinMaxVars"; +class FakeQuantWithMinMaxVars : public PrimitiveC { + public: + FakeQuantWithMinMaxVars() : PrimitiveC(kNameFakeQuantWithMinMaxVars) {} + ~FakeQuantWithMinMaxVars() = default; + MS_DECLARE_PARENT(FakeQuantWithMinMaxVars, PrimitiveC); + void Init(const bool &narrow_range, int64_t num_bits); + void set_narrow_range(const bool &narrow_range); + void set_num_bits(int64_t num_bits); + bool get_narrow_range() const; + int64_t get_num_bits() const; +}; + +using PrimFakeQuantWithMinMaxVarsPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_FAKEQUANTWITHMINMAXVARS_H_ diff --git a/mindspore/core/c_ops/fft_imag.cc b/mindspore/core/c_ops/fft_imag.cc new file mode 100644 index 0000000000..ef63040e83 --- /dev/null +++ b/mindspore/core/c_ops/fft_imag.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/fft_imag.h" +#include + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameFftImag, FftImag); +} diff --git a/mindspore/core/c_ops/fft_imag.h b/mindspore/core/c_ops/fft_imag.h new file mode 100644 index 0000000000..4a055a2641 --- /dev/null +++ b/mindspore/core/c_ops/fft_imag.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_FFTIMAG_H_ +#define MINDSPORE_CORE_C_OPS_FFTIMAG_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameFftImag = "FftImag"; +class FftImag : public PrimitiveC { + public: + FftImag() : PrimitiveC(kNameFftImag) {} + ~FftImag() = default; + MS_DECLARE_PARENT(FftImag, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_FFTIMAG_H_ diff --git a/mindspore/core/c_ops/fill.cc b/mindspore/core/c_ops/fill.cc new file mode 100644 index 0000000000..70b211700e --- /dev/null +++ b/mindspore/core/c_ops/fill.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/fill.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameFill, Fill); +} // namespace mindspore diff --git a/mindspore/core/c_ops/fill.h b/mindspore/core/c_ops/fill.h new file mode 100644 index 0000000000..e3b3794ba3 --- /dev/null +++ b/mindspore/core/c_ops/fill.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_FILL_H_ +#define MINDSPORE_CORE_C_OPS_FILL_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameFill = "Fill"; +class Fill : public PrimitiveC { + public: + Fill() : PrimitiveC(kNameFill) {} + ~Fill() = default; + MS_DECLARE_PARENT(Fill, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_FILL_H_ diff --git a/mindspore/core/c_ops/flatten.cc b/mindspore/core/c_ops/flatten.cc new file mode 100644 index 0000000000..2556b9feae --- /dev/null +++ b/mindspore/core/c_ops/flatten.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/flatten.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameFlatten, Flatten); +} // namespace mindspore diff --git a/mindspore/core/c_ops/flatten.h b/mindspore/core/c_ops/flatten.h new file mode 100644 index 0000000000..6bbc6a8725 --- /dev/null +++ b/mindspore/core/c_ops/flatten.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_FLATTEN_H_ +#define MINDSPORE_CORE_C_OPS_FLATTEN_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameFlatten = "Flatten"; +class Flatten : public PrimitiveC { + public: + Flatten() : PrimitiveC(kNameFlatten) {} + ~Flatten() = default; + MS_DECLARE_PARENT(Flatten, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_FLATTEN_H_ diff --git a/mindspore/core/c_ops/flatten_grad.cc b/mindspore/core/c_ops/flatten_grad.cc new file mode 100644 index 0000000000..24c7c93282 --- /dev/null +++ b/mindspore/core/c_ops/flatten_grad.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/flatten_grad.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameFlattenGrad, FlattenGrad); +} diff --git a/mindspore/core/c_ops/flatten_grad.h b/mindspore/core/c_ops/flatten_grad.h new file mode 100644 index 0000000000..eb45bde44a --- /dev/null +++ b/mindspore/core/c_ops/flatten_grad.h @@ -0,0 +1,40 @@ +/** + * 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_C_OPS_FLATTEN_GRAD_H_ +#define MINDSPORE_CORE_C_OPS_FLATTEN_GRAD_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameFlattenGrad = "FlattenGrad"; +class FlattenGrad : public PrimitiveC { + public: + FlattenGrad() : PrimitiveC(kNameFlattenGrad) { InitIOName({"x", "shape"}, {"output"}); } + ~FlattenGrad() = default; + MS_DECLARE_PARENT(FlattenGrad, PrimitiveC); +}; + +AbstractBasePtr FlattenGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimFlattenGrad = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_FlattenGrad_H_ diff --git a/mindspore/core/c_ops/floor.cc b/mindspore/core/c_ops/floor.cc new file mode 100644 index 0000000000..8dc8cf09dd --- /dev/null +++ b/mindspore/core/c_ops/floor.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/floor.h" +#include + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameFloor, Floor); +} // namespace mindspore diff --git a/mindspore/core/c_ops/floor.h b/mindspore/core/c_ops/floor.h new file mode 100644 index 0000000000..2b12ccb9a8 --- /dev/null +++ b/mindspore/core/c_ops/floor.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_FLOOR_H_ +#define MINDSPORE_CORE_C_OPS_FLOOR_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameFloor = "Floor"; +class Floor : public PrimitiveC { + public: + Floor() : PrimitiveC(kNameFloor) { InitIOName({"x"}, {"y"}); } + ~Floor() = default; + MS_DECLARE_PARENT(Floor, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_FLOOR_H_ diff --git a/mindspore/core/c_ops/floor_div.cc b/mindspore/core/c_ops/floor_div.cc new file mode 100644 index 0000000000..e23149e99c --- /dev/null +++ b/mindspore/core/c_ops/floor_div.cc @@ -0,0 +1,20 @@ +/** + * 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 "c_ops/floor_div.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameFloorDiv, FloorDiv); +} // namespace mindspore diff --git a/mindspore/core/c_ops/floor_div.h b/mindspore/core/c_ops/floor_div.h new file mode 100644 index 0000000000..2f707afa23 --- /dev/null +++ b/mindspore/core/c_ops/floor_div.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_FLOORDIV_H_ +#define MINDSPORE_CORE_C_OPS_FLOORDIV_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameFloorDiv = "FloorDiv"; +class FloorDiv : public PrimitiveC { + public: + FloorDiv() : PrimitiveC(kNameFloorDiv) { InitIOName({"x", "y"}, {"output"}); } + ~FloorDiv() = default; + MS_DECLARE_PARENT(FloorDiv, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_FLOORDIV_H_ diff --git a/mindspore/core/c_ops/floor_mod.cc b/mindspore/core/c_ops/floor_mod.cc new file mode 100644 index 0000000000..dc8764ed0e --- /dev/null +++ b/mindspore/core/c_ops/floor_mod.cc @@ -0,0 +1,20 @@ +/** + * 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 "c_ops/floor_mod.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameFloorMod, FloorMod); +} // namespace mindspore diff --git a/mindspore/core/c_ops/floor_mod.h b/mindspore/core/c_ops/floor_mod.h new file mode 100644 index 0000000000..3e0aff92f4 --- /dev/null +++ b/mindspore/core/c_ops/floor_mod.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_FLOORMOD_H_ +#define MINDSPORE_CORE_C_OPS_FLOORMOD_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameFloorMod = "FloorMod"; +class FloorMod : public PrimitiveC { + public: + FloorMod() : PrimitiveC(kNameFloorMod) { InitIOName({"x", "y"}, {"output"}); } + ~FloorMod() = default; + MS_DECLARE_PARENT(FloorMod, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_FLOORMOD_H_ diff --git a/mindspore/core/c_ops/gather.cc b/mindspore/core/c_ops/gather.cc new file mode 100644 index 0000000000..00ffbfe577 --- /dev/null +++ b/mindspore/core/c_ops/gather.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/gather.h" +#include + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameGather, Gather); +} // namespace mindspore diff --git a/mindspore/core/c_ops/gather.h b/mindspore/core/c_ops/gather.h new file mode 100644 index 0000000000..b01d350802 --- /dev/null +++ b/mindspore/core/c_ops/gather.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_GATHER_H_ +#define MINDSPORE_CORE_C_OPS_GATHER_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameGather = "Gather"; +class Gather : public PrimitiveC { + public: + Gather() : PrimitiveC(kNameGather) { InitIOName({"x", "dim", "index"}, {"output"}); } + ~Gather() = default; + MS_DECLARE_PARENT(Gather, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_GATHER_H_ diff --git a/mindspore/core/c_ops/gather_nd.cc b/mindspore/core/c_ops/gather_nd.cc new file mode 100644 index 0000000000..a017eed576 --- /dev/null +++ b/mindspore/core/c_ops/gather_nd.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/gather_nd.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameGatherNd, GatherNd); +} // namespace mindspore diff --git a/mindspore/core/c_ops/gather_nd.h b/mindspore/core/c_ops/gather_nd.h new file mode 100644 index 0000000000..1ea7ad69c7 --- /dev/null +++ b/mindspore/core/c_ops/gather_nd.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_GATHERND_H_ +#define MINDSPORE_CORE_C_OPS_GATHERND_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameGatherNd = "GatherNd"; +class GatherNd : public PrimitiveC { + public: + GatherNd() : PrimitiveC(kNameGatherNd) { InitIOName({"input_x", "indices"}, {"y"}); } + ~GatherNd() = default; + MS_DECLARE_PARENT(GatherNd, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_GATHERND_H_ diff --git a/mindspore/core/c_ops/greater.cc b/mindspore/core/c_ops/greater.cc new file mode 100644 index 0000000000..22e902d771 --- /dev/null +++ b/mindspore/core/c_ops/greater.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/greater.h" +#include + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameGreater, Greater); +} // namespace mindspore diff --git a/mindspore/core/c_ops/greater.h b/mindspore/core/c_ops/greater.h new file mode 100644 index 0000000000..9dfae66b59 --- /dev/null +++ b/mindspore/core/c_ops/greater.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_GREATER_H_ +#define MINDSPORE_CORE_C_OPS_GREATER_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameGreater = "Greater"; +class Greater : public PrimitiveC { + public: + Greater() : PrimitiveC(kNameGreater) { InitIOName({"x", "y"}, {"output"}); } + ~Greater() = default; + MS_DECLARE_PARENT(Greater, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_GREATER_H_ diff --git a/mindspore/core/c_ops/greater_equal.cc b/mindspore/core/c_ops/greater_equal.cc new file mode 100644 index 0000000000..d9d32e15b9 --- /dev/null +++ b/mindspore/core/c_ops/greater_equal.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/greater_equal.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameGreaterEqual, GreaterEqual); +} diff --git a/mindspore/core/c_ops/greater_equal.h b/mindspore/core/c_ops/greater_equal.h new file mode 100644 index 0000000000..0dc946a1fc --- /dev/null +++ b/mindspore/core/c_ops/greater_equal.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_GREATEREQUAL_H_ +#define MINDSPORE_CORE_C_OPS_GREATEREQUAL_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" + +namespace mindspore { +constexpr auto kNameGreaterEqual = "GreaterEqual"; +class GreaterEqual : public PrimitiveC { + public: + GreaterEqual() : PrimitiveC(kNameGreaterEqual) {} + ~GreaterEqual() = default; + MS_DECLARE_PARENT(GreaterEqual, PrimitiveC); +}; +AbstractBasePtr GreaterEqualInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimGreaterEqual = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_GREATEREQUAL_H_ diff --git a/mindspore/core/c_ops/hashtable_lookup.cc b/mindspore/core/c_ops/hashtable_lookup.cc new file mode 100644 index 0000000000..145b456419 --- /dev/null +++ b/mindspore/core/c_ops/hashtable_lookup.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/hashtable_lookup.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameHashtableLookup, HashtableLookup); +} // namespace mindspore diff --git a/mindspore/core/c_ops/hashtable_lookup.h b/mindspore/core/c_ops/hashtable_lookup.h new file mode 100644 index 0000000000..bd4f8edc49 --- /dev/null +++ b/mindspore/core/c_ops/hashtable_lookup.h @@ -0,0 +1,37 @@ +/** + * 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_C_OPS_HASHTABLELOOKUP_H_ +#define MINDSPORE_CORE_C_OPS_HASHTABLELOOKUP_H_ +#include + +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameHashtableLookup = "HashtableLookup"; +class HashtableLookup : public PrimitiveC { + public: + HashtableLookup() : PrimitiveC(kNameHashtableLookup) {} + ~HashtableLookup() = default; + MS_DECLARE_PARENT(HashtableLookup, PrimitiveC); + void Init() {} +}; + +using PrimHashtableLookupPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_HASHTABLELOOKUP_H_ diff --git a/mindspore/core/c_ops/identity.cc b/mindspore/core/c_ops/identity.cc new file mode 100644 index 0000000000..2f42f95cf0 --- /dev/null +++ b/mindspore/core/c_ops/identity.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/identity.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameIdentity, Identity); +} // namespace mindspore diff --git a/mindspore/core/c_ops/identity.h b/mindspore/core/c_ops/identity.h new file mode 100644 index 0000000000..2469736933 --- /dev/null +++ b/mindspore/core/c_ops/identity.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_IDENTITY_H_ +#define MINDSPORE_CORE_C_OPS_IDENTITY_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameIdentity = "Identity"; +class Identity : public PrimitiveC { + public: + Identity() : PrimitiveC(kNameIdentity) {} + ~Identity() = default; + MS_DECLARE_PARENT(Identity, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_IDENTITY_H_ diff --git a/mindspore/core/c_ops/instance_norm.cc b/mindspore/core/c_ops/instance_norm.cc new file mode 100644 index 0000000000..df5e31c17a --- /dev/null +++ b/mindspore/core/c_ops/instance_norm.cc @@ -0,0 +1,37 @@ +/** + * 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 "c_ops/instance_norm.h" +#include +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { + +void InstanceNorm::set_epsilon(const float &epsilon) { this->AddAttr(kEpsilon, MakeValue(epsilon)); } +float InstanceNorm::get_epsilon() const { + auto value_ptr = GetAttr(kEpsilon); + return GetValue(value_ptr); +} + +void InstanceNorm::Init(const float &epsilon) { this->set_epsilon(epsilon); } +REGISTER_PRIMITIVE_C(kNameInstanceNorm, InstanceNorm); +} // namespace mindspore diff --git a/mindspore/core/c_ops/instance_norm.h b/mindspore/core/c_ops/instance_norm.h new file mode 100644 index 0000000000..4012c70846 --- /dev/null +++ b/mindspore/core/c_ops/instance_norm.h @@ -0,0 +1,40 @@ +/** + * 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_C_OPS_INSTANCENORM_H_ +#define MINDSPORE_CORE_C_OPS_INSTANCENORM_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameInstanceNorm = "InstanceNorm"; +class InstanceNorm : public PrimitiveC { + public: + InstanceNorm() : PrimitiveC(kNameInstanceNorm) {} + ~InstanceNorm() = default; + MS_DECLARE_PARENT(InstanceNorm, PrimitiveC); + void Init(const float &epsilon = 0.00001); + void set_epsilon(const float &epsilon); + float get_epsilon() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_INSTANCENORM_H_ diff --git a/mindspore/core/c_ops/l2_normalize.cc b/mindspore/core/c_ops/l2_normalize.cc new file mode 100644 index 0000000000..e9ef6a7d29 --- /dev/null +++ b/mindspore/core/c_ops/l2_normalize.cc @@ -0,0 +1,39 @@ +/** + * 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 "c_ops/l2_normalize.h" + +namespace mindspore { +void L2Normalize::Init(int64_t axis, float epsilon) { + this->set_axis(axis); + this->set_epsilon(epsilon); +} + +void L2Normalize::set_axis(int64_t axis) { AddAttr(kAxis, MakeValue(axis)); } + +void L2Normalize::set_epsilon(float epsilon) { AddAttr(kEpsilon, MakeValue(epsilon)); } + +int64_t L2Normalize::get_axis() { + auto value_ptr = GetAttr(kAxis); + return GetValue(value_ptr); +} + +float L2Normalize::get_epsilon() { + auto value_ptr = GetAttr(kEpsilon); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameL2Normalize, L2Normalize); +} // namespace mindspore diff --git a/mindspore/core/c_ops/l2_normalize.h b/mindspore/core/c_ops/l2_normalize.h new file mode 100644 index 0000000000..cfc9851b48 --- /dev/null +++ b/mindspore/core/c_ops/l2_normalize.h @@ -0,0 +1,44 @@ +/** + * 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_C_OPS_L2NORMALIZE_H_ +#define MINDSPORE_CORE_C_OPS_L2NORMALIZE_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameL2Normalize = "L2Normalize"; +class L2Normalize : public PrimitiveC { + public: + L2Normalize() : PrimitiveC(kNameL2Normalize) {} + ~L2Normalize() = default; + MS_DECLARE_PARENT(L2Normalize, PrimitiveC); + void Init(int64_t axis = 0, float epsilon = 1e-4); + void set_axis(int64_t axis); + void set_epsilon(float epsilon); + int64_t get_axis(); + float get_epsilon(); +}; +AbstractBasePtr L2NormalizeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimL2Normalize = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_L2NORMALIZE_H_ diff --git a/mindspore/core/c_ops/layer_norm.cc b/mindspore/core/c_ops/layer_norm.cc new file mode 100644 index 0000000000..364aac1ecb --- /dev/null +++ b/mindspore/core/c_ops/layer_norm.cc @@ -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. + */ + +#include "c_ops/layer_norm.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +void LayerNorm::Init(int64_t begin_norm_axis, int64_t begin_params_axis, float epsilon) { + this->set_begin_norm_axis(begin_norm_axis); + this->set_begin_params_axis(begin_params_axis); + this->set_epsilon(epsilon); +} +void LayerNorm::set_begin_norm_axis(int64_t begin_norm_axis) { + this->AddAttr(kBeginNormAxis, MakeValue(begin_norm_axis)); +} +void LayerNorm::set_begin_params_axis(int64_t begin_params_axis) { + this->AddAttr(kBeginParamsAxis, MakeValue(begin_params_axis)); +} +void LayerNorm::set_epsilon(float epsilon) { this->AddAttr(kEpsilon, MakeValue(epsilon)); } + +int64_t LayerNorm::get_begin_norm_axis() { + auto value_ptr = this->GetAttr(kBeginNormAxis); + return GetValue(value_ptr); +} +int64_t LayerNorm::get_begin_params_axis() { + auto value_ptr = this->GetAttr(kBeginParamsAxis); + return GetValue(value_ptr); +} +float LayerNorm::get_epsilon() { + auto value_ptr = this->GetAttr(kEpsilon); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameLayerNorm, LayerNorm); +} // namespace mindspore diff --git a/mindspore/core/c_ops/layer_norm.h b/mindspore/core/c_ops/layer_norm.h new file mode 100644 index 0000000000..1781d22747 --- /dev/null +++ b/mindspore/core/c_ops/layer_norm.h @@ -0,0 +1,40 @@ +/** + * 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_C_OPS_LAYERNORM_H_ +#define MINDSPORE_CORE_C_OPS_LAYERNORM_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLayerNorm = "LayerNorm"; +class LayerNorm : public PrimitiveC { + public: + LayerNorm() : PrimitiveC(kNameLayerNorm) {} + ~LayerNorm() = default; + MS_DECLARE_PARENT(LayerNorm, PrimitiveC); + void Init(int64_t begin_norm_axis = 1, int64_t begin_params_axis = 1, float epsilon = 1e-7); + void set_begin_norm_axis(int64_t begin_norm_axis); + void set_begin_params_axis(int64_t begin_params_axis); + void set_epsilon(float epsilon); + int64_t get_begin_norm_axis(); + int64_t get_begin_params_axis(); + float get_epsilon(); +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LAYERNORM_H_ diff --git a/mindspore/core/c_ops/less.cc b/mindspore/core/c_ops/less.cc new file mode 100644 index 0000000000..f7e89ee28f --- /dev/null +++ b/mindspore/core/c_ops/less.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/less.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameLess, Less); +} diff --git a/mindspore/core/c_ops/less.h b/mindspore/core/c_ops/less.h new file mode 100644 index 0000000000..f78441e010 --- /dev/null +++ b/mindspore/core/c_ops/less.h @@ -0,0 +1,39 @@ +/** + * 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_C_OPS_LESS_H_ +#define MINDSPORE_CORE_C_OPS_LESS_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLess = "Less"; +class Less : public PrimitiveC { + public: + Less() : PrimitiveC(kNameLess) { InitIOName({"x", "y"}, {"output"}); } + ~Less() = default; + MS_DECLARE_PARENT(Less, PrimitiveC); +}; +AbstractBasePtr LessInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimLess = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_LESS_H_ diff --git a/mindspore/core/c_ops/less_equal.cc b/mindspore/core/c_ops/less_equal.cc new file mode 100644 index 0000000000..6efc85d9bd --- /dev/null +++ b/mindspore/core/c_ops/less_equal.cc @@ -0,0 +1,20 @@ +/** + * 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 "c_ops/less_equal.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameLessEqual, LessEqual); +} // namespace mindspore diff --git a/mindspore/core/c_ops/less_equal.h b/mindspore/core/c_ops/less_equal.h new file mode 100644 index 0000000000..1f95a04802 --- /dev/null +++ b/mindspore/core/c_ops/less_equal.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_LESSEQUAL_H_ +#define MINDSPORE_CORE_C_OPS_LESSEQUAL_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLessEqual = "LessEqual"; +class LessEqual : public PrimitiveC { + public: + LessEqual() : PrimitiveC(kNameLessEqual) { InitIOName({"x", "y"}, {"output"}); } + ~LessEqual() = default; + MS_DECLARE_PARENT(LessEqual, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LESSEQUAL_H_ diff --git a/mindspore/core/c_ops/local_response_normalization.cc b/mindspore/core/c_ops/local_response_normalization.cc new file mode 100644 index 0000000000..2ade03e083 --- /dev/null +++ b/mindspore/core/c_ops/local_response_normalization.cc @@ -0,0 +1,65 @@ +/** + * 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 "c_ops/local_response_normalization.h" +#include +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +void LocalResponseNormalization::set_depth_radius(const int64_t &depth_radius) { + this->AddAttr(kDepthRadius, MakeValue(depth_radius)); +} + +int64_t LocalResponseNormalization::get_depth_radius() const { + auto value_ptr = GetAttr(kDepthRadius); + return GetValue(value_ptr); +} + +void LocalResponseNormalization::set_bias(const float &bias) { this->AddAttr(kBias, MakeValue(bias)); } + +float LocalResponseNormalization::get_bias() const { + auto value_ptr = GetAttr(kBias); + return GetValue(value_ptr); +} + +void LocalResponseNormalization::set_alpha(const float &alpha) { this->AddAttr(kAlpha, MakeValue(alpha)); } + +float LocalResponseNormalization::get_alpha() const { + auto value_ptr = GetAttr(kAlpha); + return GetValue(value_ptr); +} + +void LocalResponseNormalization::set_beta(const float &beta) { this->AddAttr(kBeta, MakeValue(beta)); } + +float LocalResponseNormalization::get_beta() const { + auto value_ptr = GetAttr(kBeta); + return GetValue(value_ptr); +} +void LocalResponseNormalization::Init(const int64_t &depth_radius, const float &bias, const float &alpha, + const float &beta) { + this->set_depth_radius(depth_radius); + this->set_bias(bias); + this->set_alpha(alpha); + this->set_beta(beta); +} +REGISTER_PRIMITIVE_C(kNameLocalResponseNormalization, LocalResponseNormalization); +} // namespace mindspore diff --git a/mindspore/core/c_ops/local_response_normalization.h b/mindspore/core/c_ops/local_response_normalization.h new file mode 100644 index 0000000000..81e52d9105 --- /dev/null +++ b/mindspore/core/c_ops/local_response_normalization.h @@ -0,0 +1,47 @@ +/** + * 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_C_OPS_LOCALRESPONSENORMALIZATION_H_ +#define MINDSPORE_CORE_C_OPS_LOCALRESPONSENORMALIZATION_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLocalResponseNormalization = "LocalResponseNormalization"; +class LocalResponseNormalization : public PrimitiveC { + public: + LocalResponseNormalization() : PrimitiveC(kNameLocalResponseNormalization) {} + ~LocalResponseNormalization() = default; + MS_DECLARE_PARENT(LocalResponseNormalization, PrimitiveC); + void Init(const int64_t &depth_radius, const float &bias, const float &alpha, const float &beta); + void set_depth_radius(const int64_t &depth_radius); + void set_bias(const float &bias); + void set_alpha(const float &alpha); + void set_beta(const float &beta); + + int64_t get_depth_radius() const; + float get_bias() const; + float get_alpha() const; + float get_beta() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LOCALRESPONSENORMALIZATION_H_ diff --git a/mindspore/core/c_ops/log.cc b/mindspore/core/c_ops/log.cc new file mode 100644 index 0000000000..f3703c5cf8 --- /dev/null +++ b/mindspore/core/c_ops/log.cc @@ -0,0 +1,21 @@ +/** + * 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 "c_ops/log.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameLog, Log); +} diff --git a/mindspore/core/c_ops/log.h b/mindspore/core/c_ops/log.h new file mode 100644 index 0000000000..62e6142805 --- /dev/null +++ b/mindspore/core/c_ops/log.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_LOG_H_ +#define MINDSPORE_CORE_C_OPS_LOG_H_ +#include +#include + +#include "c_ops/primitive_c.h" +#include "c_ops/op_utils.h" +#include "abstract/abstract_value.h" + +namespace mindspore { +constexpr auto kNameLog = "Log"; +class Log : public PrimitiveC { + public: + Log() : PrimitiveC(kNameLog) { InitIOName({"x"}, {"y"}); } + ~Log() = default; + MS_DECLARE_PARENT(Log, PrimitiveC); +}; +AbstractBasePtr LogInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimLog = std::shared_ptr; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_LOG_H_ diff --git a/mindspore/core/c_ops/log_grad.cc b/mindspore/core/c_ops/log_grad.cc new file mode 100644 index 0000000000..26b6327ce3 --- /dev/null +++ b/mindspore/core/c_ops/log_grad.cc @@ -0,0 +1,29 @@ +/** + * 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 "c_ops/log_grad.h" +#include +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameLogGrad, LogGrad); +} diff --git a/mindspore/core/c_ops/log_grad.h b/mindspore/core/c_ops/log_grad.h new file mode 100644 index 0000000000..bb43cc5908 --- /dev/null +++ b/mindspore/core/c_ops/log_grad.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_LOGGRAD_H_ +#define MINDSPORE_CORE_C_OPS_LOGGRAD_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLogGrad = "LogGrad"; +class LogGrad : public PrimitiveC { + public: + LogGrad() : PrimitiveC(kNameLogGrad) {} + ~LogGrad() = default; + MS_DECLARE_PARENT(LogGrad, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LOGGRAD_H_ diff --git a/mindspore/core/c_ops/logical_and.cc b/mindspore/core/c_ops/logical_and.cc new file mode 100644 index 0000000000..826f0a5468 --- /dev/null +++ b/mindspore/core/c_ops/logical_and.cc @@ -0,0 +1,22 @@ +/** + * 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 "c_ops/logical_and.h" +#include + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameLogicalAnd, LogicalAnd); +} // namespace mindspore diff --git a/mindspore/core/c_ops/logical_and.h b/mindspore/core/c_ops/logical_and.h new file mode 100644 index 0000000000..3e579e4e4b --- /dev/null +++ b/mindspore/core/c_ops/logical_and.h @@ -0,0 +1,38 @@ +/** + * 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_C_OPS_LOGICAL_AND_H_ +#define MINDSPORE_CORE_C_OPS_LOGICAL_AND_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLogicalAnd = "LogicalAnd"; +class LogicalAnd : public PrimitiveC { + public: + LogicalAnd() : PrimitiveC(kNameLogicalAnd) { InitIOName({"x", "y"}, {"output"}); } + ~LogicalAnd() = default; + MS_DECLARE_PARENT(LogicalAnd, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LOGICAL_AND_H_ diff --git a/mindspore/core/c_ops/logical_not.cc b/mindspore/core/c_ops/logical_not.cc new file mode 100644 index 0000000000..f701cc1aae --- /dev/null +++ b/mindspore/core/c_ops/logical_not.cc @@ -0,0 +1,20 @@ +/** + * 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 "c_ops/logical_not.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameLogicalNot, LogicalNot); +} // namespace mindspore diff --git a/mindspore/core/c_ops/logical_not.h b/mindspore/core/c_ops/logical_not.h new file mode 100644 index 0000000000..0ba1eae6fe --- /dev/null +++ b/mindspore/core/c_ops/logical_not.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_LOGICALNOT_H_ +#define MINDSPORE_CORE_C_OPS_LOGICALNOT_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLogicalNot = "LogicalNot"; +class LogicalNot : public PrimitiveC { + public: + LogicalNot() : PrimitiveC(kNameLogicalNot) { InitIOName({"x"}, {"output"}); } + ~LogicalNot() = default; + MS_DECLARE_PARENT(LogicalNot, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LOGICALNOT_H_ diff --git a/mindspore/core/c_ops/logical_or.cc b/mindspore/core/c_ops/logical_or.cc new file mode 100644 index 0000000000..1b9131ff08 --- /dev/null +++ b/mindspore/core/c_ops/logical_or.cc @@ -0,0 +1,20 @@ +/** + * 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 "c_ops/logical_or.h" + +namespace mindspore { +REGISTER_PRIMITIVE_C(kNameLogicalOr, LogicalOr); +} // namespace mindspore diff --git a/mindspore/core/c_ops/logical_or.h b/mindspore/core/c_ops/logical_or.h new file mode 100644 index 0000000000..d9dc683d88 --- /dev/null +++ b/mindspore/core/c_ops/logical_or.h @@ -0,0 +1,34 @@ +/** + * 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_C_OPS_LOGICALOR_H_ +#define MINDSPORE_CORE_C_OPS_LOGICALOR_H_ +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLogicalOr = "LogicalOr"; +class LogicalOr : public PrimitiveC { + public: + LogicalOr() : PrimitiveC(kNameLogicalOr) { InitIOName({"x", "y"}, {"output"}); } + ~LogicalOr() = default; + MS_DECLARE_PARENT(LogicalOr, PrimitiveC); + void Init() {} +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LOGICALOR_H_ diff --git a/mindspore/core/c_ops/loop.cc b/mindspore/core/c_ops/loop.cc new file mode 100644 index 0000000000..793f4e0ae1 --- /dev/null +++ b/mindspore/core/c_ops/loop.cc @@ -0,0 +1,31 @@ +/** + * 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 "c_ops/loop.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +void Loop::Init(int64_t sub_graph_index) { this->set_sub_graph_index(sub_graph_index); } + +void Loop::set_sub_graph_index(int64_t sub_graph_index) { this->AddAttr(kSubGraphIndex, MakeValue(sub_graph_index)); } + +int64_t Loop::get_sub_graph_index() const { + auto value_ptr = this->GetAttr(kSubGraphIndex); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameLoop, Loop); +} // namespace mindspore diff --git a/mindspore/core/c_ops/loop.h b/mindspore/core/c_ops/loop.h new file mode 100644 index 0000000000..e3f88811b6 --- /dev/null +++ b/mindspore/core/c_ops/loop.h @@ -0,0 +1,40 @@ +/** + * 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_C_OPS_LOOP_H_ +#define MINDSPORE_CORE_C_OPS_LOOP_H_ +#include + +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLoop = "Loop"; +class Loop : public PrimitiveC { + public: + Loop() : PrimitiveC(kNameLoop) {} + ~Loop() = default; + MS_DECLARE_PARENT(Loop, PrimitiveC); + void Init(int64_t sub_graph_index); + void set_sub_graph_index(int64_t sub_graph_index); + int64_t get_sub_graph_index() const; +}; + +using PrimLoopPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LOOP_H_ diff --git a/mindspore/core/c_ops/lp_normalization.cc b/mindspore/core/c_ops/lp_normalization.cc new file mode 100644 index 0000000000..ef6763fad1 --- /dev/null +++ b/mindspore/core/c_ops/lp_normalization.cc @@ -0,0 +1,41 @@ +/** + * 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 "c_ops/lp_normalization.h" +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +void LpNormalization::Init(int64_t axis, int64_t p) { + this->set_axis(axis); + this->set_p(p); +} + +void LpNormalization::set_axis(int64_t axis) { this->AddAttr(kAxis, MakeValue(axis)); } + +int64_t LpNormalization::get_axis() const { + auto value_ptr = this->GetAttr(kAxis); + return GetValue(value_ptr); +} + +void LpNormalization::set_p(int64_t p) { this->AddAttr(kP, MakeValue(p)); } + +int64_t LpNormalization::get_p() const { + auto value_ptr = this->GetAttr(kP); + return GetValue(value_ptr); +} +REGISTER_PRIMITIVE_C(kNameLpNormalization, LpNormalization); +} // namespace mindspore diff --git a/mindspore/core/c_ops/lp_normalization.h b/mindspore/core/c_ops/lp_normalization.h new file mode 100644 index 0000000000..969219e874 --- /dev/null +++ b/mindspore/core/c_ops/lp_normalization.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_C_OPS_LPNORMALIZATION_H_ +#define MINDSPORE_CORE_C_OPS_LPNORMALIZATION_H_ +#include + +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLpNormalization = "LpNormalization"; +class LpNormalization : public PrimitiveC { + public: + LpNormalization() : PrimitiveC(kNameLpNormalization) {} + ~LpNormalization() = default; + MS_DECLARE_PARENT(LpNormalization, PrimitiveC); + void Init(int64_t axis, int64_t p); + void set_axis(int64_t axis); + void set_p(int64_t p); + int64_t get_axis() const; + int64_t get_p() const; +}; + +using PrimLpNormalizationPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LPNORMALIZATION_H_ diff --git a/mindspore/core/c_ops/lrn.cc b/mindspore/core/c_ops/lrn.cc new file mode 100644 index 0000000000..ca0a1d1086 --- /dev/null +++ b/mindspore/core/c_ops/lrn.cc @@ -0,0 +1,76 @@ +/** + * 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 "c_ops/lrn.h" +#include +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "utils/check_convert_utils.h" +#include "abstract/primitive_infer_map.h" + +namespace mindspore { +void Lrn::set_depth_radius(const int64_t &depth_radius) { + CheckAndConvertUtils::CheckInteger(kDepthRadius, depth_radius, kGreaterEqual, 0, this->name()); + this->AddAttr(kDepthRadius, MakeValue(depth_radius)); +} + +int64_t Lrn::get_depth_radius() const { + auto value_ptr = GetAttr(kDepthRadius); + return GetValue(value_ptr); +} + +void Lrn::set_bias(const float &bias) { this->AddAttr(kBias, MakeValue(bias)); } + +float Lrn::get_bias() const { + auto value_ptr = GetAttr(kBias); + return GetValue(value_ptr); +} + +void Lrn::set_alpha(const float &alpha) { this->AddAttr(kAlpha, MakeValue(alpha)); } + +float Lrn::get_alpha() const { + auto value_ptr = GetAttr(kAlpha); + return GetValue(value_ptr); +} + +void Lrn::set_beta(const float &beta) { this->AddAttr(kBeta, MakeValue(beta)); } + +float Lrn::get_beta() const { + auto value_ptr = GetAttr(kBeta); + return GetValue(value_ptr); +} +void Lrn::set_norm_region(const std::string &norm_region) { + CheckAndConvertUtils::CheckString(kNormRegion, norm_region, {"ACROSS_CHANNELS"}, this->name()); + this->AddAttr(kNormRegion, MakeValue(norm_region)); +} + +std::string Lrn::get_norm_region() const { + auto value_ptr = GetAttr(kNormRegion); + return GetValue(value_ptr); +} +void Lrn::Init(const int64_t &depth_radius, const float &bias, const float &alpha, const float &beta, + const std::string &norm_region) { + this->set_depth_radius(depth_radius); + this->set_bias(bias); + this->set_alpha(alpha); + this->set_beta(beta); + this->set_norm_region(norm_region); +} +REGISTER_PRIMITIVE_C(kNameLrn, Lrn); +} // namespace mindspore diff --git a/mindspore/core/c_ops/lrn.h b/mindspore/core/c_ops/lrn.h new file mode 100644 index 0000000000..91606c5177 --- /dev/null +++ b/mindspore/core/c_ops/lrn.h @@ -0,0 +1,49 @@ +/** + * 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_C_OPS_LRN_H_ +#define MINDSPORE_CORE_C_OPS_LRN_H_ +#include +#include +#include +#include +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLrn = "Lrn"; +class Lrn : public PrimitiveC { + public: + Lrn() : PrimitiveC(kNameLrn) { InitIOName({"x"}, {"y"}); } + ~Lrn() = default; + MS_DECLARE_PARENT(Lrn, PrimitiveC); + void Init(const int64_t &depth_radius = 5, const float &bias = 1.0, const float &alpha = 1.0, const float &beta = 0.5, + const std::string &norm_region = "ACROSS_CHANNELS"); + void set_depth_radius(const int64_t &depth_radius); + void set_bias(const float &bias); + void set_alpha(const float &alpha); + void set_beta(const float &beta); + void set_norm_region(const std::string &norm_region); + int64_t get_depth_radius() const; + float get_bias() const; + float get_alpha() const; + float get_beta() const; + std::string get_norm_region() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LRN_H_ diff --git a/mindspore/core/c_ops/lstm.cc b/mindspore/core/c_ops/lstm.cc new file mode 100644 index 0000000000..077470cf4b --- /dev/null +++ b/mindspore/core/c_ops/lstm.cc @@ -0,0 +1,82 @@ +/** + * 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 "c_ops/lstm.h" + +namespace mindspore { +void LSTM::set_input_size(const int64_t &input_size) { + CheckAndConvertUtils::CheckInteger(kInput_size, input_size, kGreaterThan, 0, this->name()); + AddAttr(kInput_size, MakeValue(input_size)); +} +int64_t LSTM::get_input_size() const { + auto value_ptr = this->GetAttr(kInput_size); + return GetValue(value_ptr); +} +void LSTM::set_hidden_size(const int64_t &hidden_size) { + CheckAndConvertUtils::CheckInteger(kHidden_size, hidden_size, kGreaterThan, 0, this->name()); + AddAttr(kHidden_size, MakeValue(hidden_size)); +} +int64_t LSTM::get_hidden_size() const { + auto value_ptr = this->GetAttr(kHidden_size); + return GetValue(value_ptr); +} +void LSTM::set_num_layers(const int64_t &num_layers) { + CheckAndConvertUtils::CheckInteger(kNum_layers, num_layers, kGreaterThan, 0, this->name()); + AddAttr(kNum_layers, MakeValue(kNum_layers)); +} +int64_t LSTM::get_num_layers() const { + auto value_ptr = this->GetAttr(kNum_layers); + return GetValue(value_ptr); +} +void LSTM::set_has_bias(const bool &has_bias) { AddAttr(kHasBias, MakeValue(has_bias)); } +bool LSTM::get_has_bias() const { + auto value_ptr = this->GetAttr(kHasBias); + return GetValue(value_ptr); +} +void LSTM::set_dropout(const float &dropout) { + CheckAndConvertUtils::CheckInRange(kDropout, dropout, kIncludeBoth, {0, 1}, this->name()); + AddAttr(kDropout, MakeValue(dropout)); +} +float LSTM::get_dropout() const { + auto value_ptr = this->GetAttr(kDropout); + return GetValue(value_ptr); +} +void LSTM::set_bidirectional(const bool &bidirectional) { AddAttr(kBidirectional, MakeValue(bidirectional)); } +bool LSTM::get_bidirectional() const { + auto value_ptr = this->GetAttr(kBidirectional); + return GetValue(value_ptr); +} +void LSTM::set_num_directions(const int64_t &num_directions) { AddAttr(kNumDirections, MakeValue(num_directions)); } +int64_t LSTM::get_num_directions() const { + auto value_ptr = this->GetAttr(kNumDirections); + return GetValue(value_ptr); +} +void LSTM::Init(const int64_t &input_size, const int64_t &hidden_size, const int64_t &num_layers, const bool &has_bias, + const float &dropout, const bool &bidirectional) { + this->set_input_size(input_size); + this->set_hidden_size(hidden_size); + this->set_num_layers(num_layers); + this->set_has_bias(has_bias); + this->set_dropout(dropout); + this->set_bidirectional(bidirectional); + if (bidirectional) { + this->set_num_directions(2); + } else { + this->set_num_directions(1); + } +} +REGISTER_PRIMITIVE_C(kNameLSTM, LSTM); +} // namespace mindspore diff --git a/mindspore/core/c_ops/lstm.h b/mindspore/core/c_ops/lstm.h new file mode 100644 index 0000000000..ec69721f50 --- /dev/null +++ b/mindspore/core/c_ops/lstm.h @@ -0,0 +1,57 @@ +/** + * 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_C_OPS_LSTM_H_ +#define MINDSPORE_CORE_C_OPS_LSTM_H_ + +#include +#include +#include +#include +#include +#include "c_ops/op_utils.h" +#include "c_ops/primitive_c.h" +#include "abstract/primitive_infer_map.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +constexpr auto kNameLSTM = "LSTM"; +class LSTM : public PrimitiveC { + public: + LSTM() : PrimitiveC(kNameLSTM) {} + ~LSTM() = default; + MS_DECLARE_PARENT(LSTM, PrimitiveC); + void Init(const int64_t &input_size, const int64_t &hidden_size, const int64_t &num_layers, const bool &has_bias, + const float &dropout, const bool &bidirectional = false); + void set_input_size(const int64_t &input_size); + int64_t get_input_size() const; + void set_hidden_size(const int64_t &hidden_size); + int64_t get_hidden_size() const; + void set_num_layers(const int64_t &num_layers); + int64_t get_num_layers() const; + void set_has_bias(const bool &has_bias); + bool get_has_bias() const; + void set_dropout(const float &dropout); + float get_dropout() const; + void set_bidirectional(const bool &bidirectional); + bool get_bidirectional() const; + void set_num_directions(const int64_t &num_directions); + int64_t get_num_directions() const; +}; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_LSTM_H_ diff --git a/mindspore/core/c_ops/op_utils.cc b/mindspore/core/c_ops/op_utils.cc index d0466c00a6..664773ebdd 100644 --- a/mindspore/core/c_ops/op_utils.cc +++ b/mindspore/core/c_ops/op_utils.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -41,7 +41,7 @@ abstract::ShapePtr BroadCastInferShape(const std::string &op_name, const std::ve } else { std::copy(x_shape.begin(), x_shape.end() - length, std::back_inserter(broadcast_shape)); } - for (int i = -length; i < 0; i++) { + for (int64_t i = -length; i < 0; i++) { if (x_shape[x_length + i] == 1) { broadcast_shape.push_back(y_shape[y_length + i]); } else if (y_shape[y_length + i] == 1) { diff --git a/mindspore/core/c_ops/op_utils.h b/mindspore/core/c_ops/op_utils.h index ad1d482d0b..799cf5260e 100644 --- a/mindspore/core/c_ops/op_utils.h +++ b/mindspore/core/c_ops/op_utils.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -25,17 +25,139 @@ #include "utils/check_convert_utils.h" namespace mindspore { -constexpr auto kKernelSize = "kernel_size"; -constexpr auto kStride = "stride"; +constexpr auto kAlpha = "alpha"; +constexpr auto kActivationType = "activation_type"; +constexpr auto kAddress = "address"; +constexpr auto kAlignCorners = "align_corners"; +constexpr auto kAspectRatios = "aspect_ratios"; +constexpr auto kAxis = "axis"; +constexpr auto kAxisType = "axis_type"; +constexpr auto kBaseSize = "base_size"; +constexpr auto kBatchDim = "batch_dim"; +constexpr auto kBeginMask = "begin_mask"; +constexpr auto kBeginNormAxis = "begin_norm_axis"; +constexpr auto kBeginParamsAxis = "begin_params_axis"; +constexpr auto kBeta = "beta"; +constexpr auto kBias = "bias"; +constexpr auto kBidirectional = "bidirectional"; +constexpr auto kBlockSize = "block_size"; +constexpr auto kBodySubgraphIndex = "body_subgraph_index"; +constexpr auto kCenterPointBox = "center_point_box"; +constexpr auto kClip = "clip"; +constexpr auto kCondition = "condition"; +constexpr auto kCondSubgraphIndex = "cond_subgraph_index"; +constexpr auto kCustom = "custom"; +constexpr auto kDampening = "dampening"; +constexpr auto kDataType = "data_type"; +constexpr auto kDctCoeffNum = "dct_coeff_num"; +constexpr auto kDelta = "delta"; +constexpr auto kDependMode = "depend_mode"; +constexpr auto kDepthRadius = "depth_radius"; constexpr auto kDilation = "dilation"; -constexpr auto kPadMode = "pad_mode"; -constexpr auto kPad = "pad"; -constexpr auto kPads = "pads"; -constexpr auto kMode = "mode"; +constexpr auto kDropout = "dropout"; +constexpr auto kDstT = "dst_t"; +constexpr auto kDType = "d_type"; +constexpr auto kEllipsisMask = "ellipsis_mask"; +constexpr auto kEndMask = "end_mask"; +constexpr auto kEpsilon = "epsilon"; +constexpr auto kFeatStride = "feat_stride"; +constexpr auto kFftLength = "fft_length"; +constexpr auto kFilterBankChannelNum = "filter_bank_channel_num"; +constexpr auto kFlip = "flip"; +constexpr auto kFormat = "format"; +constexpr auto kFreqLowerLimit = "freq_lower_limit"; +constexpr auto kFreqUpperLimit = "freq_upper_limit"; +constexpr auto kGlobal = "global"; +constexpr auto kGradientScale = "gradient_scale"; constexpr auto kGroup = "group"; +constexpr auto kHasBias = "has_bias"; +constexpr auto kHidden_size = "hidden_size"; +constexpr auto kId = "id"; +constexpr auto kImageSizeH = "image_size_h"; +constexpr auto kImageSizeW = "image_size_w"; +constexpr auto kIncludeALLGrams = "include_all_grams"; +constexpr auto kInput_size = "input_size"; +constexpr auto kIoFormat = "io_format"; +constexpr auto kIsScale = "is_scale"; +constexpr auto kIsTraining = "is_training"; +constexpr auto kKeepDims = "keep_dims"; +constexpr auto kKeepProb = "keep_prob"; +constexpr auto kKernelSize = "kernel_size"; +constexpr auto kLimit = "limit"; +constexpr auto kMagSquare = "mag_square"; +constexpr auto kMax = "max"; +constexpr auto kMaxSizes = "max_sizes"; +constexpr auto kMaxSkipSize = "max_skip_size"; +constexpr auto kMin = "min"; +constexpr auto kMinSize = "min_size"; +constexpr auto kMinSizes = "min_sizes"; +constexpr auto kMode = "mode"; +constexpr auto kN = "n"; +constexpr auto kNarrowRange = "narrow_range"; +constexpr auto kNesterov = "nesterov"; +constexpr auto kNewAxisMask = "new_axis_mask"; +constexpr auto kNgramSize = "ngram_size"; +constexpr auto kNmsThresh = "nms_thresh"; +constexpr auto kNormRegion = "norm_region"; +constexpr auto kNum_layers = "num_layers"; +constexpr auto kNumBits = "num_bits"; +constexpr auto kNumDirections = "num_directions"; +constexpr auto kOffset = "offset"; +constexpr auto kOffsetA = "offset_a"; +constexpr auto kOrder = "order"; +constexpr auto kOutChannel = "out_channel"; +constexpr auto kOutMaxValue = "out_max_value"; constexpr auto kOutputChannel = "out_channel"; +constexpr auto kOutputNum = "output_num"; +constexpr auto kOutputType = "output_type"; +constexpr auto kP = "p"; +constexpr auto kPad = "pad"; +constexpr auto kPadding = "padding"; +constexpr auto kPaddingsElementSize = "paddings_element_size"; +constexpr auto kPaddingsSize = "paddings_size"; +constexpr auto kPadItem = "pad_item"; constexpr auto kPadList = "pad_list"; -constexpr auto kAxis = "axis"; +constexpr auto kPadMode = "pad_mode"; +constexpr auto kPads = "pads"; +constexpr auto kPadSize = "pad_size"; +constexpr auto kPooledH = "pooled_h"; +constexpr auto kPooledW = "pooled_w"; +constexpr auto kPostNmsTopn = "post_nms_topn"; +constexpr auto kPower = "power"; +constexpr auto kPreNmsTopn = "pre_nms_topn"; +constexpr auto kRatio = "ratio"; +constexpr auto kReduction = "reduction"; +constexpr auto kRootRank = "root_rank"; +constexpr auto kRoundMode = "round_mode"; +constexpr auto kSame = "same"; +constexpr auto kScale = "scale"; +constexpr auto kSeqDim = "seq_dim"; +constexpr auto kSetattrFlag = "setattr_flag"; +constexpr auto kShape = "shape"; +constexpr auto kShapeSize = "shape_size"; +constexpr auto kShift = "shift"; +constexpr auto kShrinkAxisMask = "shrink_axis_mask"; +constexpr auto kSize = "size"; +constexpr auto kSorted = "sorted"; +constexpr auto kSrcT = "srcT"; +constexpr auto kStart = "start"; +constexpr auto kStepH = "step_h"; +constexpr auto kStepW = "step_w"; +constexpr auto kStride = "stride"; +constexpr auto kSubGraphIndex = "sub_graph_index"; +constexpr auto kTopK = "top_k"; +constexpr auto kTransposeA = "transpose_a"; +constexpr auto kTransposeB = "transpose_b"; +constexpr auto kUseAxis = "use_axis"; +constexpr auto kUseLocking = "use_locking"; +constexpr auto kUseNesterov = "use_nesterov"; +constexpr auto kUseNesteroy = "use_nesteroy"; +constexpr auto kValid = "valid"; +constexpr auto kValue = "value"; +constexpr auto kVariances = "variances"; +constexpr auto kWeightDecay = "weight_decay"; +constexpr auto kWeightThreshold = "weight_threshold"; +constexpr auto kWindowSize = "window_size"; const std::set common_valid_types = { kNumberTypeInt8, kNumberTypeInt16, kNumberTypeInt32, kNumberTypeInt64, kNumberTypeUInt8, kNumberTypeUInt16, diff --git a/mindspore/core/c_ops/primitive_c.cc b/mindspore/core/c_ops/primitive_c.cc index 68a9efcebe..ffc0d03051 100644 --- a/mindspore/core/c_ops/primitive_c.cc +++ b/mindspore/core/c_ops/primitive_c.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. diff --git a/mindspore/core/c_ops/primitive_c.h b/mindspore/core/c_ops/primitive_c.h index aded5848e4..76e0a04a04 100644 --- a/mindspore/core/c_ops/primitive_c.h +++ b/mindspore/core/c_ops/primitive_c.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. diff --git a/mindspore/core/c_ops/relu6.cc b/mindspore/core/c_ops/relu6.cc index 93fda4209d..bae8fc3e6f 100644 --- a/mindspore/core/c_ops/relu6.cc +++ b/mindspore/core/c_ops/relu6.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -24,7 +24,8 @@ #include "abstract/primitive_infer_map.h" namespace mindspore { -abstract::ShapePtr Relu6InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { +namespace { +abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto x = input_args[0]->GetShapeTrack(); auto shape_element = x->cast(); @@ -32,7 +33,7 @@ abstract::ShapePtr Relu6InferShape(const PrimitivePtr &primitive, const std::vec return shape_element; } -TypePtr Relu6InferType(const PrimitivePtr &prim, const std::vector &input_args) { +TypePtr InferType(const PrimitivePtr &prim, const std::vector &input_args) { const std::set valid_types = {kNumberTypeFloat16, kNumberTypeFloat32}; if (std::any_of(input_args.begin(), input_args.end(), [](AbstractBasePtr a) { return a == nullptr; })) { MS_LOG(EXCEPTION) << "nullptr"; @@ -42,11 +43,11 @@ TypePtr Relu6InferType(const PrimitivePtr &prim, const std::vectorname()); return TypeIdToType(infer_type); } - +} // namespace AbstractBasePtr Relu6Infer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { - return std::make_shared(Relu6InferType(primitive, input_args), - Relu6InferShape(primitive, input_args)->shape()); + return std::make_shared(InferType(primitive, input_args), + InferShape(primitive, input_args)->shape()); } REGISTER_PRIMITIVE_EVAL_IMPL(Relu6, prim::kPrimRelu6, Relu6Infer); REGISTER_PRIMITIVE_C(kNameRelu6, Relu6); diff --git a/mindspore/core/c_ops/relu6.h b/mindspore/core/c_ops/relu6.h index 31c8f178a8..8034e76b47 100644 --- a/mindspore/core/c_ops/relu6.h +++ b/mindspore/core/c_ops/relu6.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. diff --git a/mindspore/core/c_ops/reshape.cc b/mindspore/core/c_ops/reshape.cc index 308d047387..b10333ccf9 100644 --- a/mindspore/core/c_ops/reshape.cc +++ b/mindspore/core/c_ops/reshape.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -24,6 +24,7 @@ #include "abstract/primitive_infer_map.h" namespace mindspore { +namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { // to do return nullptr; @@ -33,6 +34,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & // to do return nullptr; } +} // namespace AbstractBasePtr ReshapeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { diff --git a/mindspore/core/c_ops/reshape.h b/mindspore/core/c_ops/reshape.h index 1ddeb26182..0364730857 100644 --- a/mindspore/core/c_ops/reshape.h +++ b/mindspore/core/c_ops/reshape.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. diff --git a/mindspore/core/c_ops/softmax.cc b/mindspore/core/c_ops/softmax.cc index b30e23110b..df56390d29 100644 --- a/mindspore/core/c_ops/softmax.cc +++ b/mindspore/core/c_ops/softmax.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -25,16 +25,16 @@ #include "abstract/primitive_infer_map.h" namespace mindspore { -void Softmax::set_axis(const std::vector &axis) { this->set_attr(kAxis, MakeValue(axis)); } +void SoftMax::set_axis(const std::vector &axis) { this->AddAttr(kAxis, MakeValue(axis)); } -std::vector Softmax::get_axis() const { +std::vector SoftMax::get_axis() const { auto value_ptr = GetAttr(kAxis); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } -void Softmax::Init(int axis) { +void SoftMax::Init(int64_t axis) { auto op_name = this->name(); - std::vector axis_vec = {axis}; + std::vector axis_vec = {axis}; CheckAndConvertUtils::CheckInteger("axis_len", axis_vec.size(), kEqual, 1, op_name); auto rank = axis_vec.size(); for (auto &item : axis_vec) { @@ -45,7 +45,7 @@ void Softmax::Init(int axis) { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - auto softmax_prim = primitive->cast(); + auto softmax_prim = primitive->cast(); MS_EXCEPTION_IF_NULL(softmax_prim); auto op_name = softmax_prim->name(); auto axis = softmax_prim->get_axis(); @@ -68,12 +68,12 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & return TypeIdToType(infer_type); } -AbstractBasePtr SoftmaxInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, +AbstractBasePtr SoftMaxInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { return std::make_shared(InferType(primitive, input_args), InferShape(primitive, input_args)->shape()); } -REGISTER_PRIMITIVE_EVAL_IMPL(Softmax, prim::kPrimSoftmax, SoftmaxInfer); -REGISTER_PRIMITIVE_C(kNameSoftmax, Softmax); +REGISTER_PRIMITIVE_EVAL_IMPL(SoftMax, prim::kPrimSoftMax, SoftMaxInfer); +REGISTER_PRIMITIVE_C(kNameSoftMax, SoftMax); } // namespace mindspore diff --git a/mindspore/core/c_ops/softmax.h b/mindspore/core/c_ops/softmax.h index c9005132d8..f881e6b22c 100644 --- a/mindspore/core/c_ops/softmax.h +++ b/mindspore/core/c_ops/softmax.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -26,20 +26,20 @@ #include "utils/check_convert_utils.h" namespace mindspore { -constexpr auto kNameSoftmax = "Softmax"; -class Softmax : public PrimitiveC { +constexpr auto kNameSoftMax = "SoftMax"; +class SoftMax : public PrimitiveC { public: - Softmax() : PrimitiveC(kNameSoftmax) { InitIOName({"x"}, {"output"}); } - ~Softmax() = default; - MS_DECLARE_PARENT(Softmax, PrimitiveC); - void Init(int axis = -1); - void set_axis(const std::vector &axis); - std::vector get_axis() const; + SoftMax() : PrimitiveC(kNameSoftMax) { InitIOName({"x"}, {"output"}); } + ~SoftMax() = default; + MS_DECLARE_PARENT(SoftMax, PrimitiveC); + void Init(int64_t axis = -1); + void set_axis(const std::vector &axis); + std::vector get_axis() const; }; -AbstractBasePtr SoftmaxInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, +AbstractBasePtr SoftMaxInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args); -using PrimSoftmaxPtr = std::shared_ptr; +using PrimSoftMaxPtr = std::shared_ptr; } // namespace mindspore #endif // MINDSPORE_CORE_C_OPS_SOFTMAX_H_ diff --git a/mindspore/core/c_ops/squeeze.cc b/mindspore/core/c_ops/squeeze.cc index 02732b6073..c579cd3f86 100644 --- a/mindspore/core/c_ops/squeeze.cc +++ b/mindspore/core/c_ops/squeeze.cc @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -15,21 +15,16 @@ */ #include "c_ops/squeeze.h" -#include -#include -#include -#include "c_ops/op_utils.h" -#include "utils/check_convert_utils.h" -#include "abstract/primitive_infer_map.h" namespace mindspore { -void Squeeze::set_axis(const std::vector &axis) { this->set_attr(kAxis, MakeValue(axis)); } -void Squeeze::Init(const std::vector &axis) { this->set_axis(axis); } -std::vector Squeeze::get_axis() const { +void Squeeze::Init(const std::vector &axis) { set_axis(axis); } +void Squeeze::set_axis(const std::vector &axis) { AddAttr(kAxis, MakeValue(axis)); } +std::vector Squeeze::get_axis() const { auto value_ptr = this->GetAttr(kAxis); - return GetValue>(value_ptr); + return GetValue>(value_ptr); } +namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto squeeze_prim = primitive->cast(); @@ -42,7 +37,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector & } return input_args[0]->BuildType(); } - +} // namespace AbstractBasePtr SqueezeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { return std::make_shared(InferType(primitive, input_args), diff --git a/mindspore/core/c_ops/squeeze.h b/mindspore/core/c_ops/squeeze.h index e08ba5d4ca..5a35b17924 100644 --- a/mindspore/core/c_ops/squeeze.h +++ b/mindspore/core/c_ops/squeeze.h @@ -1,5 +1,5 @@ /** - * Copyright 2019-2020 Huawei Technologies Co., Ltd + * 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. @@ -21,7 +21,10 @@ #include #include #include +#include +#include "c_ops/op_utils.h" #include "c_ops/primitive_c.h" +#include "abstract/primitive_infer_map.h" #include "abstract/abstract_value.h" #include "utils/check_convert_utils.h" @@ -32,9 +35,9 @@ class Squeeze : public PrimitiveC { Squeeze() : PrimitiveC(kNameSqueeze) { InitIOName({"x"}, {"output"}); } ~Squeeze() = default; MS_DECLARE_PARENT(Squeeze, PrimitiveC); - void Init(const std::vector &axis = {}); - void set_axis(const std::vector &axis); - std::vector get_axis() const; + void Init(const std::vector &axis = {}); + void set_axis(const std::vector &axis); + std::vector get_axis() const; }; AbstractBasePtr SqueezeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, diff --git a/mindspore/core/utils/check_convert_utils.h b/mindspore/core/utils/check_convert_utils.h index b1ab73f8c6..ddfc1c4d65 100644 --- a/mindspore/core/utils/check_convert_utils.h +++ b/mindspore/core/utils/check_convert_utils.h @@ -42,6 +42,47 @@ enum CompareRange { kIncludeBoth = 4, // [a,b] }; +enum ActivationType : int64_t { + NO_ACTIVATION = 0, + RELU = 1, + SIGMOID = 2, + RELU6 = 3, + ELU = 4, + LEAKY_RELU = 5, + ABS = 6, + RELU1 = 7, + SOFTSIGN = 8, + SOFTPLUS = 9, + TANH = 10, + SELU = 11, + HSWISH = 12, + HSIGMOID = 13, + THRESHOLDRELU = 14, + LINEAR = 15, + HARD_TANH = 16, + SIGN = 17, + SWISH = 18, + UNKNOW = 19, +}; +enum Format : int64_t { + NCHW = 0, + NHWC = 1, + NHWC4 = 2, + HWKC = 3, + HWCK = 4, + KCHW = 5, + CKHW = 6, + KHWC = 7, + CHWK = 8, + HW = 9, + HW4 = 10, + NC = 11, + NC4 = 12, + NC4HW4 = 13, + NUM_OF_FORMAT = 14 +}; +enum EltwiseMode : int64_t { PROD = 0, SUM = 1, MAXIMUM = 2, ELTWISEMODE_UNKNOW = 3 }; + class CheckAndConvertUtils { public: static std::vector CheckPositiveVector(const std::string &arg_name, const std::vector &arg_value,