• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/full_connection.h"
18 #include "mindapi/base/shared_ptr.h"
19 #include "mindapi/ir/value.h"
20 #include "mindapi/src/helper.h"
21 #include "ops/op_name.h"
22 #include "ops/primitive_c.h"
23 #include "utils/log_adapter.h"
24 
25 namespace mindspore {
26 namespace ops {
27 MIND_API_OPERATOR_IMPL(FullConnection, BaseOperator);
set_has_bias(const bool has_bias)28 void FullConnection::set_has_bias(const bool has_bias) { (void)this->AddAttr(kHasBias, api::MakeValue(has_bias)); }
29 
get_has_bias() const30 bool FullConnection::get_has_bias() const {
31   auto value_ptr = GetAttr(kHasBias);
32   MS_EXCEPTION_IF_NULL(value_ptr);
33   return GetValue<bool>(value_ptr);
34 }
35 
set_axis(const int64_t axis)36 void FullConnection::set_axis(const int64_t axis) { (void)this->AddAttr(kAxis, api::MakeValue(axis)); }
get_axis() const37 int64_t FullConnection::get_axis() const {
38   auto value_ptr = GetAttr(kAxis);
39   MS_EXCEPTION_IF_NULL(value_ptr);
40   return GetValue<int64_t>(value_ptr);
41 }
42 
set_use_axis(const bool use_axis)43 void FullConnection::set_use_axis(const bool use_axis) { (void)this->AddAttr(kUseAxis, api::MakeValue(use_axis)); }
get_use_axis() const44 bool FullConnection::get_use_axis() const {
45   auto value_ptr = GetAttr(kUseAxis);
46   MS_EXCEPTION_IF_NULL(value_ptr);
47   return GetValue<bool>(value_ptr);
48 }
49 
set_activation_type(const ActivationType & activation_type)50 void FullConnection::set_activation_type(const ActivationType &activation_type) {
51   int64_t swi = activation_type;
52   (void)this->AddAttr(kActivationType, api::MakeValue(swi));
53 }
get_activation_type() const54 ActivationType FullConnection::get_activation_type() const {
55   auto value_ptr = GetAttr(kActivationType);
56   MS_EXCEPTION_IF_NULL(value_ptr);
57   return ActivationType(GetValue<int64_t>(value_ptr));
58 }
Init(const bool has_bias,const int64_t axis,const bool use_axis,const ActivationType & activation_type)59 void FullConnection::Init(const bool has_bias, const int64_t axis, const bool use_axis,
60                           const ActivationType &activation_type) {
61   this->set_has_bias(has_bias);
62   this->set_axis(axis);
63   this->set_use_axis(use_axis);
64   this->set_activation_type(activation_type);
65 }
66 
67 REGISTER_PRIMITIVE_C(kNameFullConnection, FullConnection);
68 }  // namespace ops
69 }  // namespace mindspore
70