Compute Library
 22.05
LegacySupport.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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 detail
29 {
30 namespace
31 {
32 DataType convert_to_legacy_data_type(AclDataType data_type)
33 {
34  switch(data_type)
35  {
37  return DataType::F32;
39  return DataType::F16;
41  return DataType::BFLOAT16;
42  default:
43  return DataType::UNKNOWN;
44  }
45 }
46 
47 AclDataType convert_to_c_data_type(DataType data_type)
48 {
49  switch(data_type)
50  {
51  case DataType::F32:
53  case DataType::F16:
55  case DataType::BFLOAT16:
57  default:
59  }
60 }
61 
62 TensorShape create_legacy_tensor_shape(int32_t ndims, int32_t *shape)
63 {
64  TensorShape legacy_shape{};
65  for(int32_t d = 0; d < ndims; ++d)
66  {
67  legacy_shape.set(d, shape[d], false);
68  }
69  return legacy_shape;
70 }
71 int32_t *create_tensor_shape_array(const TensorInfo &info)
72 {
73  const auto num_dims = info.num_dimensions();
74  if(num_dims <= 0)
75  {
76  return nullptr;
77  }
78 
79  int32_t *shape_array = new int32_t[num_dims];
80 
81  for(size_t d = 0; d < num_dims; ++d)
82  {
83  shape_array[d] = info.tensor_shape()[d];
84  }
85 
86  return shape_array;
87 }
88 } // namespace
89 
91 {
92  TensorInfo legacy_desc;
93  legacy_desc.init(create_legacy_tensor_shape(desc.ndims, desc.shape), 1, convert_to_legacy_data_type(desc.data_type));
94  return legacy_desc;
95 }
96 
98 {
99  const auto num_dims = info.num_dimensions();
101  {
102  static_cast<int32_t>(num_dims),
103  create_tensor_shape_array(info),
104  convert_to_c_data_type(info.data_type()),
105  nullptr,
106  0
107  };
108  return desc;
109 }
110 
112 {
114  switch(desc.type)
115  {
118  break;
121  break;
124  break;
127  break;
130  break;
133  break;
136  break;
139  break;
142  break;
145  break;
148  break;
151  break;
154  break;
157  break;
158  default:
159  return ActivationLayerInfo();
160  }
161 
162  return ActivationLayerInfo(act, desc.a, desc.b);
163 }
164 } // namespace detail
165 } // namespace arm_compute
32-bit floating point
Definition: AclTypes.h:173
Lower and Upper Bounded Rectifier.
AclDataType
Definition: AclTypes.h:162
Soft Rectifier.
Square.
Unknown data type.
Definition: AclTypes.h:164
1 channel, 1 F32 per channel
TensorInfo convert_to_legacy_tensor_info(const AclTensorDescriptor &desc)
Convert a descriptor to a legacy format one.
float b
Factor &beta used by some activations.
Activation Layer Information class.
Definition: Types.h:1625
AclActivationType type
Activation type.
int32_t ndims
Number or dimensions.
Definition: AclTypes.h:193
Copyright (c) 2017-2022 Arm Limited.
ActivationFunction
Available activation functions.
Definition: Types.h:1629
1 channel, 1 F16 per channel
DataType data_type() const override
Data type used for each element of the tensor.
Definition: TensorInfo.h:242
16-bit brain floating-point number
Upper Bounded Rectifier.
size_t num_dimensions() const override
The number of dimensions of the tensor (rank)
Definition: TensorInfo.h:226
Hard-swish.
Logistic.
Square root.
Linear.
Rectifier.
Exponential Linear Unit.
void init(Format format)
Initialize the tensor info with just a format.
Definition: TensorInfo.cpp:103
Leaky Rectifier.
16-bit brain floating point
Definition: AclTypes.h:172
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
16-bit floating point
Definition: AclTypes.h:171
AclDataType data_type
Tensor Data type.
Definition: AclTypes.h:195
Hyperbolic tangent.
Absolute.
float a
Factor &alpha used by some activations.
Identity.
AclTensorDescriptor convert_to_descriptor(const TensorInfo &info)
Convert a legacy tensor meta-data to a descriptor.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
int32_t * shape
Tensor Shape.
Definition: AclTypes.h:194
DataType
Available data types.
Definition: Types.h:79
ActivationLayerInfo convert_to_activation_info(const AclActivationDescriptor &desc)
Convert an AclActivation descriptor to an internal one.