From: Inki Dae Date: Thu, 21 Jan 2021 07:36:37 +0000 (+0900) Subject: Add CLTuner support X-Git-Tag: submit/tizen/20210422.072212~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9c6930315e7cbf41f2ce73da5a566eab54ff6e79;p=platform%2Fcore%2Fmultimedia%2Finference-engine-interface.git Add CLTuner support Added CLTuner support. For CLTuner support, this patch adds a new internal API, SetCLTuner function. This function passes user-given CLTuner configuration to MLAPI and ARMNN backends before inference engine loads a given model file. [How to use] There are two CLTuner modes: READ : inference engine refers to a given tuned file for inference. GENERATION : inference engine generates a tuning file to a given model file. And there are three CLTuner types: EXHAUSTIVE : The tuning speed is slow but aggressive optimization. NORMAL : The tuning speed is reasonable and reasonable optimization. RAPID : The tuning speed is fast but leient optimization. - For CLTuner read mode, inference_engine_cltuner cltuner = { .active = true, .update = false, .cltuner.type = INFERENCE_ENGINE_CLTUNER_READ, }; - For CLTuner generation mode, inference_engine_cltuner cltuner = { .active = true, .update = true, .cltuner.type = INFERENCE_ENGINE_CLTUNER_{EXHAUSTIVE | NORMAL | RAPID}, }; inference_engine_capacity capacity; engine->GetBackendCapacity(&capacity); if (capacity.cltuner_supported) engine->SetCLTuner(&cltuner); Change-Id: Id1cc9513e444dfad21b933b46535c1b810f4a4d6 Signed-off-by: Inki Dae --- diff --git a/include/inference_engine_common.h b/include/inference_engine_common.h index 3321509..d7db0d5 100644 --- a/include/inference_engine_common.h +++ b/include/inference_engine_common.h @@ -41,6 +41,15 @@ namespace Common */ virtual int SetPrivateData(void *data) = 0; + /** + * @brief Set CLTuner configuration. + * @details This callback passes a given CLTuner configuration value to inference engine if the inference engine supports for CLTuner feature. + * + * @since_tizen 6.5 + * @param[in] cltuner This contains CLTuner configuration value. See inference_engine_cltuner structure and inference_engine_cltuner_mode_e enumeration. + */ + virtual int SetCLTuner(const inference_engine_cltuner *cltuner) = 0; + /** * @brief Set target devices. * @details See #inference_target_type_e diff --git a/include/inference_engine_common_impl.h b/include/inference_engine_common_impl.h index 63cfe7b..5966557 100644 --- a/include/inference_engine_common_impl.h +++ b/include/inference_engine_common_impl.h @@ -83,6 +83,15 @@ namespace Common */ int SetTargetDevices(int types); + /** + * @brief Set CLTuner configuration. + * @details This callback passes a given CLTuner configuration value to inference engine if the inference engine supports for CLTuner feature. + * + * @since_tizen 6.5 + * @param[in] cltuner This contains CLTuner configuration value. See inference_engine_cltuner structure and inference_engine_cltuner_mode_e enumeration. + */ + int SetCLTuner(const inference_engine_cltuner *cltuner); + /** * @brief Request to load model data with user-given model file information. * @details This callback requests a backend engine to load given model files for inference. diff --git a/include/inference_engine_type.h b/include/inference_engine_type.h index 0e42792..3e8a46f 100644 --- a/include/inference_engine_type.h +++ b/include/inference_engine_type.h @@ -106,6 +106,20 @@ extern "C" INFERENCE_TENSOR_DATA_TYPE_MAX } inference_tensor_data_type_e; + /** + * @brief Enumeration for OPenCL Tuner type. + * + * @since_tizen 6.5 + */ + typedef enum { + INFERENCE_ENGINE_CLTUNER_MIN = -1, + INFERENCE_ENGINE_CLTUNER_READ, /** < CLTuner mode is read only. */ + INFERENCE_ENGINE_CLTUNER_EXHAUSTIVE, /** < The tuning speed is slow but aggressive optimization. */ + INFERENCE_ENGINE_CLTUNER_NORMAL, /** < The tuning speed is reasonable and reasonable optimization. */ + INFERENCE_ENGINE_CLTUNER_RAPID, /** < The tuning speed is fast but lenient optimization. */ + INFERENCE_ENGINE_CLTUNER_MAX + } inference_engine_cltuner_mode_e; + /** * @brief Tensor defined by the dimension and their corresponding data * @details @a dimInfo is the information @@ -129,6 +143,13 @@ extern "C" std::vector data; } tensor_t; + typedef struct _inference_engine_cltuner { + bool active; /** < Indicate that CLTuner feature of a given inference engine is avaliable. */ + bool update; /** < Find optimal LWS paramaters if update is true, otherwise it uses a pre-tuned file for inference if the pre-tuned file exists. This type is valid only in case that active is true. */ + inference_engine_cltuner_mode_e tuning_mode; /** < Tuning mode of CLTUner. This is valid only in case that active is true. */ + std::string file_path; /** < a full path of turned file. This path is valid only in case that active is true. */ + } inference_engine_cltuner; + /** * @brief Inference engine backend configuration * @@ -204,6 +225,7 @@ extern "C" * - device list which is able to compute operations. * - tensor shape information a given backend engine supports for. * - neural network models a given backend engine supports for. + * - Indicate that a given backend supports CLTuner feature. @since_tizen 6.5 * * @since_tizen 6.0 */ @@ -211,6 +233,7 @@ extern "C" int supported_accel_devices; inference_tensor_shape_type_e supported_tensor_shape_type; std::vector supported_nn_models; + bool cltuner_supported; // TODO. } inference_engine_capacity; diff --git a/src/inference_engine_common_impl.cpp b/src/inference_engine_common_impl.cpp index 4ef465f..4bc8222 100644 --- a/src/inference_engine_common_impl.cpp +++ b/src/inference_engine_common_impl.cpp @@ -467,6 +467,23 @@ namespace Common return ret; } + int InferenceEngineCommon::SetCLTuner(const inference_engine_cltuner *cltuner) + { + CHECK_ENGINE_INSTANCE(mBackendHandle); + + if (cltuner->active && (cltuner->tuning_mode <= INFERENCE_ENGINE_CLTUNER_MIN || + cltuner->tuning_mode >= INFERENCE_ENGINE_CLTUNER_MAX)) { + LOGE("Invalid tuning mode of CLTuner.(%d)", cltuner->tuning_mode); + return INFERENCE_ENGINE_ERROR_INVALID_PARAMETER; + } + + int ret = mBackendHandle->SetCLTuner(cltuner); + if (ret != INFERENCE_ENGINE_ERROR_NONE) + LOGE("Fail to SetCLTuner"); + + return ret; + } + int InferenceEngineCommon::Load(std::vector model_paths, inference_model_format_e model_format) { diff --git a/test/src/inference_engine_profiler.cpp b/test/src/inference_engine_profiler.cpp index 81581f0..c97dfa1 100644 --- a/test/src/inference_engine_profiler.cpp +++ b/test/src/inference_engine_profiler.cpp @@ -161,6 +161,16 @@ TEST_P(InferenceEngineTfliteTest, Inference) ret = engine->GetBackendCapacity(&capacity); EXPECT_EQ(ret, INFERENCE_ENGINE_ERROR_NONE); + if (capacity.cltuner_supported) { + inference_engine_cltuner cltuner; + cltuner.active = true; + cltuner.update = false; + cltuner.tuning_mode = static_cast(INFERENCE_ENGINE_CLTUNER_READ); + + ret = engine->SetCLTuner(&cltuner); + EXPECT_EQ(ret, INFERENCE_ENGINE_ERROR_NONE); + } + ret = engine->SetTargetDevices(target_devices); EXPECT_EQ(ret, INFERENCE_ENGINE_ERROR_NONE);