diff options
author | Jan Eilers <jan.eilers@arm.com> | 2021-10-26 16:57:34 +0100 |
---|---|---|
committer | Jan Eilers <jan.eilers@arm.com> | 2021-11-02 11:49:32 +0000 |
commit | f39f8d8597c59057118f67cacf70d246f95fea9b (patch) | |
tree | 35c6f5b1b641a143d29e1ce478877f9e2b251569 /delegate/src/test/DelegateOptionsTest.cpp | |
parent | 32c7527df494a99a97283fe09580671e10f8d398 (diff) | |
download | armnn-f39f8d8597c59057118f67cacf70d246f95fea9b.tar.gz |
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 <jan.eilers@arm.com>
Change-Id: I0ada17f511027dd3f47a85142cae346464682f5a
Diffstat (limited to 'delegate/src/test/DelegateOptionsTest.cpp')
-rw-r--r-- | delegate/src/test/DelegateOptionsTest.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
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<std::string>& keys, + std::vector<std::string>& values, + std::stringstream& ss) +{ + StreamRedirector redirect(std::cout, ss.rdbuf()); + + std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; + std::vector<int32_t> tensorShape { 1, 2, 2, 1 }; + std::vector<float> inputData = { 1, 2, 3, 4 }; + std::vector<float> divData = { 2, 2, 3, 4 }; + std::vector<float> expectedResult = { 1, 2, 2, 2 }; + + // Create options_keys and options_values char array + size_t num_options = keys.size(); + std::unique_ptr<const char*> options_keys = + std::unique_ptr<const char*>(new const char*[num_options + 1]); + std::unique_ptr<const char*> options_values = + std::unique_ptr<const char*>(new const char*[num_options + 1]); + for (size_t i=0; i<num_options; ++i) + { + options_keys.get()[i] = keys[i].c_str(); + options_values.get()[i] = values[i].c_str(); + } + + armnnDelegate::DelegateOptions delegateOptions(options_keys.get(), options_values.get(), num_options, nullptr); + DelegateOptionTest<float>(::tflite::TensorType_FLOAT32, + backends, + tensorShape, + inputData, + inputData, + divData, + expectedResult, + delegateOptions); +} + +TEST_CASE ("ArmnnDelegateStringParsingOptionReduceFp32ToFp16") +{ + SUBCASE("Fp16=1") + { + std::stringstream ss; + std::vector<std::string> keys { "backends", "debug-data", "reduce-fp32-to-fp16", "logging-severity"}; + std::vector<std::string> 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<std::string> keys { "backends", "debug-data", "reduce-fp32-to-fp16"}; + std::vector<std::string> 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<std::string> keys { "backends", "debug-data", "reduce-fp32-to-fp16"}; + std::vector<std::string> 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<std::string> keys { "backends", "debug-data", "reduce-fp32-to-fp16"}; + std::vector<std::string> 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<std::string> keys { "backends", "debug-data", "reduce-fp32-to-fp16"}; + std::vector<std::string> 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); + } +} + } |