Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ability to enable NNApi in C api #37636

Merged
merged 3 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions tensorflow/lite/c/c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ TfLiteInterpreter* TfLiteInterpreterCreate(
}

if (optional_options) {
interpreter->UseNNAPI(optional_options->use_nnapi);

if (optional_options->num_threads !=
TfLiteInterpreterOptions::kDefaultNumThreads) {
interpreter->SetNumThreads(optional_options->num_threads);
Expand Down
5 changes: 5 additions & 0 deletions tensorflow/lite/c/c_api_experimental.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ void TfLiteInterpreterOptionsAddCustomOp(TfLiteInterpreterOptions* options,
options->op_resolver.AddCustom(name, registration, min_version, max_version);
}

void TfLiteInterpreterOptionsSetUseNNAPI(TfLiteInterpreterOptions* options,
bool enable) {
options->use_nnapi = enable;
}

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
4 changes: 4 additions & 0 deletions tensorflow/lite/c/c_api_experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ TFL_CAPI_EXPORT void TfLiteInterpreterOptionsAddCustomOp(
const TfLiteRegistration* registration, int32_t min_version,
int32_t max_version);

// Enable or disable the NN API for the interpreter (true to enable).
TFL_CAPI_EXPORT extern void TfLiteInterpreterOptionsSetUseNNAPI(
TfLiteInterpreterOptions* options, bool enable);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
Expand Down
1 change: 1 addition & 0 deletions tensorflow/lite/c/c_api_experimental_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ TEST(CApiExperimentalTest, Smoke) {
TfLiteInterpreterOptions* options = TfLiteInterpreterOptionsCreate();
TfLiteInterpreterOptionsAddBuiltinOp(options, kTfLiteBuiltinAdd,
GetDummyRegistration(), 1, 1);
TfLiteInterpreterOptionsSetUseNNAPI(options, true);

TfLiteInterpreter* interpreter = TfLiteInterpreterCreate(model, options);
ASSERT_NE(interpreter, nullptr);
Expand Down
2 changes: 2 additions & 0 deletions tensorflow/lite/c/c_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct TfLiteInterpreterOptions {
void* error_reporter_user_data = nullptr;

std::vector<TfLiteDelegate*> delegates;

bool use_nnapi = false;
};

struct TfLiteInterpreter {
Expand Down