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 <inki.dae@samsung.com>
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
* This callback passes given device types - CPU, GPU, CUSTOM or combinated one if a backend engine supports hybrid inferencea - to a backend engine.
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.
* The backend engine should load the given model files according to a given model file format.
} 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
* of a tensor, which is multi-dimension matix. @a data is the data pointer
std::vector<void *> 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
*
* - 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
*/
int supported_accel_devices;
inference_tensor_shape_type_e supported_tensor_shape_type;
std::vector<std::string> supported_nn_models;
+ bool cltuner_supported;
// TODO.
} inference_engine_capacity;
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<std::string> model_paths,
inference_model_format_e model_format)
{
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_mode_e>(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);