aboutsummaryrefslogtreecommitdiff
path: root/delegate/test/ElementwiseUnaryTest.cpp
diff options
context:
space:
mode:
authorTeresa Charlin <teresa.charlinreyes@arm.com>2023-03-14 12:10:28 +0000
committerTeresa Charlin <teresa.charlinreyes@arm.com>2023-03-28 11:41:55 +0100
commitad1b3d7518429e2d16a2695d9b0bbf81b6565ac9 (patch)
treea5b8e1ad68a2437f007338f0b6195ca5ed2bddc3 /delegate/test/ElementwiseUnaryTest.cpp
parent9cb3466b677a1048b8abb24661e92c4c83fdda04 (diff)
downloadarmnn-ad1b3d7518429e2d16a2695d9b0bbf81b6565ac9.tar.gz
IVGCVSW-7555 Restructure Delegate
* New folders created: * common is for common code where TfLite API is not used * classic is for existing delegate implementations * opaque is for new opaque delegate implementation, * tests is for shared between existing Delegate and Opaque Delegate which have test utils to work which delegate to use. * Existing delegate is built to libarmnnDelegate.so and opaque delegate is built as libarmnnOpaqueDelegate.so * Opaque structure is introduced but no API is added yet. * CmakeList.txt and delegate/CMakeList.txt have been modified and 2 new CmakeList.txt added * Rename BUILD_ARMNN_TFLITE_DELEGATE as BUILD_CLASSIC_DELEGATE * Rename BUILD_ARMNN_TFLITE_OPAQUE_DELEGATE as BUILD_OPAQUE_DELEGATE Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com> Change-Id: Ib682b9ad0ac8d8acdc4ec6d9099bb0008a9fe8ed
Diffstat (limited to 'delegate/test/ElementwiseUnaryTest.cpp')
-rw-r--r--delegate/test/ElementwiseUnaryTest.cpp420
1 files changed, 420 insertions, 0 deletions
diff --git a/delegate/test/ElementwiseUnaryTest.cpp b/delegate/test/ElementwiseUnaryTest.cpp
new file mode 100644
index 0000000000..6331436308
--- /dev/null
+++ b/delegate/test/ElementwiseUnaryTest.cpp
@@ -0,0 +1,420 @@
+//
+// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ElementwiseUnaryTestHelper.hpp"
+
+#include <armnn_delegate.hpp>
+
+#include <flatbuffers/flatbuffers.h>
+#include <tensorflow/lite/interpreter.h>
+#include <tensorflow/lite/kernels/register.h>
+#include <tensorflow/lite/model.h>
+#include <schema_generated.h>
+#include <tensorflow/lite/version.h>
+
+#include <doctest/doctest.h>
+
+namespace armnnDelegate
+{
+
+TEST_SUITE("ElementwiseUnary_GpuAccTests")
+{
+
+TEST_CASE ("Abs_Float32_GpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ -0.1f, -0.2f, -0.3f,
+ 0.1f, 0.2f, 0.3f
+ };
+ // Calculate output data
+ std::vector<float> expectedOutputValues(inputValues.size());
+ for (unsigned int i = 0; i < inputValues.size(); ++i)
+ {
+ expectedOutputValues[i] = std::abs(inputValues[i]);
+ }
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_ABS, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Exp_Float32_GpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 5.0f, 4.0f,
+ 3.0f, 2.0f,
+ 1.0f, 1.1f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 148.413159102577f, 54.598150033144f,
+ 20.085536923188f, 7.389056098931f,
+ 2.718281828459f, 3.004166023946f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_EXP, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Log_Float32_GpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 1.0f, 1.0f, 2.0f,
+ 3.0f, 4.0f, 2.71828f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 0.f, 0.f, 0.69314718056f,
+ 1.09861228867f, 1.38629436112f, 0.99999932734f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_LOG, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Neg_Float32_GpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 1.f, 0.f, 3.f,
+ 25.f, 64.f, 100.f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ -1.f, 0.f, -3.f,
+ -25.f, -64.f, -100.f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_NEG, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Rsqrt_Float32_GpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 1.f, 4.f, 16.f,
+ 25.f, 64.f, 100.f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 1.f, 0.5f, 0.25f,
+ 0.2f, 0.125f, 0.1f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_RSQRT, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Sin_Float32_GpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 0.0f, 1.0f, 16.0f,
+ 0.5f, 36.0f, -1.f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 0.0f, 0.8414709848f, -0.28790331666f,
+ 0.4794255386f, -0.99177885344f, -0.8414709848f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_SIN, backends, inputValues, expectedOutputValues);
+}
+} // TEST_SUITE("ElementwiseUnary_GpuAccTests")
+
+
+
+TEST_SUITE("ElementwiseUnary_CpuAccTests")
+{
+
+TEST_CASE ("Abs_Float32_CpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ -0.1f, -0.2f, -0.3f,
+ 0.1f, 0.2f, 0.3f
+ };
+ // Calculate output data
+ std::vector<float> expectedOutputValues(inputValues.size());
+ for (unsigned int i = 0; i < inputValues.size(); ++i)
+ {
+ expectedOutputValues[i] = std::abs(inputValues[i]);
+ }
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_ABS, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Exp_Float32_CpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 5.0f, 4.0f,
+ 3.0f, 2.0f,
+ 1.0f, 1.1f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 148.413159102577f, 54.598150033144f,
+ 20.085536923188f, 7.389056098931f,
+ 2.718281828459f, 3.004166023946f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_EXP, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Log_Float32_CpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 1.0f, 1.0f, 2.0f,
+ 3.0f, 4.0f, 2.71828f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 0.f, 0.f, 0.69314718056f,
+ 1.09861228867f, 1.38629436112f, 0.99999932734f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_LOG, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Neg_Float32_CpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 1.f, 0.f, 3.f,
+ 25.f, 64.f, 100.f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ -1.f, 0.f, -3.f,
+ -25.f, -64.f, -100.f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_NEG, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Rsqrt_Float32_CpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 1.f, 4.f, 16.f,
+ 25.f, 64.f, 100.f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 1.f, 0.5f, 0.25f,
+ 0.2f, 0.125f, 0.1f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_RSQRT, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Sin_Float32_CpuAcc_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 0.0f, 1.0f, 16.0f,
+ 0.5f, 36.0f, -1.f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 0.0f, 0.8414709848f, -0.28790331666f,
+ 0.4794255386f, -0.99177885344f, -0.8414709848f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_SIN, backends, inputValues, expectedOutputValues);
+}
+} // TEST_SUITE("ElementwiseUnary_CpuAccTests")
+
+TEST_SUITE("ElementwiseUnary_CpuRefTests")
+{
+
+TEST_CASE ("Abs_Float32_CpuRef_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ -0.1f, -0.2f, -0.3f,
+ 0.1f, 0.2f, 0.3f
+ };
+ // Calculate output data
+ std::vector<float> expectedOutputValues(inputValues.size());
+ for (unsigned int i = 0; i < inputValues.size(); ++i)
+ {
+ expectedOutputValues[i] = std::abs(inputValues[i]);
+ }
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_ABS, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Exp_Float32_CpuRef_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 5.0f, 4.0f,
+ 3.0f, 2.0f,
+ 1.0f, 1.1f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 148.413159102577f, 54.598150033144f,
+ 20.085536923188f, 7.389056098931f,
+ 2.718281828459f, 3.004166023946f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_EXP, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Log_Float32_CpuRef_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 1.0f, 1.0f, 2.0f,
+ 3.0f, 4.0f, 2.71828f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 0.f, 0.f, 0.69314718056f,
+ 1.09861228867f, 1.38629436112f, 0.99999932734f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_LOG, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Neg_Float32_CpuRef_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 1.f, 0.f, 3.f,
+ 25.f, 64.f, 100.f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ -1.f, 0.f, -3.f,
+ -25.f, -64.f, -100.f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_NEG, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Rsqrt_Float32_CpuRef_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 1.f, 4.f, 16.f,
+ 25.f, 64.f, 100.f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 1.f, 0.5f, 0.25f,
+ 0.2f, 0.125f, 0.1f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_RSQRT, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Sqrt_Float32_CpuRef_Test")
+{
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 9.0f, 4.25f, 81.9f,
+ 0.1f, 0.9f, 169.0f
+ };
+ // Calculate output data
+ std::vector<float> expectedOutputValues(inputValues.size());
+ for (unsigned int i = 0; i < inputValues.size(); ++i)
+ {
+ expectedOutputValues[i] = std::sqrt(inputValues[i]);
+ }
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_SQRT, backends, inputValues, expectedOutputValues);
+}
+
+TEST_CASE ("Sin_Float32_CpuRef_Test")
+{
+ // Create the ArmNN Delegate
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ // Set input data
+ std::vector<float> inputValues
+ {
+ 0.0f, 1.0f, 16.0f,
+ 0.5f, 36.0f, -1.f
+ };
+ // Set output data
+ std::vector<float> expectedOutputValues
+ {
+ 0.0f, 0.8414709848f, -0.28790331666f,
+ 0.4794255386f, -0.99177885344f, -0.8414709848f
+ };
+
+ ElementwiseUnaryFP32Test(tflite::BuiltinOperator_SIN, backends, inputValues, expectedOutputValues);
+}
+} // TEST_SUITE("ElementwiseUnary_CpuRefTests")
+
+} // namespace armnnDelegate \ No newline at end of file