Compute Library
 22.11
AssemblyUtils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2022 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 
26 namespace arm_compute
27 {
28 namespace assembly_utils
29 {
31 {
32  arm_gemm::Activation gemm_act;
33 
34  // Early exit in case lower bound is other than 0, as it's not yet supported
35  if(act.b() != 0.f)
36  {
37  return gemm_act;
38  }
39 
40  switch(act.activation())
41  {
44  break;
47  gemm_act.param1 = act.a();
48  gemm_act.param2 = 0.f;
49  break;
52  gemm_act.param1 = act.a();
53  gemm_act.param2 = act.b();
54  break;
55  default:
57  }
58 
59  return gemm_act;
60 }
61 
62 arm_conv::PaddingValues map_to_arm_conv_padding(const PadStrideInfo &pad_stride_info)
63 {
64  return arm_conv::PaddingValues{ pad_stride_info.pad_left(),
65  pad_stride_info.pad_top(),
66  pad_stride_info.pad_right(),
67  pad_stride_info.pad_bottom() };
68 }
69 
71 {
72  arm_gemm::WeightFormat gemm_weight_fromat;
73 
74  switch(weight_format)
75  {
77  gemm_weight_fromat = arm_gemm::WeightFormat::UNSPECIFIED;
78  break;
80  gemm_weight_fromat = arm_gemm::WeightFormat::ANY;
81  break;
83  gemm_weight_fromat = arm_gemm::WeightFormat::OHWI;
84  break;
86  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo2;
87  break;
89  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo4;
90  break;
92  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo8;
93  break;
95  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo16;
96  break;
98  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo32;
99  break;
101  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo64;
102  break;
104  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo128;
105  break;
107  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo4i2;
108  break;
110  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo4i2_bf16;
111  break;
113  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo8i2;
114  break;
116  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo8i2_bf16;
117  break;
119  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo16i2;
120  break;
122  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo16i2_bf16;
123  break;
125  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo32i2;
126  break;
128  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo32i2_bf16;
129  break;
131  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo64i2;
132  break;
134  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo64i2_bf16;
135  break;
137  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo4i4;
138  break;
140  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo4i4_bf16;
141  break;
143  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo8i4;
144  break;
146  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo8i4_bf16;
147  break;
149  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo16i4;
150  break;
152  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo16i4_bf16;
153  break;
155  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo32i4;
156  break;
158  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo32i4_bf16;
159  break;
161  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo64i4;
162  break;
164  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo64i4_bf16;
165  break;
167  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo2i8;
168  break;
170  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo4i8;
171  break;
173  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo8i8;
174  break;
176  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo16i8;
177  break;
179  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo32i8;
180  break;
182  gemm_weight_fromat = arm_gemm::WeightFormat::OHWIo64i8;
183  break;
184  default:
185  gemm_weight_fromat = arm_gemm::WeightFormat::UNSPECIFIED;
186  }
187  return gemm_weight_fromat;
188 }
189 
191 {
192  arm_compute::WeightFormat acl_weight_fromat;
193 
194  switch(weight_format)
195  {
197  acl_weight_fromat = arm_compute::WeightFormat::UNSPECIFIED;
198  break;
200  acl_weight_fromat = arm_compute::WeightFormat::ANY;
201  break;
203  acl_weight_fromat = arm_compute::WeightFormat::OHWI;
204  break;
206  acl_weight_fromat = arm_compute::WeightFormat::OHWIo2;
207  break;
209  acl_weight_fromat = arm_compute::WeightFormat::OHWIo4;
210  break;
212  acl_weight_fromat = arm_compute::WeightFormat::OHWIo8;
213  break;
215  acl_weight_fromat = arm_compute::WeightFormat::OHWIo16;
216  break;
218  acl_weight_fromat = arm_compute::WeightFormat::OHWIo32;
219  break;
221  acl_weight_fromat = arm_compute::WeightFormat::OHWIo64;
222  break;
224  acl_weight_fromat = arm_compute::WeightFormat::OHWIo128;
225  break;
227  acl_weight_fromat = arm_compute::WeightFormat::OHWIo4i2;
228  break;
230  acl_weight_fromat = arm_compute::WeightFormat::OHWIo4i2_bf16;
231  break;
233  acl_weight_fromat = arm_compute::WeightFormat::OHWIo8i2;
234  break;
236  acl_weight_fromat = arm_compute::WeightFormat::OHWIo8i2_bf16;
237  break;
239  acl_weight_fromat = arm_compute::WeightFormat::OHWIo16i2;
240  break;
242  acl_weight_fromat = arm_compute::WeightFormat::OHWIo16i2_bf16;
243  break;
245  acl_weight_fromat = arm_compute::WeightFormat::OHWIo32i2;
246  break;
248  acl_weight_fromat = arm_compute::WeightFormat::OHWIo32i2_bf16;
249  break;
251  acl_weight_fromat = arm_compute::WeightFormat::OHWIo64i2;
252  break;
254  acl_weight_fromat = arm_compute::WeightFormat::OHWIo64i2_bf16;
255  break;
257  acl_weight_fromat = arm_compute::WeightFormat::OHWIo4i4;
258  break;
260  acl_weight_fromat = arm_compute::WeightFormat::OHWIo4i4_bf16;
261  break;
263  acl_weight_fromat = arm_compute::WeightFormat::OHWIo8i4;
264  break;
266  acl_weight_fromat = arm_compute::WeightFormat::OHWIo8i4_bf16;
267  break;
269  acl_weight_fromat = arm_compute::WeightFormat::OHWIo16i4;
270  break;
272  acl_weight_fromat = arm_compute::WeightFormat::OHWIo16i4_bf16;
273  break;
275  acl_weight_fromat = arm_compute::WeightFormat::OHWIo32i4;
276  break;
278  acl_weight_fromat = arm_compute::WeightFormat::OHWIo32i4_bf16;
279  break;
281  acl_weight_fromat = arm_compute::WeightFormat::OHWIo64i4;
282  break;
284  acl_weight_fromat = arm_compute::WeightFormat::OHWIo64i4_bf16;
285  break;
287  acl_weight_fromat = arm_compute::WeightFormat::OHWIo2i8;
288  break;
290  acl_weight_fromat = arm_compute::WeightFormat::OHWIo4i8;
291  break;
293  acl_weight_fromat = arm_compute::WeightFormat::OHWIo8i8;
294  break;
296  acl_weight_fromat = arm_compute::WeightFormat::OHWIo16i8;
297  break;
299  acl_weight_fromat = arm_compute::WeightFormat::OHWIo32i8;
300  break;
302  acl_weight_fromat = arm_compute::WeightFormat::OHWIo64i8;
303  break;
304  default:
305  acl_weight_fromat = arm_compute::WeightFormat::UNSPECIFIED;
306  }
307  return acl_weight_fromat;
308 }
309 } // namespace assembly_utils
310 } // namespace arm_compute
float a() const
Get the alpha value.
Definition: Types.h:1684
WeightFormat
Memory layouts for the weights tensor.
Definition: Types.h:2015
unsigned int pad_top() const
Get the top padding.
Definition: Types.h:753
Activation Layer Information class.
Definition: Types.h:1639
Copyright (c) 2017-2022 Arm Limited.
unsigned int pad_right() const
Get the right padding.
Definition: Types.h:748
Padding and stride information class.
Definition: Types.h:669
arm_gemm::WeightFormat map_to_arm_gemm_weight_format(const arm_compute::WeightFormat &weight_format)
Performs a mapping from Compute Library WeightFormat to the assembly WeightFormat enum...
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1679
float b() const
Get the beta value.
Definition: Types.h:1689
arm_gemm::Activation map_to_arm_gemm_activation(const ActivationLayerInfo &act)
Performs a mapping between Compute Library ActivationLayerInfo and the assembly Activation structure...
unsigned int pad_bottom() const
Get the bottom padding.
Definition: Types.h:758
arm_conv::PaddingValues map_to_arm_conv_padding(const PadStrideInfo &pad_stride_info)
Performs a mapping between Compute Library PadStrideInfo and the assembly PaddingValues structure...
unsigned int pad_left() const
Get the left padding.
Definition: Types.h:743
arm_compute::WeightFormat map_to_arm_compute_weight_format(const arm_gemm::WeightFormat &weight_format)
Performs a mapping from Assembly WeightFormat to the Compute Library WeightFormat enum...