1 /**
2 * Copyright 2020-2021 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "ops/fusion/prelu_fusion.h"
18
19 #include <vector>
20
21 #include "mindapi/base/shared_ptr.h"
22 #include "mindapi/ir/value.h"
23 #include "mindapi/src/helper.h"
24 #include "ops/base_operator.h"
25 #include "ops/op_name.h"
26 #include "ops/primitive_c.h"
27 #include "utils/log_adapter.h"
28
29 namespace mindspore {
30 namespace ops {
31 MIND_API_OPERATOR_IMPL(PReLUFusion, BaseOperator);
Init(const bool channel_shared,const std::vector<float> & slope)32 void PReLUFusion::Init(const bool channel_shared, const std::vector<float> &slope) {
33 this->set_channel_shared(channel_shared);
34 this->set_slope(slope);
35 }
36
set_channel_shared(const bool channel_shared)37 void PReLUFusion::set_channel_shared(const bool channel_shared) {
38 (void)this->AddAttr(kChannelShared, api::MakeValue(channel_shared));
39 }
40
set_slope(const std::vector<float> & slope)41 void PReLUFusion::set_slope(const std::vector<float> &slope) { (void)this->AddAttr(kSlope, api::MakeValue(slope)); }
42
get_channel_shared() const43 bool PReLUFusion::get_channel_shared() const {
44 auto value_ptr = GetAttr(kChannelShared);
45 MS_EXCEPTION_IF_NULL(value_ptr);
46 return GetValue<bool>(value_ptr);
47 }
get_slope() const48 std::vector<float> PReLUFusion::get_slope() const {
49 auto value_ptr = GetAttr(kSlope);
50 MS_EXCEPTION_IF_NULL(value_ptr);
51 return GetValue<std::vector<float>>(value_ptr);
52 }
53 REGISTER_PRIMITIVE_C(kNamePReLUFusion, PReLUFusion);
54 } // namespace ops
55 } // namespace mindspore
56