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 <lestat.de.lionkur@gmail.com>
  • Loading branch information
AenBleidd committed Aug 22, 2023
1 parent b8f67dc commit 821695d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
1 change: 0 additions & 1 deletion android/BOINC/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 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), "OpenCL: %s", dlerror());
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 Expand Up @@ -665,6 +747,10 @@ void COPROCS::get_opencl(
(other_opencls.size() == 0)
) {
gpu_warning(warnings, "OpenCL library present but no OpenCL-capable devices found");
#ifdef ANDROID
gpu_warning(warnings, "OpenCL: trying alternate library");
goto androidretry;
#endif
}
leave:
#ifdef _WIN32
Expand Down

0 comments on commit 821695d

Please sign in to comment.