Browse Source

relu

pull/16010/head
shen_jingxing 5 years ago
parent
commit
cfd7b4baf8
8 changed files with 50 additions and 22 deletions
  1. +0
    -2
      mindspore/core/abstract/infer_functions.h
  2. +0
    -7
      mindspore/core/abstract/prim_nn.cc
  3. +0
    -2
      mindspore/core/abstract/primitive_infer_map.cc
  4. +4
    -2
      mindspore/core/base/core_ops.h
  5. +34
    -3
      mindspore/core/ops/relu.cc
  6. +8
    -3
      mindspore/core/ops/relu.h
  7. +3
    -2
      mindspore/core/ops/relu6.cc
  8. +1
    -1
      mindspore/core/ops/relu6.h

+ 0
- 2
mindspore/core/abstract/infer_functions.h View File

@@ -57,8 +57,6 @@ AbstractBasePtr InferImplBiasAdd(const AnalysisEnginePtr &, const PrimitivePtr &
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplBiasAddGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplRelu(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplHSigmoid(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list);
AbstractBasePtr InferImplHSigmoidGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive,


+ 0
- 7
mindspore/core/abstract/prim_nn.cc View File

@@ -409,13 +409,6 @@ AbstractBasePtr InferImplBiasAddGrad(const AnalysisEnginePtr &, const PrimitiveP
return ret;
}

AbstractBasePtr InferImplRelu(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
// Inputs: a tensor.
CheckArgsSize(primitive->name(), args_spec_list, 1);
return args_spec_list[0]->Broaden();
}

AbstractBasePtr InferImplHSigmoid(const AnalysisEnginePtr &, const PrimitivePtr &primitive,
const AbstractBasePtrList &args_spec_list) {
// Inputs: a tensor.


+ 0
- 2
mindspore/core/abstract/primitive_infer_map.cc View File

@@ -121,8 +121,6 @@ PrimitiveEvalImplMap &GetPrimitiveToEvalImplMap() {
{prim::kPrimReluGrad, {InferImplReluGrad, nullptr, true}},
{prim::kPrimConv2D, {InferImplConv2D, nullptr, true}},
{prim::kPrimBiasAdd, {InferImplBiasAdd, nullptr, true}},
{prim::kPrimRelu, {InferImplRelu, nullptr, true}},
{prim::kPrimRelu6, {InferImplRelu, nullptr, true}},
{prim::kPrimZerosLike, {InferImplZerosLike, nullptr, true}},
{prim::kPrimBpropCut, {InferImplBpropCut, nullptr, true}},
{prim::kPrimLayerNorm, {InferImplLayerNorm, nullptr, true}},


+ 4
- 2
mindspore/core/base/core_ops.h View File

@@ -51,6 +51,8 @@ constexpr auto kStack = "Stack";
constexpr auto kUnstack = "Unstack";
constexpr auto kTupleGetItem = "TupleGetItem";
constexpr auto kGeLU = "GeLU";
constexpr auto kReLU = "ReLU";
constexpr auto kReLU6 = "ReLU6";
constexpr auto kGeLUGrad = "GeLUGrad";
constexpr auto kFastGeLU = "FastGeLU";
constexpr auto kFastGeLUGrad = "FastGeLUGrad";
@@ -284,9 +286,9 @@ inline const PrimitivePtr kPrimGeLU = std::make_shared<Primitive>(kGeLU);
inline const PrimitivePtr kPrimGeLUGrad = std::make_shared<Primitive>(kGeLUGrad);
inline const PrimitivePtr kPrimFastGeLU = std::make_shared<Primitive>(kFastGeLU);
inline const PrimitivePtr kPrimFastGeLUGrad = std::make_shared<Primitive>(kFastGeLUGrad);
inline const PrimitivePtr kPrimRelu = std::make_shared<Primitive>("ReLU");
inline const PrimitivePtr kPrimRelu = std::make_shared<Primitive>(kReLU);
inline const PrimitivePtr kPrimElu = std::make_shared<Primitive>("Elu");
inline const PrimitivePtr kPrimRelu6 = std::make_shared<Primitive>("ReLU6");
inline const PrimitivePtr kPrimRelu6 = std::make_shared<Primitive>(kReLU6);
inline const PrimitivePtr kPrimReluV2 = std::make_shared<Primitive>("ReLUV2");
inline const PrimitivePtr kPrimPRelu = std::make_shared<Primitive>("PReLU");
inline const PrimitivePtr kPrimSoftplus = std::make_shared<Primitive>("Softplus");


+ 34
- 3
mindspore/core/ops/relu.cc View File

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

#include "ops/relu.h"
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>

#include "ops/op_utils.h"
#include "utils/check_convert_utils.h"
#include "abstract/primitive_infer_map.h"

namespace mindspore {
namespace ops {
REGISTER_PRIMITIVE_C(kNameReLU, ReLU);
abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
auto x = input_args[0]->BuildShape();
MS_EXCEPTION_IF_NULL(x);
auto shape_element = x->cast<abstract::ShapePtr>();
MS_EXCEPTION_IF_NULL(shape_element);
return shape_element;
}
TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(prim);
auto prim_name = prim->name();
CheckAndConvertUtils::CheckInteger("ReLU infer", input_args.size(), kEqual, 1, prim_name);
MS_EXCEPTION_IF_NULL(input_args[0]);
auto x_type_map = input_args[0]->BuildType();
MS_EXCEPTION_IF_NULL(x_type_map);
auto x_type = x_type_map->cast<TensorTypePtr>();
std::set<TypePtr> valid_x_type = {kTensorType};
return CheckAndConvertUtils::CheckTensorTypeValid("input_x", x_type, valid_x_type, prim_name);
}
AbstractBasePtr ReLUInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {
return std::make_shared<abstract::AbstractTensor>(InferType(primitive, input_args),
InferShape(primitive, input_args));
}
REGISTER_PRIMITIVE_EVAL_IMPL(ReLU, prim::kPrimRelu, ReLUInfer, nullptr, true);

} // namespace ops
} // namespace mindspore

+ 8
- 3
mindspore/core/ops/relu.h View File

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

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

namespace mindspore {
namespace ops {
constexpr auto kNameReLU = "ReLU";
constexpr auto kNameReLU = prim::kReLU;
class ReLU : public PrimitiveC {
public:
ReLU() : PrimitiveC(kNameReLU) { InitIOName({"x"}, {"output"}); }
@@ -30,6 +34,7 @@ class ReLU : public PrimitiveC {
MS_DECLARE_PARENT(ReLU, PrimitiveC);
void Init() {}
};
using PrimReLUPtr = std::shared_ptr<ReLU>;
} // namespace ops
} // namespace mindspore



+ 3
- 2
mindspore/core/ops/relu6.cc View File

@@ -29,6 +29,7 @@ namespace {
abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
MS_EXCEPTION_IF_NULL(primitive);
auto x = input_args[0]->GetShapeTrack();
MS_EXCEPTION_IF_NULL(x);
auto shape_element = x->cast<abstract::ShapePtr>();
MS_EXCEPTION_IF_NULL(shape_element);
return shape_element;
@@ -47,8 +48,8 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &
AbstractBasePtr ReLU6Infer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
const std::vector<AbstractBasePtr> &input_args) {
return std::make_shared<abstract::AbstractTensor>(InferType(primitive, input_args),
InferShape(primitive, input_args)->shape());
InferShape(primitive, input_args));
}
REGISTER_PRIMITIVE_C(kNameReLU6, ReLU6);
REGISTER_PRIMITIVE_EVAL_IMPL(ReLU6, prim::kPrimRelu6, ReLU6Infer, nullptr, true);
} // namespace ops
} // namespace mindspore

+ 1
- 1
mindspore/core/ops/relu6.h View File

@@ -25,7 +25,7 @@

namespace mindspore {
namespace ops {
constexpr auto kNameReLU6 = "ReLU6";
constexpr auto kNameReLU6 = prim::kReLU6;
class ReLU6 : public PrimitiveC {
public:
ReLU6() : PrimitiveC(kNameReLU6) { InitIOName({"x"}, {"output"}); }


Loading…
Cancel
Save