2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "IACLTensor.h"
28 size_t IACLTensor::dimension(size_t index) const
30 // Assume that the front is higher dimensional.
31 // i.g. N: 0, C: 1, H: 2, W: 3 for NCHW layout
32 // NOTE This tensor must not be applied dim correction
33 auto rank = num_dimensions();
34 rank = rank == 0 ? 1 : rank;
36 const ARMComputeAxis reversed{(static_cast<uint32_t>(rank - index) - 1)};
37 return info()->dimension(reversed.value());
40 size_t IACLTensor::calcOffset(const ir::Coordinates &coords) const
42 auto rank = num_dimensions();
43 rank = rank == 0 ? 1 : rank;
44 assert(rank == coords.size());
46 ::arm_compute::Coordinates acl_coords;
47 for (uint32_t i = 0; i < rank; ++i)
49 const ARMComputeAxis reversed{static_cast<uint32_t>((rank - i) - 1)};
50 acl_coords.set(reversed.value(), coords[i]);
53 return info()->offset_element_in_bytes(acl_coords);
56 ir::Layout IACLTensor::layout() const { return acl_common::asRuntimeLayout(info()->data_layout()); }
58 ir::DataType IACLTensor::data_type() const
60 return acl_common::asRuntimeDataType(info()->data_type());
63 float IACLTensor::data_scale() const
65 // FIXME What if quantization info is non-uniform?
66 return info()->quantization_info().uniform().scale;
69 int32_t IACLTensor::data_offset() const
71 // FIXME What if quantization info is non-uniform?
72 return info()->quantization_info().uniform().offset;
75 } // namespace acl_common
76 } // namespace backend