From 5df15c56444fe1b5f770eaca38d8031b5ffe151e Mon Sep 17 00:00:00 2001 From: wejoncy <247153481@qq.com> Date: Tue, 25 Jan 2022 02:17:56 +0800 Subject: [PATCH] additional options of NNAPI for ORT_PERF_TOOL (#10351) * additional options of NNAPI for ORT_PERF_TOOL * reuse current key '-i' * fix * fix * _MSC_VER won't be defined when build with NDK * fix * fix --- .../test/perftest/command_args_parser.cc | 10 ++++++++-- onnxruntime/test/perftest/ort_test_session.cc | 20 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index 7d1a4e8b47..2667060331 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -65,8 +65,8 @@ namespace perftest { "\t [Usage]: -e -i '| |'\n\n" "\t [Example] [For OpenVINO EP] -e openvino -i \"device_type|CPU_FP32 enable_vpu_fast_compile|true num_of_threads|5 use_compiled_network|true blob_dump_path|\"\"\"\n" "\t [TensorRT only] [trt_max_partition_iterations]: Maximum iterations for TensorRT parser to get capability.\n" - "\t [TensorRT only] [trt_min_subgraph_size]: Minimum size of TensorRT subgraphs.\n" - "\t [TensorRT only] [trt_max_workspace_size]: Set TensorRT maximum workspace size in byte.\n" + "\t [TensorRT only] [trt_min_subgraph_size]: Minimum size of TensorRT subgraphs.\n" + "\t [TensorRT only] [trt_max_workspace_size]: Set TensorRT maximum workspace size in byte.\n" "\t [TensorRT only] [trt_fp16_enable]: Enable TensorRT FP16 precision.\n" "\t [TensorRT only] [trt_int8_enable]: Enable TensorRT INT8 precision.\n" "\t [TensorRT only] [trt_int8_calibration_table_name]: Specify INT8 calibration table name.\n" @@ -79,6 +79,12 @@ namespace perftest { "\t [TensorRT only] [trt_force_sequential_engine_build]: Force TensorRT engines to be built sequentially.\n" "\t [Usage]: -e -i '| |'\n\n" "\t [Example] [For TensorRT EP] -e tensorrt -i 'trt_fp16_enable|true trt_int8_enable|true trt_int8_calibration_table_name|calibration.flatbuffers trt_int8_use_native_calibration_table|false trt_force_sequential_engine_build|false'\n" + "\t [NNAPI only] [NNAPI_FLAG_USE_FP16]: Use fp16 relaxation in NNAPI EP..\n" + "\t [NNAPI only] [NNAPI_FLAG_USE_NCHW]: Use the NCHW layout in NNAPI EP.\n" + "\t [NNAPI only] [NNAPI_FLAG_CPU_DISABLED]: Prevent NNAPI from using CPU devices.\n" + "\t [NNAPI only] [NNAPI_FLAG_CPU_ONLY]: Using CPU only in NNAPI EP.\n" + "\t [Usage]: -e -i ' '\n\n" + "\t [Example] [For NNAPI EP] -e nnapi -i \" NNAPI_FLAG_USE_FP16 NNAPI_FLAG_USE_NCHW NNAPI_FLAG_CPU_DISABLED \"\n" "\t-h: help\n"); } #ifdef _WIN32 diff --git a/onnxruntime/test/perftest/ort_test_session.cc b/onnxruntime/test/perftest/ort_test_session.cc index 551709ea62..75a2c178ea 100644 --- a/onnxruntime/test/perftest/ort_test_session.cc +++ b/onnxruntime/test/perftest/ort_test_session.cc @@ -323,7 +323,25 @@ OnnxRuntimeTestSession::OnnxRuntimeTestSession(Ort::Env& env, std::random_device #endif } else if (provider_name == onnxruntime::kNnapiExecutionProvider) { #ifdef USE_NNAPI - Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_Nnapi(session_options, 0)); + uint32_t nnapi_flags = 0; + std::string ov_string = performance_test_config.run_config.ep_runtime_config_string; + std::istringstream ss(ov_string); + std::string key; + while (ss >> key) { + if (key == "NNAPI_FLAG_USE_FP16") { + nnapi_flags |= NNAPI_FLAG_USE_FP16; + } else if (key == "NNAPI_FLAG_USE_NCHW") { + nnapi_flags |= NNAPI_FLAG_USE_NCHW; + } else if (key == "NNAPI_FLAG_CPU_DISABLED") { + nnapi_flags |= NNAPI_FLAG_CPU_DISABLED; + } else if (key == "NNAPI_FLAG_CPU_ONLY") { + nnapi_flags |= NNAPI_FLAG_CPU_ONLY; + } else if (key.empty()) { + } else { + ORT_THROW("[ERROR] [NNAPI] wrong key type entered. Choose from the following runtime key options that are available for NNAPI. ['NNAPI_FLAG_USE_FP16', 'NNAPI_FLAG_USE_NCHW', 'NNAPI_FLAG_CPU_DISABLED', 'NNAPI_FLAG_CPU_ONLY'] \n"); + } + } + Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_Nnapi(session_options, nnapi_flags)); #else ORT_THROW("NNAPI is not supported in this build\n"); #endif