Skip to content

Commit 9c86aec

Browse files
terryheotensorflower-gardener
authored andcommitted
litert: Enable GPU Accelerator on Android
- Added build target for libLiteRtGpuAccelerator.so PiperOrigin-RevId: 732300108
1 parent f19e248 commit 9c86aec

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

tensorflow/lite/experimental/litert/cc/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ cc_test(
459459
# "@com_google_absl//absl/log:absl_log",
460460
# "@com_google_absl//absl/strings:string_view",
461461
# "@com_google_absl//absl/types:span",
462-
# "//third_party/odml/infra/ml_drift_delegate:ml_drift_cl_accelerator", # buildcleaner: keep
462+
# "//third_party/odml/infra/ml_drift_delegate/litert:ml_drift_cl_accelerator", # buildcleaner: keep
463463
# "//tensorflow/lite:framework",
464464
# "//tensorflow/lite/c:c_api_opaque",
465465
# "//tensorflow/lite/c:common",

tensorflow/lite/experimental/litert/core/environment.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "tensorflow/lite/experimental/litert/core/environment.h"
1616

17+
#include <dlfcn.h>
18+
1719
#include <memory>
1820
#include <string>
1921
#include <utility>
@@ -43,7 +45,12 @@ litert::Expected<LiteRtEnvironmentT::Ptr> LiteRtEnvironmentT::CreateWithOptions(
4345
}
4446

4547
// Find `LiteRtRegisterAcceleratorGpuOpenCl` to register the GPU delegate.
46-
void* lib_opencl = nullptr;
48+
static void* lib_opencl =
49+
tflite::SharedLibrary::LoadLibrary("libLiteRtGpuAccelerator.so");
50+
if (!lib_opencl) {
51+
// If the library is not found, find the symbol in the current library.
52+
lib_opencl = RTLD_DEFAULT;
53+
}
4754
auto opencl_registrar_func = reinterpret_cast<void (*)(LiteRtEnvironment)>(
4855
tflite::SharedLibrary::GetLibrarySymbol(
4956
lib_opencl, "LiteRtRegisterAcceleratorGpuOpenCl"));

0 commit comments

Comments
 (0)