Expose 'CreateNNAPIDelegate(StatefulNnApiDelegate::Options)' unconditionally,

rather than only on Android.  On unsupported platforms, it will return nullptr.

PiperOrigin-RevId: 333654569
Change-Id: I2dc6f63f7a25c951f6f310acd8c1b52657be7267
This commit is contained in:
Fergus Henderson 2020-09-24 20:22:02 -07:00 committed by TensorFlower Gardener
parent 1d535df0d1
commit cc967a1f37
3 changed files with 9 additions and 14 deletions

View File

@ -41,16 +41,12 @@ cc_library(
copts = tflite_copts(),
deps = [
"//tensorflow/lite/c:common",
"//tensorflow/lite/delegates/nnapi:nnapi_delegate",
] + select({
"//tensorflow/lite/delegates/gpu:supports_gpu_delegate": [
"//tensorflow/lite/delegates/gpu:delegate",
],
"//conditions:default": [],
}) + select({
"//tensorflow:android": [
"//tensorflow/lite/delegates/nnapi:nnapi_delegate",
],
"//conditions:default": [],
}) + select({
"//tensorflow:android_arm": [
"//tensorflow/lite/delegates/hexagon:hexagon_delegate",

View File

@ -105,14 +105,16 @@ TfLiteDelegatePtr CreateNNAPIDelegate() {
#endif // defined(__ANDROID__)
}
#if defined(__ANDROID__)
TfLiteDelegatePtr CreateNNAPIDelegate(StatefulNnApiDelegate::Options options) {
#if defined(__ANDROID__)
return TfLiteDelegatePtr(
new StatefulNnApiDelegate(options), [](TfLiteDelegate* delegate) {
delete reinterpret_cast<StatefulNnApiDelegate*>(delegate);
});
}
#else
return CreateNullDelegate();
#endif // defined(__ANDROID__)
}
#if TFLITE_SUPPORTS_GPU_DELEGATE
TfLiteDelegatePtr CreateGPUDelegate(TfLiteGpuDelegateOptionsV2* options) {

View File

@ -29,12 +29,10 @@ limitations under the License.
#include "tensorflow/lite/delegates/gpu/delegate.h"
#endif
#if defined(__ANDROID__)
#include "tensorflow/lite/delegates/nnapi/nnapi_delegate.h"
#if (defined(__arm__) || defined(__aarch64__))
#if defined(__ANDROID__) && (defined(__arm__) || defined(__aarch64__))
#include "tensorflow/lite/delegates/hexagon/hexagon_delegate.h"
#endif
#endif
// TODO(b/149248802): include XNNPACK delegate when the issue is resolved.
#if !defined(__Fuchsia__) || defined(TFLITE_WITHOUT_XNNPACK)
@ -46,8 +44,8 @@ limitations under the License.
namespace tflite {
namespace evaluation {
// Same w/ Interpreter::TfLiteDelegatePtr to avoid pulling
// tensorflow/lite/interpreter.h dependency
// Same as Interpreter::TfLiteDelegatePtr, defined here to avoid pulling
// in tensorflow/lite/interpreter.h dependency.
using TfLiteDelegatePtr =
std::unique_ptr<TfLiteDelegate, void (*)(TfLiteDelegate*)>;
@ -68,10 +66,9 @@ inline TfLiteStatus GetSortedFileNames(const std::string& directory,
std::unordered_set<std::string>());
}
// Returns nullptr on error, e.g. if NNAPI isn't supported on this platform.
TfLiteDelegatePtr CreateNNAPIDelegate();
#if defined(__ANDROID__)
TfLiteDelegatePtr CreateNNAPIDelegate(StatefulNnApiDelegate::Options options);
#endif
TfLiteDelegatePtr CreateGPUDelegate();
#if TFLITE_SUPPORTS_GPU_DELEGATE