diff options
author | Sadik Armagan <sadik.armagan@arm.com> | 2021-04-21 14:03:28 +0100 |
---|---|---|
committer | Sadik Armagan <sadik.armagan@arm.com> | 2021-04-23 06:55:49 +0000 |
commit | 937565b90bb33eea785898c44db2942dd7af56e7 (patch) | |
tree | c033c6a364a24475e7f8e723519b26ddfddaedc3 /delegate/src/test/CastTest.cpp | |
parent | 48f011e1d5337ff580ae2c315f670bfc15413598 (diff) | |
download | armnn-937565b90bb33eea785898c44db2942dd7af56e7.tar.gz |
IVGCVSW-5430 'Add CAST Operator Support to Delegate'
Signed-off-by: Sadik Armagan <sadik.armagan@arm.com>
Change-Id: I6da711950b8e7d3c0d5cbd443e91eb36700ac4c8
Diffstat (limited to 'delegate/src/test/CastTest.cpp')
-rw-r--r-- | delegate/src/test/CastTest.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/delegate/src/test/CastTest.cpp b/delegate/src/test/CastTest.cpp new file mode 100644 index 0000000000..623c045247 --- /dev/null +++ b/delegate/src/test/CastTest.cpp @@ -0,0 +1,107 @@ +// +// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "CastTestHelper.hpp" + +#include <armnn_delegate.hpp> + +#include <flatbuffers/flatbuffers.h> +#include <tensorflow/lite/schema/schema_generated.h> + +#include <doctest/doctest.h> + +namespace armnnDelegate +{ + +void CastUint8ToFp32Test(std::vector<armnn::BackendId>& backends) +{ + std::vector<int32_t> inputShape {1, 3, 2, 3}; + + std::vector<uint8_t> inputValues { 1, 3, 1, 3, 1, 3, 1, 3, 1, + 3, 1, 3, 1, 2, 1, 3, 1, 3 }; + + std::vector<float> expectedOutputValues { 1.0f, 3.0f, 1.0f, 3.0f, 1.0f, 3.0f, 1.0f, 3.0f, 1.0f, + 3.0f, 1.0f, 3.0f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f }; + + CastTest<uint8_t, float>(::tflite::TensorType_UINT8, + ::tflite::TensorType_FLOAT32, + backends, + inputShape, + inputValues, + expectedOutputValues); +} + +void CastInt32ToFp32Test(std::vector<armnn::BackendId>& backends) +{ + std::vector<int32_t> inputShape {1, 3, 2, 3}; + + std::vector<int32_t> inputValues { -1, -3, -1, -3, -1, -3, -1, -3, 1, + 3, 1, 3, 1, 2, 1, 3, 1, 3 }; + + std::vector<float> expectedOutputValues { -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, -1.0f, -3.0f, 1.0f, + 3.0f, 1.0f, 3.0f, 1.0f, 2.0f, 1.0f, 3.0f, 1.0f, 3.0f }; + + CastTest<int32_t, float>(::tflite::TensorType_INT32, + ::tflite::TensorType_FLOAT32, + backends, + inputShape, + inputValues, + expectedOutputValues); +} + +// CAST Test Suite +TEST_SUITE("CAST_CpuRefTests") +{ + +TEST_CASE ("CAST_UINT8_TO_FP32_CpuRef_Test") +{ + std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef}; + CastUint8ToFp32Test(backends); +} + +TEST_CASE ("CAST_INT32_TO_FP32_CpuRef_Test") +{ + std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef}; + CastInt32ToFp32Test(backends); +} + +} + +TEST_SUITE("CAST_CpuAccTests") +{ + +TEST_CASE ("CAST_UINT8_TO_FP32_CpuAcc_Test") +{ + std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc}; + CastUint8ToFp32Test(backends); +} + +TEST_CASE ("CAST_INT32_TO_FP32_CpuAcc_Test") +{ + std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc}; + CastInt32ToFp32Test(backends); +} + +} + +TEST_SUITE("CAST_GpuAccTests") +{ + +TEST_CASE ("CAST_UINT8_TO_FP32_GpuAcc_Test") +{ + std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc}; + CastUint8ToFp32Test(backends); +} + +TEST_CASE ("CAST_INT32_TO_FP32_GpuAcc_Test") +{ + std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc}; + CastInt32ToFp32Test(backends); +} + +} +// End of CAST Test Suite + +} // namespace armnnDelegate
\ No newline at end of file |