Skip to content

Commit

Permalink
[Android] Try to enhance GPU detection
Browse files Browse the repository at this point in the history
Signed-off-by: Vitalii Koshura <[email protected]>
  • Loading branch information
AenBleidd committed Aug 22, 2023
1 parent b8f67dc commit 5ae2324
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions client/gpu_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,77 @@ void COPROCS::get_opencl(
#else
#ifdef __APPLE__
opencl_lib = dlopen("/System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL", RTLD_NOW);
#elif defined ANDROID
// std::string opencl_lib_path = "/system/vendor/lib/libOpenCL.so";
std::string libarch_name;
if (sizeof(void*) == 8) {
libarch_name = "lib64";
}
else {
libarch_name = "lib";
}

std::string opencl_lib_path;
androidretry:
if (opencl_lib_path.empty()) {
opencl_lib_path = "libOpenCL.so";
}
else if (opencl_lib_path == "libOpenCL.so") {
opencl_lib_path = "libOpenCL.so.1";
}
else if (opencl_lib_path == "libOpenCL.so.1") {
opencl_lib_path = "/vendor/" + libarch_name + "/libOpenCL.so";
}
else if (opencl_lib_path == "/vendor/" + libarch_name + "/libOpenCL.so") {
opencl_lib_path = "/vendor/" + libarch_name + "/egl/libGLES_mali.so";
}
else if (opencl_lib_path == "/vendor/" + libarch_name + "/egl/libGLES_mali.so") {
opencl_lib_path = "/system_ext/" + libarch_name + "libOpenCL_system.so";
}
else if (opencl_lib_path == "/system_ext/" + libarch_name + "libOpenCL_system.so") {
opencl_lib_path = "/vendor/" + libarch_name + "/libGLES_adreno.so";
}
else if (opencl_lib_path == "/vendor/" + libarch_name + "/libGLES_adreno.so") {
opencl_lib_path = "/vendor/" + libarch_name + "/libGLESv2_adreno.so";
}
else if (opencl_lib_path == "/vendor/" + libarch_name + "/libGLESv2_adreno.so") {
opencl_lib_path = "/vendor/" + libarch_name + "/libGLESv3_adreno.so";
}
else if (opencl_lib_path == "/vendor/" + libarch_name + "/libGLESv3_adreno.so") {
opencl_lib_path = "/vendor/" + libarch_name + "/egl/libGLES_adreno.so";
}
else if (opencl_lib_path == "/vendor/" + libarch_name + "/egl/libGLES_adreno.so") {
opencl_lib_path = "/vendor/" + libarch_name + "/egl/libGLESv2_adreno.so";
}
else if (opencl_lib_path == "/vendor/" + libarch_name + "/egl/libGLESv2_adreno.so") {
opencl_lib_path = "/vendor/" + libarch_name + "/egl/libGLESv3_adreno.so";
}
else {
snprintf(buf, sizeof(buf), "OpenCL: %s", dlerror());
gpu_warning(warnings, buf);
goto leave;
}
opencl_lib = dlopen(opencl_lib_path.c_str(), RTLD_NOW);
snprintf(buf, sizeof(buf), "Opening OpenCL: %s", opencl_lib_path.c_str());
gpu_warning(warnings, buf);
if (!opencl_lib) {
snprintf(buf, sizeof(buf), "Failed to open OpenCL: %s", opencl_lib_path.c_str());
gpu_warning(warnings, buf);
goto androidretry;
}
#else
opencl_lib = dlopen("libOpenCL.so", RTLD_NOW);
if (!opencl_lib) {
opencl_lib = dlopen("libOpenCL.so.1", RTLD_NOW);
}
#endif
#ifndef ANDROID
if (!opencl_lib) {
snprintf(buf, sizeof(buf), "OpenCL: %s", dlerror());
gpu_warning(warnings, buf);
return;
}
#endif
p_clGetPlatformIDs = (cl_int(*)(cl_uint, cl_platform_id*, cl_uint*)) dlsym( opencl_lib, "clGetPlatformIDs" );
p_clGetPlatformInfo = (cl_int(*)(cl_platform_id, cl_platform_info, size_t, void*, size_t*)) dlsym( opencl_lib, "clGetPlatformInfo" );
p_clGetDeviceIDs = (cl_int(*)(cl_platform_id, cl_device_type, cl_uint, cl_device_id*, cl_uint*)) dlsym( opencl_lib, "clGetDeviceIDs" );
Expand All @@ -238,25 +298,47 @@ void COPROCS::get_opencl(

if (!p_clGetPlatformIDs) {
gpu_warning(warnings, "clGetPlatformIDs() missing from OpenCL library");
#ifdef ANDROID
goto androidretry;
#else
goto leave;
#endif
}
if (!p_clGetPlatformInfo) {
gpu_warning(warnings, "clGetPlatformInfo() missing from OpenCL library");
#ifdef ANDROID
goto androidretry;
#else
goto leave;
#endif
}
if (!p_clGetDeviceIDs) {
gpu_warning(warnings, "clGetDeviceIDs() missing from OpenCL library");
#ifdef ANDROID
goto androidretry;
#else
goto leave;
#endif
}
if (!p_clGetDeviceInfo) {
gpu_warning(warnings, "clGetDeviceInfo() missing from OpenCL library");
#ifdef ANDROID
goto androidretry;
#else
goto leave;
#endif
}

ciErrNum = (*p_clGetPlatformIDs)(MAX_OPENCL_PLATFORMS, platforms, &num_platforms);
if ((ciErrNum != CL_SUCCESS) || (num_platforms == 0)) {
snprintf(buf, sizeof(buf), "clGetPlatformIDs() failed; error %d, num_platforms", ciErrNum, num_platforms);
gpu_warning(warnings, buf);
gpu_warning(warnings, "clGetPlatformIDs() failed to return any OpenCL platforms");
#ifdef ANDROID
goto androidretry;
#else
goto leave;
#endif
}

if (nvidia_gpus.size()) {
Expand Down

0 comments on commit 5ae2324

Please sign in to comment.