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:
parent
1d535df0d1
commit
cc967a1f37
@ -41,16 +41,12 @@ cc_library(
|
|||||||
copts = tflite_copts(),
|
copts = tflite_copts(),
|
||||||
deps = [
|
deps = [
|
||||||
"//tensorflow/lite/c:common",
|
"//tensorflow/lite/c:common",
|
||||||
|
"//tensorflow/lite/delegates/nnapi:nnapi_delegate",
|
||||||
] + select({
|
] + select({
|
||||||
"//tensorflow/lite/delegates/gpu:supports_gpu_delegate": [
|
"//tensorflow/lite/delegates/gpu:supports_gpu_delegate": [
|
||||||
"//tensorflow/lite/delegates/gpu:delegate",
|
"//tensorflow/lite/delegates/gpu:delegate",
|
||||||
],
|
],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}) + select({
|
|
||||||
"//tensorflow:android": [
|
|
||||||
"//tensorflow/lite/delegates/nnapi:nnapi_delegate",
|
|
||||||
],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}) + select({
|
}) + select({
|
||||||
"//tensorflow:android_arm": [
|
"//tensorflow:android_arm": [
|
||||||
"//tensorflow/lite/delegates/hexagon:hexagon_delegate",
|
"//tensorflow/lite/delegates/hexagon:hexagon_delegate",
|
||||||
|
@ -105,14 +105,16 @@ TfLiteDelegatePtr CreateNNAPIDelegate() {
|
|||||||
#endif // defined(__ANDROID__)
|
#endif // defined(__ANDROID__)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
|
||||||
TfLiteDelegatePtr CreateNNAPIDelegate(StatefulNnApiDelegate::Options options) {
|
TfLiteDelegatePtr CreateNNAPIDelegate(StatefulNnApiDelegate::Options options) {
|
||||||
|
#if defined(__ANDROID__)
|
||||||
return TfLiteDelegatePtr(
|
return TfLiteDelegatePtr(
|
||||||
new StatefulNnApiDelegate(options), [](TfLiteDelegate* delegate) {
|
new StatefulNnApiDelegate(options), [](TfLiteDelegate* delegate) {
|
||||||
delete reinterpret_cast<StatefulNnApiDelegate*>(delegate);
|
delete reinterpret_cast<StatefulNnApiDelegate*>(delegate);
|
||||||
});
|
});
|
||||||
}
|
#else
|
||||||
|
return CreateNullDelegate();
|
||||||
#endif // defined(__ANDROID__)
|
#endif // defined(__ANDROID__)
|
||||||
|
}
|
||||||
|
|
||||||
#if TFLITE_SUPPORTS_GPU_DELEGATE
|
#if TFLITE_SUPPORTS_GPU_DELEGATE
|
||||||
TfLiteDelegatePtr CreateGPUDelegate(TfLiteGpuDelegateOptionsV2* options) {
|
TfLiteDelegatePtr CreateGPUDelegate(TfLiteGpuDelegateOptionsV2* options) {
|
||||||
|
@ -29,12 +29,10 @@ limitations under the License.
|
|||||||
#include "tensorflow/lite/delegates/gpu/delegate.h"
|
#include "tensorflow/lite/delegates/gpu/delegate.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
|
||||||
#include "tensorflow/lite/delegates/nnapi/nnapi_delegate.h"
|
#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"
|
#include "tensorflow/lite/delegates/hexagon/hexagon_delegate.h"
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO(b/149248802): include XNNPACK delegate when the issue is resolved.
|
// TODO(b/149248802): include XNNPACK delegate when the issue is resolved.
|
||||||
#if !defined(__Fuchsia__) || defined(TFLITE_WITHOUT_XNNPACK)
|
#if !defined(__Fuchsia__) || defined(TFLITE_WITHOUT_XNNPACK)
|
||||||
@ -46,8 +44,8 @@ limitations under the License.
|
|||||||
namespace tflite {
|
namespace tflite {
|
||||||
namespace evaluation {
|
namespace evaluation {
|
||||||
|
|
||||||
// Same w/ Interpreter::TfLiteDelegatePtr to avoid pulling
|
// Same as Interpreter::TfLiteDelegatePtr, defined here to avoid pulling
|
||||||
// tensorflow/lite/interpreter.h dependency
|
// in tensorflow/lite/interpreter.h dependency.
|
||||||
using TfLiteDelegatePtr =
|
using TfLiteDelegatePtr =
|
||||||
std::unique_ptr<TfLiteDelegate, void (*)(TfLiteDelegate*)>;
|
std::unique_ptr<TfLiteDelegate, void (*)(TfLiteDelegate*)>;
|
||||||
|
|
||||||
@ -68,10 +66,9 @@ inline TfLiteStatus GetSortedFileNames(const std::string& directory,
|
|||||||
std::unordered_set<std::string>());
|
std::unordered_set<std::string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns nullptr on error, e.g. if NNAPI isn't supported on this platform.
|
||||||
TfLiteDelegatePtr CreateNNAPIDelegate();
|
TfLiteDelegatePtr CreateNNAPIDelegate();
|
||||||
#if defined(__ANDROID__)
|
|
||||||
TfLiteDelegatePtr CreateNNAPIDelegate(StatefulNnApiDelegate::Options options);
|
TfLiteDelegatePtr CreateNNAPIDelegate(StatefulNnApiDelegate::Options options);
|
||||||
#endif
|
|
||||||
|
|
||||||
TfLiteDelegatePtr CreateGPUDelegate();
|
TfLiteDelegatePtr CreateGPUDelegate();
|
||||||
#if TFLITE_SUPPORTS_GPU_DELEGATE
|
#if TFLITE_SUPPORTS_GPU_DELEGATE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user