Exclude Pixel-specific code from compilation when not on Android.
PiperOrigin-RevId: 313288675 Change-Id: I5883edf3fc9f90eb6d7bdeac02bb32bd2949ff7b
This commit is contained in:
parent
6a0bdbdb7c
commit
3f423f882b
@ -26,21 +26,27 @@ namespace tflite {
|
||||
namespace gpu {
|
||||
namespace cl {
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#define LoadFunction(function) \
|
||||
if (is_pixel) { \
|
||||
function = reinterpret_cast<PFN_##function>(loadOpenCLPointer(#function)); \
|
||||
} else { \
|
||||
function = reinterpret_cast<PFN_##function>(dlsym(libopencl, #function)); \
|
||||
}
|
||||
#else
|
||||
#define LoadFunction(function) \
|
||||
function = reinterpret_cast<PFN_##function>(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());
|
||||
#ifdef __ANDROID__
|
||||
// Pixel phone?
|
||||
libopencl = dlopen("libOpenCL-pixel.so", RTLD_NOW | RTLD_LOCAL);
|
||||
if (libopencl) {
|
||||
@ -50,20 +56,21 @@ absl::Status LoadOpenCL() {
|
||||
enableOpenCL();
|
||||
LoadOpenCLFunctions(libopencl, true);
|
||||
return absl::OkStatus();
|
||||
} else {
|
||||
}
|
||||
#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<loadOpenCLPointer_t>(
|
||||
dlsym(libopencl, "loadOpenCLPointer"));
|
||||
}
|
||||
#endif
|
||||
|
||||
LoadFunction(clGetPlatformIDs);
|
||||
LoadFunction(clGetPlatformInfo);
|
||||
|
Loading…
Reference in New Issue
Block a user