Closed liguobing closed 1 year ago
release编译使用的so库就是我发的,但是头文件应该是不一样的,release的opencl部分代码是纯C的,而Anime4KCPP_Android则用了OpenCL官方的cpp封装库。
还是so库的兼容性问题,sdk的so库我换过,然后忘记了😓。 release的so库应该是zuk z2里扒下来的,我发的sdk的so库是从一款联想的855手机里扒下来的。我用release的代码链接现在的so库一样一堆问题。
但是不知道是不是因为z2的so库版本太老(骁龙820),在855上测试GPU跑OpenCL性能比使用Eigen3的CPU慢得多(也可能是手机的GPU带宽瓶颈)。
zukz2libOpenCL_arm64-v8a.zip(不是很确定这个so库到底是不是arm64的,AS会提示不兼容但是又可以链接上并正常工作)
EDIT:非常离谱且无语,我发现现在用AS的bug在编译链接上armv7的OpenCL库就可以工作,具体就是先用arm64的库编译一遍然后然后替换so库再点编译就能链接上armv7的库,而且一切正常???估计那个z2的so库也是armv7的,怀疑是安卓版本或者编译目标SDK版本的问题。
感谢您的回复,这几天我试了各种操作,都不行,各种出错,头发都快薅秃了。
我按照您的操作试了一下,好像还是不行,您看下是不是我的理解有问题
我的操作步骤如下:
还是使用 opencl.zip 中的 so 库和头文件
1.修改 build.gradle,将 include 'arm64-v8a','armeabi-v7a' 中的 'armeabi-v7a' 删除,这样只保留了编译 arm64 2.在 AndroidStudio 中 rebuild 这里 rebuild 成功 3.替换 lib 中 'arm64-v8a' 目录下的 libOpenCL.so 为 'armeabi-v7a' 下的 so 文件 4.rebuild 这里 rebuild 不成功,报错如下
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[2/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/ACCuda.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[3/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CPUAnime4K09.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[4/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/ACNCNN.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[5/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CPUCNNProcessor.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[6/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/ACCreator.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[7/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCPPWrapper.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[8/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CPUACNet.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[9/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/AC.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[10/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CPUACNetProcessor.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[11/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CudaAnime4K09.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[12/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/NCNNACNet.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[13/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/OpenCLACNet.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[14/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CudaACNet.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[15/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/FilterProcessor.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[16/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/VideoProcessor.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[17/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/OpenCLAnime4K09.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[18/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/VideoIO.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[19/19] Linking CXX shared library E:\Work_Space\Anime4KCPP_Android\app\build\intermediates\cxx\Debug\5av2r2w1\obj\arm64-v8a\libAnime4KCPPCore.so
FAILED: E:/Work_Space/Anime4KCPP_Android/app/build/intermediates/cxx/Debug/5av2r2w1/obj/arm64-v8a/libAnime4KCPPCore.so
cmd.exe /C "cd . && D:\AndroidSDK\ndk\21.3.6528147\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android24 --gcc-toolchain=D:/AndroidSDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/AndroidSDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -std=c++17 -frtti -fexceptions -O3 -static-openmp -fopenmp -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libAnime4KCPPCore.so -o E:\Work_Space\Anime4KCPP_Android\app\build\intermediates\cxx\Debug\5av2r2w1\obj\arm64-v8a\libAnime4KCPPCore.so @CMakeFiles\Anime4KCPPCore.rsp && cd ."
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Execution failed for task ':app:buildCMakeDebug[arm64-v8a]'.
> com.android.ide.common.process.ProcessException: ninja: Entering directory `E:\Work_Space\Anime4KCPP_Android\app\.cxx\Debug\5av2r2w1\arm64-v8a'
[1/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/ACOpenCL.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[2/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/ACCuda.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[3/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CPUAnime4K09.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[4/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/ACNCNN.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[5/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CPUCNNProcessor.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[6/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/ACCreator.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[7/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCPPWrapper.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[8/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CPUACNet.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[9/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/AC.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[10/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CPUACNetProcessor.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[11/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CudaAnime4K09.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[12/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/NCNNACNet.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[13/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/OpenCLACNet.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[14/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/CudaACNet.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[15/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/FilterProcessor.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[16/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/VideoProcessor.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[17/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/OpenCLAnime4K09.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[18/19] Building CXX object CMakeFiles/Anime4KCPPCore.dir/Anime4KCore/src/VideoIO.cpp.o
clang++: warning: argument unused during compilation: '-static-openmp' [-Wunused-command-line-argument]
[19/19] Linking CXX shared library E:\Work_Space\Anime4KCPP_Android\app\build\intermediates\cxx\Debug\5av2r2w1\obj\arm64-v8a\libAnime4KCPPCore.so
FAILED: E:/Work_Space/Anime4KCPP_Android/app/build/intermediates/cxx/Debug/5av2r2w1/obj/arm64-v8a/libAnime4KCPPCore.so
cmd.exe /C "cd . && D:\AndroidSDK\ndk\21.3.6528147\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android24 --gcc-toolchain=D:/AndroidSDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/AndroidSDK/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -std=c++17 -frtti -fexceptions -O3 -static-openmp -fopenmp -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libAnime4KCPPCore.so -o E:\Work_Space\Anime4KCPP_Android\app\build\intermediates\cxx\Debug\5av2r2w1\obj\arm64-v8a\libAnime4KCPPCore.so @CMakeFiles\Anime4KCPPCore.rsp && cd ."
E:/Libs/Android/OpenCL/lib/arm64-v8a/libOpenCL.so: error adding symbols: File in wrong format
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
我的操作是这样的,没有修改配置文件,而是插上手机开启usb调试,然后直接点run,此时应该会编译并在手机上运行,这个时候点all stop,然后去换掉so库,再点run,会发现此时依然可以run成功。但是过一段时间再run又会提示so库不兼容。就很离谱。
如果还不成功的话,不妨直接替换编译出的apk的lib文件夹里打包的so库试一下。
然后可以尝试降低sdk版本到30,以前是没有这个奇怪的问题的,opencl相关代码也没有什么修改。我看谷歌在sdk31加入了对load native库的限制。
我按你的方法试了一下,也可以编译成功。先删除armv7然后点make,此时成功,然后替换so库再make依然成功。
我不知道该怎么形容了,替换之后成功开启了 GPU 啥也不说了,我给你磕一个吧
您好,我 使用 https://github.com/TianZerL/Anime4KCPP/issues/108#issuecomment-1801871654 中您提供的 opencl SDK,编译成功,但提示不支持 GPU 模式,我定位到代码是: ACOpenCL.cpp 中的
cl::Platform::get(&platforms);
这句会抛出异常。我又尝试了将手机中的 libOpenCL.so 文件导出替换,开启 GPU 模式时会提示如下错误:
通过搜索,应该是调用了系统私有 NDK 所致,于是将手机中的 so 文件导出,在 CMkeLists 中加入
以此方式加入了 libcutils.so libvndksupport.so libc++.so libbase.so libdl_android.so ld-android.so
但这个时候再开启 GPU,提示如下错误:
但是使用您再 release 中提供的 apk,是可以开启 GPU 模式的,所以您提供的 OpenCL SDK,对应的是最新的 Anime4KCPP_Android 吗?