#include <unistd.h>
#include <time.h>
#include <queue>
+#include <algorithm>
#include <armnn/ArmNN.hpp>
#include <armnn/backends/ITensorHandle.hpp>
InferenceARMNN::InferenceARMNN(void) :
mNetwork(armnn::INetworkPtr(nullptr, nullptr)),
- mNetworkIdentifier(-1)
+ mNetworkIdentifier(-1),
+ mCLTuner()
{
LOGI("ENTER");
LOGI("LEAVE");
mOutputBindingInfo.clear();
std::vector<armnn::BindingPointInfo>().swap(mOutputBindingInfo);
+ armnn::IRuntime::Destroy(sRuntime);
sRuntime = nullptr;
}
return INFERENCE_ENGINE_ERROR_NONE;
}
+
+ int InferenceARMNN::SetCLTuner(const inference_engine_cltuner *cltuner)
+ {
+ LOGI("ENTER");
+
+ if (cltuner == NULL) {
+ LOGE("cltuner is NULL.");
+ return INFERENCE_ENGINE_ERROR_INVALID_PARAMETER;
+ }
+
+ mCLTuner = *cltuner;
+
+ LOGI("CLTuner is %s", mCLTuner.active ? "used" : "not used");
+
+ if (mCLTuner.active) {
+ LOGI("Update mode is %s", mCLTuner.update ? "enabled" : "disabled");
+ LOGI("tuning_mode is %d\n", mCLTuner.tuning_mode);
+ LOGI("A given tuned file path is %s", mCLTuner.file_path.c_str());
+ }
+
+ LOGI("LEAVE");
+
+ return INFERENCE_ENGINE_ERROR_NONE;
+ }
+
int InferenceARMNN::CreateTfLiteNetwork(std::string model_path)
{
LOGI("ENTER");
armnn::IRuntime::CreationOptions creation_options;
+ // The use of CLTuner is valid only in case of GpuAcc request.
+ if (mCLTuner.active && UseGpuAcc()) {
+ std::string tune_path = model_paths[0] + ".tune";
+
+ // file_path can be set by user. So if file_path is given then
+ // user-given path will be passed to a given inference engine.
+ // On the other hand, if file_path is empty then default
+ // path - "model file path + .tune" - will be passed to the
+ // inference engine.
+ if (!mCLTuner.file_path.empty())
+ tune_path = mCLTuner.file_path;
+
+ LOGI("CLTuner tuning file name is %s", tune_path.c_str());
+
+ // If CLTuner is read only mode then set INFERENCE_ENGINE_CLTUNER_READ
+ // to TuningLevel.
+ // Ps. if TuningLevel is INFERENCE_ENGINE_CLTUNER_READ then
+ // ARMCL will read a tuned file for inference.
+ if (mCLTuner.update == false) {
+ LOGI("CLTuner mode is read only.");
+ mCLTuner.tuning_mode = INFERENCE_ENGINE_CLTUNER_READ;
+ }
+
+ creation_options.m_BackendOptions.emplace_back(
+ armnn::BackendOptions
+ {
+ "GpuAcc",
+ {
+ {"TuningLevel", static_cast<int>(mCLTuner.tuning_mode)},
+ {"TuningFile", tune_path.c_str()}
+ }
+ }
+ );
+ }
+
if (sRuntime == nullptr) {
sRuntime = armnn::IRuntime::CreateRaw(creation_options);
LOGI("Created ARMNN runtime");
capacity->supported_accel_devices = INFERENCE_TARGET_CPU |
INFERENCE_TARGET_GPU;
+ capacity->cltuner_supported = true;
LOGI("LEAVE");
return ret;
}
+ bool InferenceARMNN::UseGpuAcc(void)
+ {
+ return (std::find(mAccelType.begin(), mAccelType.end(),
+ armnn::Compute::GpuAcc) != mAccelType.end());
+ }
+
int InferenceARMNN::Run(
std::vector<inference_engine_tensor_buffer> &input_buffers,
std::vector<inference_engine_tensor_buffer> &output_buffers)
int SetTargetDevices(int types) override;
+ int SetCLTuner(const inference_engine_cltuner *cltuner) final;
+
int Load(std::vector<std::string> model_paths,
inference_model_format_e model_format) override;
int CheckTensorBuffers(
std::vector<inference_engine_tensor_buffer> &input_buffers,
std::vector<inference_engine_tensor_buffer> &output_buffers);
+ bool UseGpuAcc(void);
std::vector<armnn::BackendId> mAccelType;
std::vector<armnn::BindingPointInfo> mOutputBindingInfo;
std::vector<std::string> mDesignated_inputs;
std::vector<std::string> mDesignated_outputs;
+ inference_engine_cltuner mCLTuner;
};
} /* InferenceEngineImpl */