From 5ae23241be06ca1a42dcf60070b7104c2669b117 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Tue, 22 Aug 2023 01:33:08 +0200 Subject: [PATCH] [Android] Try to enhance GPU detection Signed-off-by: Vitalii Koshura --- client/gpu_opencl.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/client/gpu_opencl.cpp b/client/gpu_opencl.cpp index 5f0c48a5b11..d892c81bf82 100644 --- a/client/gpu_opencl.cpp +++ b/client/gpu_opencl.cpp @@ -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" ); @@ -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()) {