aboutsummaryrefslogtreecommitdiff
path: root/include/armnnTestUtils/DataLayoutUtils.hpp
diff options
context:
space:
mode:
authorSadik Armagan <sadik.armagan@arm.com>2021-11-24 15:47:28 +0000
committerSadik Armagan <sadik.armagan@arm.com>2021-12-14 11:02:41 +0000
commita097d2a0ed8e30d5aaf6d29ec18d0c39201b7b67 (patch)
tree947e587bc42d07f52c55b155308b5ea5bd3ebacd /include/armnnTestUtils/DataLayoutUtils.hpp
parentbc14881a76699dd942e94265116da68a6466455e (diff)
downloadarmnn-a097d2a0ed8e30d5aaf6d29ec18d0c39201b7b67.tar.gz
IVGCVSW-6453 'Move the ArmNN Test Utils code to a physically separate directory'
* Created include/armnnTestUtils directory * Moved Arm NN test utils files into armnnTestUtils directory Signed-off-by: Sadik Armagan <sadik.armagan@arm.com> Change-Id: I03ac54c645c41c52650c4c03b6a58fb1481fef5d
Diffstat (limited to 'include/armnnTestUtils/DataLayoutUtils.hpp')
-rw-r--r--include/armnnTestUtils/DataLayoutUtils.hpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/include/armnnTestUtils/DataLayoutUtils.hpp b/include/armnnTestUtils/DataLayoutUtils.hpp
new file mode 100644
index 0000000000..fde6f172cc
--- /dev/null
+++ b/include/armnnTestUtils/DataLayoutUtils.hpp
@@ -0,0 +1,60 @@
+//
+// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <armnn/Tensor.hpp>
+#include <armnn/Types.hpp>
+
+#include <armnnUtils/Permute.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;
+}
+
+template<typename T>
+void PermuteTensorNdhwcToNcdhw(armnn::TensorInfo& tensorInfo, std::vector<T>& tensorData)
+{
+ const armnn::PermutationVector ndhwcToNcdhw = { 0, 2, 3, 4, 1 };
+
+ tensorInfo = armnnUtils::Permuted(tensorInfo, ndhwcToNcdhw);
+
+ std::vector<T> tmp(tensorData.size());
+ armnnUtils::Permute(tensorInfo.GetShape(), ndhwcToNcdhw, tensorData.data(), tmp.data(), sizeof(T));
+ tensorData = tmp;
+}
+
+template<typename T>
+void PermuteTensorNcdhwToNdhwc(armnn::TensorInfo& tensorInfo, std::vector<T>& tensorData)
+{
+ const armnn::PermutationVector ncdhwToNdhwc = { 0, 4, 1, 2, 3 };
+
+ tensorInfo = armnnUtils::Permuted(tensorInfo, ncdhwToNdhwc);
+
+ std::vector<T> tmp(tensorData.size());
+ armnnUtils::Permute(tensorInfo.GetShape(), ncdhwToNdhwc, tensorData.data(), tmp.data(), sizeof(T));
+ tensorData = tmp;
+}