From 994261e409391ebdabc977c0ba43a7539ebb167e Mon Sep 17 00:00:00 2001 From: liuyu Date: Thu, 25 Feb 2021 10:06:43 +0800 Subject: [PATCH] add master new cops --- mindspore/core/ops/grad/abs_grad.cc | 24 ++++++++++ mindspore/core/ops/grad/abs_grad.h | 40 +++++++++++++++++ mindspore/core/ops/lin_space.cc | 24 ++++++++++ mindspore/core/ops/lin_space.h | 39 +++++++++++++++++ mindspore/core/ops/random_standard_normal.cc | 10 ++--- mindspore/core/ops/random_standard_normal.h | 6 +-- mindspore/core/ops/uniform_real.cc | 46 ++++++++++++++++++++ mindspore/core/ops/uniform_real.h | 46 ++++++++++++++++++++ 8 files changed, 227 insertions(+), 8 deletions(-) create mode 100644 mindspore/core/ops/grad/abs_grad.cc create mode 100644 mindspore/core/ops/grad/abs_grad.h create mode 100644 mindspore/core/ops/lin_space.cc create mode 100644 mindspore/core/ops/lin_space.h create mode 100644 mindspore/core/ops/uniform_real.cc create mode 100644 mindspore/core/ops/uniform_real.h diff --git a/mindspore/core/ops/grad/abs_grad.cc b/mindspore/core/ops/grad/abs_grad.cc new file mode 100644 index 0000000000..b3e04a3e00 --- /dev/null +++ b/mindspore/core/ops/grad/abs_grad.cc @@ -0,0 +1,24 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ops/grad/abs_grad.h" +#include + +namespace mindspore { +namespace ops { +REGISTER_PRIMITIVE_C(kNameAbsGrad, AbsGrad); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/grad/abs_grad.h b/mindspore/core/ops/grad/abs_grad.h new file mode 100644 index 0000000000..2632fe17d6 --- /dev/null +++ b/mindspore/core/ops/grad/abs_grad.h @@ -0,0 +1,40 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_CORE_OPS_ABS_GRAD_H_ +#define MINDSPORE_CORE_OPS_ABS_GRAD_H_ +#include +#include +#include +#include +#include "ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +namespace ops { +constexpr auto kNameAbsGrad = "AbsGrad"; +class AbsGrad : public PrimitiveC { + public: + AbsGrad() : PrimitiveC(kNameAbsGrad) {} + ~AbsGrad() = default; + MS_DECLARE_PARENT(AbsGrad, PrimitiveC); + void Init() {} +}; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_ABS_GRAD_H_ diff --git a/mindspore/core/ops/lin_space.cc b/mindspore/core/ops/lin_space.cc new file mode 100644 index 0000000000..82159a49ae --- /dev/null +++ b/mindspore/core/ops/lin_space.cc @@ -0,0 +1,24 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ops/lin_space.h" +#include + +namespace mindspore { +namespace ops { +REGISTER_PRIMITIVE_C(kNameLinSpace, LinSpace); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/lin_space.h b/mindspore/core/ops/lin_space.h new file mode 100644 index 0000000000..e85c4f130c --- /dev/null +++ b/mindspore/core/ops/lin_space.h @@ -0,0 +1,39 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_CORE_OPS_LIN_SPACE_H_ +#define MINDSPORE_CORE_OPS_LIN_SPACE_H_ +#include +#include + +#include "ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +namespace ops { +constexpr auto kNameLinSpace = "LinSpace"; +class LinSpace : public PrimitiveC { + public: + LinSpace() : PrimitiveC(kNameLinSpace) { InitIOName({"start", "stop", "num"}, {"output"}); } + ~LinSpace() = default; + MS_DECLARE_PARENT(LinSpace, PrimitiveC); + void Init() {} +}; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_LIN_SPACE_H_ diff --git a/mindspore/core/ops/random_standard_normal.cc b/mindspore/core/ops/random_standard_normal.cc index 8772100b70..6537d9c653 100644 --- a/mindspore/core/ops/random_standard_normal.cc +++ b/mindspore/core/ops/random_standard_normal.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,14 +31,14 @@ void RandomStandardNormal::set_seed(const int64_t seed) { this->AddAttr(kSeed, M void RandomStandardNormal::set_seed2(const int64_t seed2) { this->AddAttr(kSeed2, MakeValue(seed2)); } -bool RandomStandardNormal::get_seed() const { +int64_t RandomStandardNormal::get_seed() const { auto value_ptr = GetAttr(kSeed); - return GetValue(value_ptr); + return GetValue(value_ptr); } -bool RandomStandardNormal::get_seed2() const { +int64_t RandomStandardNormal::get_seed2() const { auto value_ptr = GetAttr(kSeed2); - return GetValue(value_ptr); + return GetValue(value_ptr); } REGISTER_PRIMITIVE_C(kNameRandomStandardNormal, RandomStandardNormal); diff --git a/mindspore/core/ops/random_standard_normal.h b/mindspore/core/ops/random_standard_normal.h index de0f91abf7..1437a3891b 100644 --- a/mindspore/core/ops/random_standard_normal.h +++ b/mindspore/core/ops/random_standard_normal.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,8 @@ class RandomStandardNormal : public PrimitiveC { void set_seed(const int64_t seed); void set_seed2(const int64_t seed2); - bool get_seed() const; - bool get_seed2() const; + int64_t get_seed() const; + int64_t get_seed2() const; }; AbstractBasePtr RandomStandardNormalInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, diff --git a/mindspore/core/ops/uniform_real.cc b/mindspore/core/ops/uniform_real.cc new file mode 100644 index 0000000000..b6e96754f7 --- /dev/null +++ b/mindspore/core/ops/uniform_real.cc @@ -0,0 +1,46 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ops/uniform_real.h" +#include +#include +#include +#include "ops/op_utils.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +namespace ops { +void UniformReal::Init(const int64_t seed, const int64_t seed2) { + this->set_seed(seed); + this->set_seed2(seed2); +} + +void UniformReal::set_seed(const int64_t seed) { this->AddAttr(kSeed, MakeValue(seed)); } + +void UniformReal::set_seed2(const int64_t seed2) { this->AddAttr(kSeed2, MakeValue(seed2)); } + +int64_t UniformReal::get_seed() const { + auto value_ptr = GetAttr(kSeed); + return GetValue(value_ptr); +} + +int64_t UniformReal::get_seed2() const { + auto value_ptr = GetAttr(kSeed2); + return GetValue(value_ptr); +} + +REGISTER_PRIMITIVE_C(kNameUniformReal, UniformReal); +} // namespace ops +} // namespace mindspore diff --git a/mindspore/core/ops/uniform_real.h b/mindspore/core/ops/uniform_real.h new file mode 100644 index 0000000000..225f871e32 --- /dev/null +++ b/mindspore/core/ops/uniform_real.h @@ -0,0 +1,46 @@ +/** + * Copyright 2021 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MINDSPORE_CORE_OPS_RANDOM_UNIFORM_REAL_H_ +#define MINDSPORE_CORE_OPS_RANDOM_UNIFORM_REAL_H_ +#include +#include +#include +#include +#include "ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" + +namespace mindspore { +namespace ops { +constexpr auto kNameUniformReal = "UniformReal"; +class UniformReal : public PrimitiveC { + public: + UniformReal() : PrimitiveC(kNameUniformReal) {} + ~UniformReal() = default; + MS_DECLARE_PARENT(UniformReal, PrimitiveC); + void Init(const int64_t seed, const int64_t seed2); + + void set_seed(const int64_t seed); + void set_seed2(const int64_t seed2); + + int64_t get_seed() const; + int64_t get_seed2() const; +}; +} // namespace ops +} // namespace mindspore + +#endif // MINDSPORE_CORE_OPS_RANDOM_UNIFORM_REAL_H_