Skip to content

Commit

Permalink
[Android] Fix GPU detection
Browse files Browse the repository at this point in the history
This fixes #4204.

Signed-off-by: Vitalii Koshura <[email protected]>
  • Loading branch information
AenBleidd committed Aug 18, 2023
1 parent 640be40 commit 2c398b3
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 5 deletions.
12 changes: 12 additions & 0 deletions 3rdParty/vcpkg_ports/configs/client/android/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "boinc-client",
"dependencies":
[
{
"name": "curl",
"features": ["openssl"],
"default-features": false
},
"opencl"
]
}
2 changes: 2 additions & 0 deletions android/buildAndroidBOINC-CI.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion android/build_boinc_arm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down
2 changes: 1 addition & 1 deletion android/build_boinc_arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down
2 changes: 1 addition & 1 deletion android/build_boinc_armv6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion android/build_boinc_x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down
2 changes: 1 addition & 1 deletion android/build_boinc_x86_64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down
15 changes: 15 additions & 0 deletions client/gpu_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
#include <mach-o/dyld.h>
#endif
#include "config.h"
#ifdef ANDROID
#include <CL/cl.h>
#else
#include <dlfcn.h>
#endif
#endif

#include <vector>
#include <string>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c398b3

Please sign in to comment.