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/grad/pooling_grad.h"
18 #include "ops/op_utils.h"
19
20 namespace mindspore {
21 namespace ops {
Init(const PoolMode & pool_mode,const std::vector<int64_t> & window,const std::vector<int64_t> & stride,const PadMode & pad_mode,const std::vector<int64_t> & pad_list,const RoundMode & round_mode,const Format & format,const bool global)22 void PoolingGrad::Init(const PoolMode &pool_mode, const std::vector<int64_t> &window,
23 const std::vector<int64_t> &stride, const PadMode &pad_mode,
24 const std::vector<int64_t> &pad_list, const RoundMode &round_mode, const Format &format,
25 const bool global) {
26 set_pool_mode(pool_mode);
27 set_window(window);
28 set_stride(stride);
29 set_pad_mode(pad_mode);
30 set_pad_list(pad_list);
31 set_round_mode(round_mode);
32 set_format(format);
33 set_global(global);
34 }
35
set_pool_mode(const PoolMode & pool_mode)36 void PoolingGrad::set_pool_mode(const PoolMode &pool_mode) {
37 int64_t swi = pool_mode;
38 (void)this->AddAttr(kPoolMode, MakeValue(swi));
39 }
40
get_pool_mode() const41 PoolMode PoolingGrad::get_pool_mode() const {
42 auto value_ptr = GetAttr(kPoolMode);
43 return PoolMode(GetValue<int64_t>(value_ptr));
44 }
45
set_window(const std::vector<int64_t> & window)46 void PoolingGrad::set_window(const std::vector<int64_t> &window) { (void)this->AddAttr(kWindow, MakeValue(window)); }
47
get_window() const48 std::vector<int64_t> PoolingGrad::get_window() const {
49 auto value_ptr = GetAttr(kWindow);
50 MS_EXCEPTION_IF_NULL(value_ptr);
51 return GetValue<std::vector<int64_t>>(value_ptr);
52 }
53
set_stride(const std::vector<int64_t> & stride)54 void PoolingGrad::set_stride(const std::vector<int64_t> &stride) { (void)this->AddAttr(kStride, MakeValue(stride)); }
55
get_stride() const56 std::vector<int64_t> PoolingGrad::get_stride() const {
57 auto value_ptr = GetAttr(kStride);
58 MS_EXCEPTION_IF_NULL(value_ptr);
59 return GetValue<std::vector<int64_t>>(value_ptr);
60 }
61
set_pad_mode(const PadMode & pad_mode)62 void PoolingGrad::set_pad_mode(const PadMode &pad_mode) {
63 int64_t swi = pad_mode;
64 (void)this->AddAttr(kPadMode, MakeValue(swi));
65 }
66
get_pad_mode() const67 PadMode PoolingGrad::get_pad_mode() const {
68 auto value_ptr = GetAttr(kPadMode);
69 MS_EXCEPTION_IF_NULL(value_ptr);
70 return PadMode(GetValue<int64_t>(value_ptr));
71 }
72
set_pad_list(const std::vector<int64_t> & pad_list)73 void PoolingGrad::set_pad_list(const std::vector<int64_t> &pad_list) {
74 (void)this->AddAttr(kPadList, MakeValue(pad_list));
75 }
76
get_pad_list() const77 std::vector<int64_t> PoolingGrad::get_pad_list() const {
78 auto value_ptr = GetAttr(kPadList);
79 MS_EXCEPTION_IF_NULL(value_ptr);
80 return GetValue<std::vector<int64_t>>(value_ptr);
81 }
82
set_round_mode(const RoundMode & round_mode)83 void PoolingGrad::set_round_mode(const RoundMode &round_mode) {
84 int64_t swi = round_mode;
85 (void)this->AddAttr(kRoundMode, MakeValue(swi));
86 }
87
get_round_mode() const88 RoundMode PoolingGrad::get_round_mode() const {
89 auto value_ptr = GetAttr(kRoundMode);
90 MS_EXCEPTION_IF_NULL(value_ptr);
91 return RoundMode(GetValue<int64_t>(value_ptr));
92 }
93
set_format(const Format & format)94 void PoolingGrad::set_format(const Format &format) {
95 int64_t swi = format;
96 (void)this->AddAttr(kFormat, MakeValue(swi));
97 }
98
get_format() const99 Format PoolingGrad::get_format() const {
100 auto value_ptr = GetAttr(kFormat);
101 MS_EXCEPTION_IF_NULL(value_ptr);
102 return Format(GetValue<int64_t>(value_ptr));
103 }
104
set_global(const bool global)105 void PoolingGrad::set_global(const bool global) { (void)this->AddAttr(kGlobal, MakeValue(global)); }
106
get_global() const107 bool PoolingGrad::get_global() const {
108 auto value_ptr = GetAttr(kGlobal);
109 MS_EXCEPTION_IF_NULL(value_ptr);
110 return GetValue<bool>(value_ptr);
111 }
112 REGISTER_PRIMITIVE_C(kNamePoolingGrad, PoolingGrad);
113 } // namespace ops
114 } // namespace mindspore
115