[Fix #11447] Use correct type for tensor shape vectors (#11448)

* [Fix] Use correct type for tensor shape vectors

* Replacing std::vector with absl::InlinedVector

* Remove explicit use of absl:: namespace;
Add back explicit size in constructors.

* Remove explicit size for InlinedVector
This commit is contained in:
GPhilo 2022-06-07 18:06:32 +02:00 committed by GitHub
parent b4f1e769c0
commit 40f4304c7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@
#include <cmath>
#include "core/common/common.h"
#include "core/common/inlined_containers.h"
#include "core/framework/op_kernel.h"
#include "core/util/math.h"
#include "core/util/math_cpuonly.h"
@ -37,9 +38,9 @@ ACLNEPool PoolOperation(onnxruntime::OpKernelContext* context,
const Tensor* X = context->Input<Tensor>(0);
const TensorShape& x_shape = X->Shape();
std::vector<int64_t> pads = pool_attrs.pads;
std::vector<int64_t> strides = pool_attrs.strides;
std::vector<int64_t> kernel_shape = pool_attrs.kernel_shape;
auto pads = pool_attrs.pads;
auto strides = pool_attrs.strides;
auto kernel_shape = pool_attrs.kernel_shape;
if (pool_attrs.global_pooling) {
const auto& input_dims = x_shape.GetDims();
@ -47,7 +48,7 @@ ACLNEPool PoolOperation(onnxruntime::OpKernelContext* context,
pads.assign(kernel_shape.size(), 0);
}
std::vector<int64_t> output_dims = pool_attrs.SetOutputSize(x_shape, x_shape[1], &pads);
const auto& output_dims = pool_attrs.SetOutputSize(x_shape, x_shape[1], &pads);
Tensor* Y = context->Output(0, TensorShape(output_dims));
ACLNEPool tpool;
@ -63,11 +64,11 @@ ACLNEPool PoolOperation(onnxruntime::OpKernelContext* context,
if (pool_attrs.global_pooling) {
layer->configure(tpool.in.get(), tpool.out.get(), arm_compute::PoolingLayerInfo(pool_type));
} else {
std::vector<int64_t> aclStrides(2);
TensorShapeVector aclStrides(2);
aclStrides[0] = (strides.size() == 2) ? strides[1] : 1;
aclStrides[1] = strides[0];
std::vector<int64_t> aclPads(4);
InlinedVector<int64_t> aclPads(4);
// The pad order in acl is: pad_left, pad_right, pad_top, pad_bottom
if (pads.size() == 2) {
if (strides.size() == 1) {
@ -91,7 +92,7 @@ ACLNEPool PoolOperation(onnxruntime::OpKernelContext* context,
arm_compute::PadStrideInfo aclPadStride = arm_compute::PadStrideInfo(aclStrides[0], aclStrides[1],
aclPads[0], aclPads[1], aclPads[2], aclPads[3], arm_compute::DimensionRoundingType::FLOOR);
std::vector<int64_t> aclKernelShape(2);
TensorShapeVector aclKernelShape(2);
aclKernelShape[0] = (kernel_shape.size() > 1) ? kernel_shape[1] : 1;
aclKernelShape[1] = kernel_shape[0];
@ -145,8 +146,8 @@ Status Pool<T, PoolType>::Compute(OpKernelContext* context) const {
const Tensor* X = context->Input<Tensor>(0);
std::vector<int64_t> dilations(PoolBase::pool_attrs_.dilations);
std::vector<int64_t> aclDilations(2);
TensorShapeVector dilations(PoolBase::pool_attrs_.dilations);
InlinedVector<int64_t> aclDilations(2);
aclDilations[0] = (dilations.size() == 2) ? dilations[1] : 1;
aclDilations[1] = (!dilations.empty()) ? dilations[0] : 1;
@ -191,8 +192,8 @@ template <typename T>
Status MaxPoolV8<T>::Compute(OpKernelContext* context) const {
const Tensor* X = context->Input<Tensor>(0);
std::vector<int64_t> dilations(PoolBase::pool_attrs_.dilations);
std::vector<int64_t> aclDilations(2);
TensorShapeVector dilations(PoolBase::pool_attrs_.dilations);
InlinedVector<int64_t> aclDilations(2);
aclDilations[0] = (dilations.size() == 2) ? dilations[1] : 1;
aclDilations[1] = (!dilations.empty()) ? dilations[0] : 1;