aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/test/DataLayoutUtils.hpp
blob: f89325829ed5c8c7b9d1a374fdcdfe17a32d0c4b (plain)
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
//
// 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;
}