Use a heavier but more accurate way to obtain information about applying delegate, and update the fyi message accordingly.

PiperOrigin-RevId: 322100537
Change-Id: I5ded22b26e0bdbfb908cbcea80aff0744a550e01
This commit is contained in:
Chao Mei 2020-07-20 02:12:55 -07:00 committed by TensorFlower Gardener
parent 102603bc11
commit 0a6475b416

View File

@ -650,26 +650,38 @@ TfLiteStatus BenchmarkTfLiteModel::Init() {
<< " delegate.";
return kTfLiteError;
} else {
bool fully_delegated = true;
if (interpreter_->execution_plan().size() != 1) {
fully_delegated = false;
} else {
int first_node_id = interpreter_->execution_plan()[0];
const TfLiteNode first_node =
interpreter_->node_and_registration(first_node_id)->first;
if (delegate.get() != first_node.delegate) {
fully_delegated = false;
// Ideally, such delegate info should already be computed when the
// delegate is being applied to the model graph.
int num_delegated_kernels = 0;
for (int i = 0; i < interpreter_->execution_plan().size(); ++i) {
int node_id = interpreter_->execution_plan()[i];
const TfLiteNode& node =
interpreter_->node_and_registration(node_id)->first;
if (delegate.get() == node.delegate) {
num_delegated_kernels++;
}
}
bool fully_delegated = (num_delegated_kernels == 1 &&
interpreter_->execution_plan().size() == 1);
if (params_.Get<bool>("require_full_delegation") && !fully_delegated) {
TFLITE_LOG(ERROR) << "Disallowed CPU fallback detected.";
return kTfLiteError;
}
const std::string delegate_status =
fully_delegated ? "completely" : "partially";
TFLITE_LOG(INFO) << "Applied " << delegate_provider->GetName()
<< " delegate, and the model graph will be "
<< delegate_status << " executed w/ the delegate.";
if (fully_delegated) {
TFLITE_LOG(INFO) << "Applied " << delegate_provider->GetName()
<< " delegate, and the model graph will be completely"
<< " executed by the delegate.";
} else if (num_delegated_kernels > 0) {
TFLITE_LOG(INFO) << "Applied " << delegate_provider->GetName()
<< " delegate, and the model graph will be partially"
<< " executed by the delegate w/ "
<< num_delegated_kernels << " delegate kernels.";
} else {
TFLITE_LOG(INFO) << "Though " << delegate_provider->GetName()
<< " delegate is applied, the model graph will not be"
<< " executed by the delegate.";
}
}
owned_delegates_.emplace_back(std::move(delegate));
}