From f39f8d8597c59057118f67cacf70d246f95fea9b Mon Sep 17 00:00:00 2001 From: Jan Eilers Date: Tue, 26 Oct 2021 16:57:34 +0100 Subject: Move command line parsing in external delegate to DelegateOptions * Moves the creation of a DelegateOption object from armnn_external_delegate to DelegateOptions. * This allows this code to be reused elsewhere * Allow boolean values of DelegateOptions to be passed as strings e.g. 'true' or 'false' * Add unit tests Signed-off-by: Jan Eilers Change-Id: I0ada17f511027dd3f47a85142cae346464682f5a --- delegate/src/test/DelegateOptionsTest.cpp | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'delegate/src/test') diff --git a/delegate/src/test/DelegateOptionsTest.cpp b/delegate/src/test/DelegateOptionsTest.cpp index 338772596b..54f9c8f0e3 100644 --- a/delegate/src/test/DelegateOptionsTest.cpp +++ b/delegate/src/test/DelegateOptionsTest.cpp @@ -223,6 +223,90 @@ TEST_CASE ("ArmnnDelegateSerializeToDot") fs::remove(filename); } +void CreateFp16StringParsingTestRun(std::vector& keys, + std::vector& values, + std::stringstream& ss) +{ + StreamRedirector redirect(std::cout, ss.rdbuf()); + + std::vector backends = { armnn::Compute::CpuRef }; + std::vector tensorShape { 1, 2, 2, 1 }; + std::vector inputData = { 1, 2, 3, 4 }; + std::vector divData = { 2, 2, 3, 4 }; + std::vector expectedResult = { 1, 2, 2, 2 }; + + // Create options_keys and options_values char array + size_t num_options = keys.size(); + std::unique_ptr options_keys = + std::unique_ptr(new const char*[num_options + 1]); + std::unique_ptr options_values = + std::unique_ptr(new const char*[num_options + 1]); + for (size_t i=0; i(::tflite::TensorType_FLOAT32, + backends, + tensorShape, + inputData, + inputData, + divData, + expectedResult, + delegateOptions); +} + +TEST_CASE ("ArmnnDelegateStringParsingOptionReduceFp32ToFp16") +{ + SUBCASE("Fp16=1") + { + std::stringstream ss; + std::vector keys { "backends", "debug-data", "reduce-fp32-to-fp16", "logging-severity"}; + std::vector values { "CpuRef", "1", "1", "info"}; + CreateFp16StringParsingTestRun(keys, values, ss); + CHECK(ss.str().find("convert_fp32_to_fp16") != std::string::npos); + CHECK(ss.str().find("convert_fp16_to_fp32") != std::string::npos); + } + SUBCASE("Fp16=true") + { + std::stringstream ss; + std::vector keys { "backends", "debug-data", "reduce-fp32-to-fp16"}; + std::vector values { "CpuRef", "TRUE", "true"}; + CreateFp16StringParsingTestRun(keys, values, ss); + CHECK(ss.str().find("convert_fp32_to_fp16") != std::string::npos); + CHECK(ss.str().find("convert_fp16_to_fp32") != std::string::npos); + } + SUBCASE("Fp16=True") + { + std::stringstream ss; + std::vector keys { "backends", "debug-data", "reduce-fp32-to-fp16"}; + std::vector values { "CpuRef", "true", "True"}; + CreateFp16StringParsingTestRun(keys, values, ss); + CHECK(ss.str().find("convert_fp32_to_fp16") != std::string::npos); + CHECK(ss.str().find("convert_fp16_to_fp32") != std::string::npos); + } + SUBCASE("Fp16=0") + { + std::stringstream ss; + std::vector keys { "backends", "debug-data", "reduce-fp32-to-fp16"}; + std::vector values { "CpuRef", "true", "0"}; + CreateFp16StringParsingTestRun(keys, values, ss); + CHECK(ss.str().find("convert_fp32_to_fp16") == std::string::npos); + CHECK(ss.str().find("convert_fp16_to_fp32") == std::string::npos); + } + SUBCASE("Fp16=false") + { + std::stringstream ss; + std::vector keys { "backends", "debug-data", "reduce-fp32-to-fp16"}; + std::vector values { "CpuRef", "1", "false"}; + CreateFp16StringParsingTestRun(keys, values, ss); + CHECK(ss.str().find("convert_fp32_to_fp16") == std::string::npos); + CHECK(ss.str().find("convert_fp16_to_fp32") == std::string::npos); + } +} + } -- cgit v1.2.1