• 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 <memory>
18 #include "ops/grad/group_conv2d_grad_input.h"
19 #include "ops/op_utils.h"
20 
21 namespace mindspore {
22 namespace ops {
Init(const int64_t & in_channel,const int64_t & out_channel,const std::vector<int64_t> & kernel_size,const PadMode & pad_mode,const std::vector<int64_t> & pad_list,const std::vector<int64_t> & stride,const std::vector<int64_t> & dilation,const int64_t & group,const std::vector<int64_t> & input_shape,const Format & format,const ActivationType & activation_type,const bool has_bias)23 void GroupConv2DGradInput::Init(const int64_t &in_channel, const int64_t &out_channel,
24                                 const std::vector<int64_t> &kernel_size, const PadMode &pad_mode,
25                                 const std::vector<int64_t> &pad_list, const std::vector<int64_t> &stride,
26                                 const std::vector<int64_t> &dilation, const int64_t &group,
27                                 const std::vector<int64_t> &input_shape, const Format &format,
28                                 const ActivationType &activation_type, const bool has_bias) {
29   set_in_channel(in_channel);
30   set_out_channel(out_channel);
31   set_kernel_size(kernel_size);
32   set_pad_mode(pad_mode);
33   set_pad_list(pad_list);
34   set_stride(stride);
35   set_dilation(dilation);
36   set_group(group);
37   set_input_shape(input_shape);
38   set_format(format);
39   set_activation_type(activation_type);
40   set_has_bias(has_bias);
41 }
42 
set_in_channel(const int64_t & in_channel)43 void GroupConv2DGradInput::set_in_channel(const int64_t &in_channel) {
44   (void)this->AddAttr(kInChannel, MakeValue(in_channel));
45 }
46 
get_in_channel() const47 int64_t GroupConv2DGradInput::get_in_channel() const {
48   auto value_ptr = GetAttr(kInChannel);
49   MS_EXCEPTION_IF_NULL(value_ptr);
50   return GetValue<int64_t>(value_ptr);
51 }
52 
set_out_channel(const int64_t & out_channel)53 void GroupConv2DGradInput::set_out_channel(const int64_t &out_channel) {
54   (void)this->AddAttr(kOutChannel, MakeValue(out_channel));
55 }
56 
get_out_channel() const57 int64_t GroupConv2DGradInput::get_out_channel() const {
58   auto value_ptr = GetAttr(kOutChannel);
59   MS_EXCEPTION_IF_NULL(value_ptr);
60   return GetValue<int64_t>(value_ptr);
61 }
62 
set_kernel_size(const std::vector<int64_t> & kernel_size)63 void GroupConv2DGradInput::set_kernel_size(const std::vector<int64_t> &kernel_size) {
64   (void)this->AddAttr(kKernelSize, MakeValue(kernel_size));
65 }
66 
get_kernel_size() const67 std::vector<int64_t> GroupConv2DGradInput::get_kernel_size() const {
68   auto value_ptr = GetAttr(kKernelSize);
69   MS_EXCEPTION_IF_NULL(value_ptr);
70   return GetValue<std::vector<int64_t>>(value_ptr);
71 }
72 
set_pad_mode(const PadMode & pad_mode)73 void GroupConv2DGradInput::set_pad_mode(const PadMode &pad_mode) {
74   int64_t swi = pad_mode;
75   (void)this->AddAttr(kPadMode, MakeValue(swi));
76 }
77 
get_pad_mode() const78 PadMode GroupConv2DGradInput::get_pad_mode() const {
79   auto value_ptr = GetAttr(kPadMode);
80   MS_EXCEPTION_IF_NULL(value_ptr);
81   return PadMode(GetValue<int64_t>(value_ptr));
82 }
83 
set_pad_list(const std::vector<int64_t> & pad_list)84 void GroupConv2DGradInput::set_pad_list(const std::vector<int64_t> &pad_list) {
85   (void)this->AddAttr(kPadList, MakeValue(pad_list));
86 }
87 
get_pad_list() const88 std::vector<int64_t> GroupConv2DGradInput::get_pad_list() const {
89   auto value_ptr = GetAttr(kPadList);
90   MS_EXCEPTION_IF_NULL(value_ptr);
91   return GetValue<std::vector<int64_t>>(value_ptr);
92 }
93 
set_stride(const std::vector<int64_t> & stride)94 void GroupConv2DGradInput::set_stride(const std::vector<int64_t> &stride) {
95   (void)this->AddAttr(kStride, MakeValue(stride));
96 }
97 
get_stride() const98 std::vector<int64_t> GroupConv2DGradInput::get_stride() const {
99   auto value_ptr = GetAttr(kStride);
100   MS_EXCEPTION_IF_NULL(value_ptr);
101   return GetValue<std::vector<int64_t>>(value_ptr);
102 }
103 
set_dilation(const std::vector<int64_t> & dilation)104 void GroupConv2DGradInput::set_dilation(const std::vector<int64_t> &dilation) {
105   (void)this->AddAttr(kDilation, MakeValue(dilation));
106 }
107 
get_dilation() const108 std::vector<int64_t> GroupConv2DGradInput::get_dilation() const {
109   auto value_ptr = GetAttr(kDilation);
110   MS_EXCEPTION_IF_NULL(value_ptr);
111   return GetValue<std::vector<int64_t>>(value_ptr);
112 }
113 
set_group(const int64_t & group)114 void GroupConv2DGradInput::set_group(const int64_t &group) { (void)this->AddAttr(kGroup, MakeValue(group)); }
115 
get_group() const116 int64_t GroupConv2DGradInput::get_group() const {
117   auto value_ptr = GetAttr(kGroup);
118   MS_EXCEPTION_IF_NULL(value_ptr);
119   return GetValue<int64_t>(value_ptr);
120 }
121 
set_input_shape(const std::vector<int64_t> & input_shape)122 void GroupConv2DGradInput::set_input_shape(const std::vector<int64_t> &input_shape) {
123   (void)this->AddAttr(kInputShape, MakeValue(input_shape));
124 }
125 
get_input_shape() const126 std::vector<int64_t> GroupConv2DGradInput::get_input_shape() const {
127   auto value_ptr = GetAttr(kInputShape);
128   MS_EXCEPTION_IF_NULL(value_ptr);
129   return GetValue<std::vector<int64_t>>(value_ptr);
130 }
131 
set_format(const Format & format)132 void GroupConv2DGradInput::set_format(const Format &format) {
133   int64_t swi = format;
134   (void)this->AddAttr(kFormat, MakeValue(swi));
135 }
136 
get_format() const137 Format GroupConv2DGradInput::get_format() const {
138   auto value_ptr = GetAttr(kFormat);
139   MS_EXCEPTION_IF_NULL(value_ptr);
140   return Format(GetValue<int64_t>(value_ptr));
141 }
142 
set_activation_type(const ActivationType & activation_type)143 void GroupConv2DGradInput::set_activation_type(const ActivationType &activation_type) {
144   int64_t swi = activation_type;
145   (void)this->AddAttr(kActivationType, MakeValue(swi));
146 }
147 
get_activation_type() const148 ActivationType GroupConv2DGradInput::get_activation_type() const {
149   auto value_ptr = GetAttr(kActivationType);
150   MS_EXCEPTION_IF_NULL(value_ptr);
151   return ActivationType(GetValue<int64_t>(value_ptr));
152 }
153 
set_has_bias(const bool has_bias)154 void GroupConv2DGradInput::set_has_bias(const bool has_bias) { (void)this->AddAttr(kHasBias, MakeValue(has_bias)); }
155 
get_has_bias() const156 bool GroupConv2DGradInput::get_has_bias() const {
157   auto value_ptr = GetAttr(kHasBias);
158   MS_EXCEPTION_IF_NULL(value_ptr);
159   return GetValue<bool>(value_ptr);
160 }
GroupConv2DGradInputInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)161 AbstractBasePtr GroupConv2DGradInputInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
162                                           const std::vector<AbstractBasePtr> &input_args) {
163   MS_EXCEPTION_IF_NULL(primitive);
164   auto prim_name = primitive->name();
165   const int64_t input_num = 2;
166   (void)CheckAndConvertUtils::CheckInteger("group_conv_2D_infer", SizeToLong(input_args.size()), kGreaterEqual,
167                                            input_num, prim_name);
168   MS_EXCEPTION_IF_NULL(input_args[0]);
169 
170   // Infer shape
171   auto shape_ptr = primitive->GetAttr(kInputShape);
172   MS_EXCEPTION_IF_NULL(shape_ptr);
173   auto shape = GetValue<std::vector<int64_t>>(shape_ptr);
174 
175   // Infer type
176   auto type_ptr = input_args[0]->BuildType();
177   MS_EXCEPTION_IF_NULL(type_ptr);
178   auto type_tensor_ptr = type_ptr->cast<TensorTypePtr>();
179   MS_EXCEPTION_IF_NULL(type_tensor_ptr);
180   auto type = type_tensor_ptr->element();
181   return std::make_shared<abstract::AbstractTensor>(type, shape);
182 }
183 REGISTER_PRIMITIVE_C(kNameGroupConv2DGradInput, GroupConv2DGradInput);
184 }  // namespace ops
185 }  // namespace mindspore
186