From 3f423f882b7dd975799fdc6872e00172676c0b54 Mon Sep 17 00:00:00 2001 From: Robert David Date: Tue, 26 May 2020 16:23:56 -0700 Subject: [PATCH] Exclude Pixel-specific code from compilation when not on Android. PiperOrigin-RevId: 313288675 Change-Id: I5883edf3fc9f90eb6d7bdeac02bb32bd2949ff7b --- .../lite/delegates/gpu/cl/opencl_wrapper.cc | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc b/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc index fadaabe32a0..bdaa807d83c 100644 --- a/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc +++ b/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc @@ -26,44 +26,51 @@ namespace tflite { namespace gpu { namespace cl { +#ifdef __ANDROID__ #define LoadFunction(function) \ if (is_pixel) { \ function = reinterpret_cast(loadOpenCLPointer(#function)); \ } else { \ function = reinterpret_cast(dlsym(libopencl, #function)); \ } +#else +#define LoadFunction(function) \ + function = reinterpret_cast(dlsym(libopencl, #function)); +#endif absl::Status LoadOpenCL() { void* libopencl = dlopen("libOpenCL.so", RTLD_NOW | RTLD_LOCAL); if (libopencl) { LoadOpenCLFunctions(libopencl, false); return absl::OkStatus(); - } else { - // record error - std::string error(dlerror()); - // Pixel phone? - libopencl = dlopen("libOpenCL-pixel.so", RTLD_NOW | RTLD_LOCAL); - if (libopencl) { - typedef void (*enableOpenCL_t)(); - enableOpenCL_t enableOpenCL = - reinterpret_cast(dlsym(libopencl, "enableOpenCL")); - enableOpenCL(); - LoadOpenCLFunctions(libopencl, true); - return absl::OkStatus(); - } else { - return absl::UnknownError( - absl::StrCat("Can not open OpenCL library on this device - ", error)); - } } + // record error + std::string error(dlerror()); +#ifdef __ANDROID__ + // Pixel phone? + libopencl = dlopen("libOpenCL-pixel.so", RTLD_NOW | RTLD_LOCAL); + if (libopencl) { + typedef void (*enableOpenCL_t)(); + enableOpenCL_t enableOpenCL = + reinterpret_cast(dlsym(libopencl, "enableOpenCL")); + enableOpenCL(); + LoadOpenCLFunctions(libopencl, true); + return absl::OkStatus(); + } +#endif + return absl::UnknownError( + absl::StrCat("Can not open OpenCL library on this device - ", error)); } void LoadOpenCLFunctions(void* libopencl, bool is_pixel) { +#ifdef __ANDROID__ typedef void* (*loadOpenCLPointer_t)(const char* name); loadOpenCLPointer_t loadOpenCLPointer; if (is_pixel) { loadOpenCLPointer = reinterpret_cast( dlsym(libopencl, "loadOpenCLPointer")); } +#endif LoadFunction(clGetPlatformIDs); LoadFunction(clGetPlatformInfo);