1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Convert.h"
#include "Swizzle.h"
#include "model/operand/DataType.h"
namespace neurun
{
namespace backend
{
namespace acl_cl
{
::arm_compute::TensorShape asTensorShape(const ::neurun::model::operand::Shape &shape,
bool apply_dim_correction)
{
const uint32_t rank = shape.rank();
::arm_compute::TensorShape res{};
res.set_num_dimensions(rank);
for (uint32_t axis = 0; axis < rank; ++axis)
{
// NOTE In some cases, in incorrect dimensions is required.
// For example, intput_size is 1 in LSTM. The input-to-input weights([num_units, input_size]) of
// LSTM is used as the weight of the FullyConnected.
// The FullyConnected's weight must be greater or equal than 2-dimensions.
// However, if the dimension correction is applied to input_to_input_weights with input_size
// equal to 1, it will be changed to 1-D.
// So input_to_input_weights is not used by the weight of FullyConnected.
res.set(ToARMComputeAxis(rank, axis).value(), shape.dim(axis), apply_dim_correction);
}
return res;
}
::arm_compute::DataType asDataType(const ::neurun::model::operand::DataType &type)
{
switch (type)
{
case ::neurun::model::operand::DataType::SCALAR_FLOAT32:
case ::neurun::model::operand::DataType::TENSOR_FLOAT32:
return ::arm_compute::DataType::F32;
case ::neurun::model::operand::DataType::SCALAR_INT32:
case ::neurun::model::operand::DataType::TENSOR_INT32:
return ::arm_compute::DataType::S32;
case ::neurun::model::operand::DataType::SCALAR_UINT32:
return ::arm_compute::DataType::U32;
case ::neurun::model::operand::DataType::TENSOR_QUANT8_ASYMM:
return ::arm_compute::DataType::QASYMM8;
default:
throw std::runtime_error("Not supported, yet");
break;
}
}
::arm_compute::QuantizationInfo asQuantizationInfo(const float scale, const int32_t offset)
{
return ::arm_compute::QuantizationInfo(scale, offset);
}
::arm_compute::TensorInfo asTensorInfo(const ::neurun::model::operand::Shape &shape,
const ::neurun::model::operand::TypeInfo &typeInfo)
{
return ::arm_compute::TensorInfo(asTensorShape(shape), 1, asDataType(typeInfo.type()),
asQuantizationInfo(typeInfo.scale(), typeInfo.offset()));
}
} // namespace acl_cl
} // namespace backend
} // namespace neurun
|