From 2c398b3968caaa127fc80e1d8b1576de6ae64ae9 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Fri, 18 Aug 2023 00:15:47 +0200 Subject: [PATCH] [Android] Fix GPU detection This fixes #4204. Signed-off-by: Vitalii Koshura --- .../vcpkg_ports/configs/client/android/vcpkg.json | 12 ++++++++++++ android/buildAndroidBOINC-CI.sh | 2 ++ android/build_boinc_arm.sh | 2 +- android/build_boinc_arm64.sh | 2 +- android/build_boinc_armv6.sh | 2 +- android/build_boinc_x86.sh | 2 +- android/build_boinc_x86_64.sh | 2 +- client/gpu_opencl.cpp | 15 +++++++++++++++ 8 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 3rdParty/vcpkg_ports/configs/client/android/vcpkg.json diff --git a/3rdParty/vcpkg_ports/configs/client/android/vcpkg.json b/3rdParty/vcpkg_ports/configs/client/android/vcpkg.json new file mode 100644 index 00000000000..cc4c52083f7 --- /dev/null +++ b/3rdParty/vcpkg_ports/configs/client/android/vcpkg.json @@ -0,0 +1,12 @@ +{ + "name": "boinc-client", + "dependencies": + [ + { + "name": "curl", + "features": ["openssl"], + "default-features": false + }, + "opencl" + ] +} diff --git a/android/buildAndroidBOINC-CI.sh b/android/buildAndroidBOINC-CI.sh index 1b87458b836..fdb317d1587 100755 --- a/android/buildAndroidBOINC-CI.sh +++ b/android/buildAndroidBOINC-CI.sh @@ -211,6 +211,8 @@ fi manifest_dir=$THIRD_PARTY/vcpkg_ports/configs/$component if [ $component = "apps" ]; then manifest_dir=$manifest_dir/android +elif [ $component = "client" ]; then + manifest_dir=$manifest_dir/android fi manifests="--x-manifest-root=$manifest_dir --x-install-root=$VCPKG_ROOT/installed/" vcpkg_overlay="--overlay-ports=$vcpkg_ports_dir/ports --overlay-triplets=$vcpkg_ports_dir/triplets/$triplets_setup" diff --git a/android/build_boinc_arm.sh b/android/build_boinc_arm.sh index 9e41cc7ac77..3f5c3200c81 100755 --- a/android/build_boinc_arm.sh +++ b/android/build_boinc_arm.sh @@ -41,7 +41,7 @@ export CXX=armv7a-linux-androideabi16-clang++ export LD=arm-linux-androideabi-ld export CFLAGS="--sysroot=$TCSYSROOT -DANDROID -DDECLARE_TIMEZONE -Wall -I$TCINCLUDES/include -O3 -fomit-frame-pointer -fPIE -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -D__ANDROID_API__=16" export CXXFLAGS="--sysroot=$TCSYSROOT -DANDROID -Wall -I$TCINCLUDES/include -funroll-loops -fexceptions -O3 -fomit-frame-pointer -fPIE -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -D__ANDROID_API__=16" -export LDFLAGS="$CONFIG_LDFLAGS -llog -fPIE -pie -latomic -static-libstdc++ -march=armv7-a -Wl,--fix-cortex-a8" +export LDFLAGS="$CONFIG_LDFLAGS -llog -fPIE -pie -latomic -lOpenCL -static-libstdc++ -march=armv7-a -Wl,--fix-cortex-a8" export GDB_CFLAGS="--sysroot=$TCSYSROOT -Wall -g -I$TCINCLUDES/include" MAKE_FLAGS="" diff --git a/android/build_boinc_arm64.sh b/android/build_boinc_arm64.sh index 9327e26be7f..09b8e8d3508 100755 --- a/android/build_boinc_arm64.sh +++ b/android/build_boinc_arm64.sh @@ -39,7 +39,7 @@ export CXX=aarch64-linux-android21-clang++ export LD=aarch64-linux-android-ld export CFLAGS="--sysroot=$TCSYSROOT -DANDROID -DANDROID_64 -DDECLARE_TIMEZONE -Wall -I$TCINCLUDES/include -O3 -fomit-frame-pointer -fPIE -D__ANDROID_API__=21" export CXXFLAGS="--sysroot=$TCSYSROOT -DANDROID -DANDROID_64 -Wall -I$TCINCLUDES/include -funroll-loops -fexceptions -O3 -fomit-frame-pointer -fPIE -D__ANDROID_API__=21" -export LDFLAGS="$CONFIG_LDFLAGS -llog -fPIE -pie -latomic -static-libstdc++" +export LDFLAGS="$CONFIG_LDFLAGS -llog -fPIE -pie -latomic -lOpenCL -static-libstdc++" export GDB_CFLAGS="--sysroot=$TCSYSROOT -Wall -g -I$TCINCLUDES/include" MAKE_FLAGS="" diff --git a/android/build_boinc_armv6.sh b/android/build_boinc_armv6.sh index cf6b03d15c3..64b6e118f1b 100755 --- a/android/build_boinc_armv6.sh +++ b/android/build_boinc_armv6.sh @@ -37,7 +37,7 @@ export CXX=arm-linux-androideabi-clang++ export LD=arm-linux-androideabi-ld export CFLAGS="--sysroot=$TCSYSROOT -DANDROID -DDECLARE_TIMEZONE -Wall -I$TCINCLUDES/include -O3 -fomit-frame-pointer -fPIE -march=armv6 -mfloat-abi=softfp -mfpu=vfp -D__ANDROID_API__=16 -DARMV6" export CXXFLAGS="--sysroot=$TCSYSROOT -DANDROID -Wall -I$TCINCLUDES/include -funroll-loops -fexceptions -O3 -fomit-frame-pointer -fPIE -march=armv6 -mfloat-abi=softfp -mfpu=vfp -D__ANDROID_API__=16 -DARMV6" -export LDFLAGS="$CONFIG_LDFLAGS -L$TCSYSROOT/usr/lib -L$TCINCLUDES/lib -llog -fPIE -pie -static-libstdc++ -march=armv6 -lc++_static -lc++abi -landroid_support -lunwind -latomic" +export LDFLAGS="$CONFIG_LDFLAGS -L$TCSYSROOT/usr/lib -L$TCINCLUDES/lib -llog -fPIE -pie -static-libstdc++ -march=armv6 -lc++_static -lc++abi -landroid_support -lunwind -latomic -lOpenCL" export GDB_CFLAGS="--sysroot=$TCSYSROOT -Wall -g -I$TCINCLUDES/include" # Prepare android toolchain and environment diff --git a/android/build_boinc_x86.sh b/android/build_boinc_x86.sh index 2613da7ed1b..6a0db23b0ff 100755 --- a/android/build_boinc_x86.sh +++ b/android/build_boinc_x86.sh @@ -38,7 +38,7 @@ export CXX=i686-linux-android16-clang++ export LD=i686-linux-android-ld export CFLAGS="--sysroot=$TCSYSROOT -DANDROID -DDECLARE_TIMEZONE -Wall -I$TCINCLUDES/include -O3 -fomit-frame-pointer -fPIE -D__ANDROID_API__=16" export CXXFLAGS="--sysroot=$TCSYSROOT -DANDROID -Wall -I$TCINCLUDES/include -funroll-loops -fexceptions -O3 -fomit-frame-pointer -fPIE -D__ANDROID_API__=16" -export LDFLAGS="$CONFIG_LDFLAGS -llog -fPIE -pie -latomic -static-libstdc++" +export LDFLAGS="$CONFIG_LDFLAGS -llog -fPIE -pie -latomic -lOpenCL -static-libstdc++" export GDB_CFLAGS="--sysroot=$TCSYSROOT -Wall -g -I$TCINCLUDES/include" MAKE_FLAGS="" diff --git a/android/build_boinc_x86_64.sh b/android/build_boinc_x86_64.sh index 529eb757d0a..1f5dcab6b22 100755 --- a/android/build_boinc_x86_64.sh +++ b/android/build_boinc_x86_64.sh @@ -39,7 +39,7 @@ export CXX=x86_64-linux-android21-clang++ export LD=x86_64-linux-android-ld export CFLAGS="--sysroot=$TCSYSROOT -DANDROID -DANDROID_64 -DDECLARE_TIMEZONE -Wall -I$TCINCLUDES/include -O3 -fomit-frame-pointer -fPIE -D__ANDROID_API__=21" export CXXFLAGS="--sysroot=$TCSYSROOT -DANDROID -DANDROID_64 -Wall -I$TCINCLUDES/include -funroll-loops -fexceptions -O3 -fomit-frame-pointer -fPIE -D__ANDROID_API__=21" -export LDFLAGS="$CONFIG_LDFLAGS -llog -fPIE -pie -latomic -static-libstdc++" +export LDFLAGS="$CONFIG_LDFLAGS -llog -fPIE -pie -latomic -lOpenCL -static-libstdc++" export GDB_CFLAGS="--sysroot=$TCSYSROOT -Wall -g -I$TCINCLUDES/include" MAKE_FLAGS="" diff --git a/client/gpu_opencl.cpp b/client/gpu_opencl.cpp index 5f0c48a5b11..cb21c716c50 100644 --- a/client/gpu_opencl.cpp +++ b/client/gpu_opencl.cpp @@ -28,8 +28,12 @@ #include #endif #include "config.h" +#ifdef ANDROID +#include +#else #include #endif +#endif #include #include @@ -216,6 +220,11 @@ void COPROCS::get_opencl( p_clGetPlatformInfo = (CL_PLATFORMINFO)GetProcAddress( opencl_lib, "clGetPlatformInfo" ); p_clGetDeviceIDs = (CL_DEVICEIDS)GetProcAddress( opencl_lib, "clGetDeviceIDs" ); p_clGetDeviceInfo = (CL_INFO)GetProcAddress( opencl_lib, "clGetDeviceInfo" ); +#elif defined (ANDROID) + p_clGetPlatformIDs = &clGetPlatformIDs; + p_clGetPlatformInfo = &clGetPlatformInfo; + p_clGetDeviceIDs = &clGetDeviceIDs; + p_clGetDeviceInfo = &clGetDeviceInfo; #else #ifdef __APPLE__ opencl_lib = dlopen("/System/Library/Frameworks/OpenCL.framework/Versions/Current/OpenCL", RTLD_NOW); @@ -256,6 +265,10 @@ void COPROCS::get_opencl( ciErrNum = (*p_clGetPlatformIDs)(MAX_OPENCL_PLATFORMS, platforms, &num_platforms); if ((ciErrNum != CL_SUCCESS) || (num_platforms == 0)) { gpu_warning(warnings, "clGetPlatformIDs() failed to return any OpenCL platforms"); + snprintf(buf, sizeof(buf), "clGetPlatformIDs() return value: %d", ciErrNum); + gpu_warning(warnings, buf); + snprintf(buf, sizeof(buf), "clGetPlatformIDs() num_platforms: %d", num_platforms); + gpu_warning(warnings, buf); goto leave; } @@ -669,6 +682,8 @@ void COPROCS::get_opencl( leave: #ifdef _WIN32 if (opencl_lib) FreeLibrary(opencl_lib); +#elif defined (ANDROID) + return; #else if (opencl_lib) dlclose(opencl_lib); #endif