diff options
Diffstat (limited to 'src/backends/backendsCommon/test/DataLayoutUtils.hpp')
-rw-r--r-- | src/backends/backendsCommon/test/DataLayoutUtils.hpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/backends/backendsCommon/test/DataLayoutUtils.hpp b/src/backends/backendsCommon/test/DataLayoutUtils.hpp new file mode 100644 index 0000000000..f89325829e --- /dev/null +++ b/src/backends/backendsCommon/test/DataLayoutUtils.hpp @@ -0,0 +1,36 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <Permute.hpp> + +#include <armnn/Tensor.hpp> +#include <armnn/Types.hpp> + +template<typename T> +void PermuteTensorNchwToNhwc(armnn::TensorInfo& tensorInfo, std::vector<T>& tensorData) +{ + const armnn::PermutationVector nchwToNhwc = { 0, 3, 1, 2 }; + + tensorInfo = armnnUtils::Permuted(tensorInfo, nchwToNhwc); + + std::vector<T> tmp(tensorData.size()); + armnnUtils::Permute(tensorInfo.GetShape(), nchwToNhwc, tensorData.data(), tmp.data(), sizeof(T)); + tensorData = tmp; +} + +template<typename T> +void PermuteTensorNhwcToNchw(armnn::TensorInfo& tensorInfo, std::vector<T>& tensorData) +{ + const armnn::PermutationVector nhwcToNchw = { 0, 2, 3, 1 }; + + tensorInfo = armnnUtils::Permuted(tensorInfo, nhwcToNchw); + + std::vector<T> tmp(tensorData.size()); + armnnUtils::Permute(tensorInfo.GetShape(), nhwcToNchw, tensorData.data(), tmp.data(), sizeof(T)); + + tensorData = tmp; +} |