From 9b11335534002668914fa1cd8a3c50daa2a634a0 Mon Sep 17 00:00:00 2001 From: Sachin Joglekar Date: Wed, 15 Apr 2020 10:14:15 -0700 Subject: [PATCH] Fix Hexagon unit tests by reducing min nodes per partitions to 1 PiperOrigin-RevId: 306667501 Change-Id: Id91da849cd77dd8861786841d8194c5e6d2a04fb --- .../hexagon/builders/tests/hexagon_delegate_op_model.h | 2 ++ .../lite/experimental/delegates/hexagon/hexagon_delegate.cc | 5 ++++- .../lite/experimental/delegates/hexagon/hexagon_delegate.h | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tensorflow/lite/experimental/delegates/hexagon/builders/tests/hexagon_delegate_op_model.h b/tensorflow/lite/experimental/delegates/hexagon/builders/tests/hexagon_delegate_op_model.h index e2c63e4b8b1..9fd9dc69172 100644 --- a/tensorflow/lite/experimental/delegates/hexagon/builders/tests/hexagon_delegate_op_model.h +++ b/tensorflow/lite/experimental/delegates/hexagon/builders/tests/hexagon_delegate_op_model.h @@ -44,6 +44,8 @@ class SingleOpModelWithHexagon : public SingleOpModel { "vendor/lib/rfsa/adsp;/dsp", 1 /*overwrite*/); + // For tests, we use one-op-models. + params_.min_nodes_per_partition = 1; auto* delegate_ptr = TfLiteHexagonDelegateCreate(¶ms_); ASSERT_TRUE(delegate_ptr != nullptr); delegate_ = Interpreter::TfLiteDelegatePtr( diff --git a/tensorflow/lite/experimental/delegates/hexagon/hexagon_delegate.cc b/tensorflow/lite/experimental/delegates/hexagon/hexagon_delegate.cc index 20d74605baa..8810df4257f 100644 --- a/tensorflow/lite/experimental/delegates/hexagon/hexagon_delegate.cc +++ b/tensorflow/lite/experimental/delegates/hexagon/hexagon_delegate.cc @@ -95,7 +95,7 @@ TfLiteStatus DelegatePrepare(TfLiteContext* context, TfLiteDelegate* delegate) { TfLiteHexagonDelegateOptions* params = static_cast(delegate->data_); const auto delegate_partitions = helper.GetFirstNLargestPartitions( - params->max_delegated_partitions, kMinNodesPerHexagonGraph); + params->max_delegated_partitions, params->min_nodes_per_partition); // To avoid creating a new TfLiteIntArray and free it later, we reserve one // element to represent TfLiteIntArray.size which is the 1st element of @@ -133,6 +133,9 @@ class HexagonDelegate : public TfLiteDelegate { params_.max_delegated_partitions, kMaxMaxHexagonGraphs); params_.max_delegated_partitions = kMaxMaxHexagonGraphs; } + if (params_.min_nodes_per_partition <= 0) { + params_.min_nodes_per_partition = kMinNodesPerHexagonGraph; + } } TfLiteHexagonDelegateOptions* params() { return ¶ms_; } diff --git a/tensorflow/lite/experimental/delegates/hexagon/hexagon_delegate.h b/tensorflow/lite/experimental/delegates/hexagon/hexagon_delegate.h index 4995605e9fb..d3230f1376e 100644 --- a/tensorflow/lite/experimental/delegates/hexagon/hexagon_delegate.h +++ b/tensorflow/lite/experimental/delegates/hexagon/hexagon_delegate.h @@ -55,6 +55,9 @@ struct TFL_CAPI_EXPORT TfLiteHexagonDelegateOptions { // hexagon_nn_init. Each graph corresponds to one delegated node subset in the // TFLite model. int max_delegated_partitions; + // This sets the minimum number of nodes per graph created with + // hexagon_nn_init. Defaults to 2. + int min_nodes_per_partition; }; // Return a delegate that uses Hexagon SDK for ops execution. -- GitLab