Hello,
I encounter the same problem. After some digging I have found problematic construction in cmake. I think main entry is cmake/modules/Vulkan.cmake
. At the begining of that file, we can see that find_vulkan is first command. FindVulkan.cmake
has suspicius statement in CMAKE_SYSTEM_NAME STREQUAL "Android"
condition, i.e. return
statement, which breaks FindVulka.cmake
macro.
The question is, how to set USE_VULKAN
variable. ON
causes problems. I would like to set path to SDK, but how can I specify that with Android NDK? Do Android NDK contains Vulkan SDK?
@srkreddy1238 sorry, for necromancing this thread, but do you remember, or have notes about how you compiled tvm_runtime with vulkan? How do you specified Vulkan SDK?
–edit–
I have temporary fixed problem. I’m not sure about further consequences… But if you want:
- In FindVulkan.cmake remove
return
statement in mentioned condition
- Remove/Comment-out last top-level condition
if(Vulkan_FOUND)
.
- To
cmake
command add something like -DVulkan_LIBRARY=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/24/libvulkan.so
- Cmake output:
-- Android Vulkan_INCLUDE_DIRS=/home/piotr/android/sdk/ndk/26.1.10909125/sources/third_party/vulkan/src/include
-- Skip finding SPIRV in Android, make sure you only build tvm runtime.
- Make output:
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/static_library.cc.o
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/system_library.cc.o
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/thread_pool.cc.o
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/threading_backend.cc.o
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vm/bytecode.cc.o
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vm/executable.cc.o
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vm/vm.cc.o
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/workspace_pool.cc.o
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/disco/distributed/socket_session.cc.o
....
[ 71%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vulkan/vulkan_amdrgp.cc.o
[ 85%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vulkan/vulkan_buffer.cc.o
[ 85%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vulkan/vulkan_common.cc.o
[ 85%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vulkan/vulkan_device.cc.o
[ 85%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vulkan/vulkan_device_api.cc.o
[ 85%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vulkan/vulkan_instance.cc.o
[ 85%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vulkan/vulkan_module.cc.o
[ 85%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vulkan/vulkan_stream.cc.o
[ 85%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/vulkan/vulkan_wrapped_func.cc.o
[ 85%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/contrib/random/random.cc.o
[100%] Building CXX object tvm/CMakeFiles/tvm_runtime_objs.dir/src/runtime/contrib/sort/sort.cc.o
[100%] Built target tvm_runtime_objs
[100%] Linking CXX shared library libtvm_runtime.so
[100%] Built target tvm_runtime
➜ build
–edit2–
I had this error:
libc++abi: terminating due to uncaught exception of type tvm::runtime::InternalError: [12:44:05]
/tvm/src/runtime/library_module.cc:122:
Binary was created using {vulkan} but a loader of that name is not registered.
Available loaders are static_library, relax.Executable, metadata_module, VMExecutable, metadata, const_loader.
Perhaps you need to recompile with this runtime enabled.
Stack trace not available when DMLC_LOG_STACK_TRACE is disabled at compile time.
Now I have:
Build fingerprint: 'HUAWEI/ADY-L29/HWADY:12/HUAWEIADY-L29/104.2.0.161C432:user/release-keys'
#00 0x0000000000098cb0 /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: 82f181b5d9da8999785cca84af3dad4b)
#01 0x00000000012ad014 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#02 0x00000000011c87bc /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#03 0x00000000011be0b4 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#04 0x00000000011b4c64 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#05 0x0000000001319a54 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#06 0x00000000013159ac /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#07 0x000000000177de70 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#08 0x00000000012efbd8 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#09 0x00000000012ef5dc /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#10 0x00000000013c4ce0 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#11 0x0000000001726d80 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#12 0x00000000017255e4 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#13 0x000000000176c0f0 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#14 0x000000000176b664 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#15 0x000000000176b4f0 /vendor/lib64/libbishenggpucompiler_v200.so (BuildId: a9d776435b8c2dae5d84700b7af45276)
#16 0x000000000187df74 /vendor/lib64/libbishenggpucompiler_v200.so (cmpbe_v2_compile_multiple_shaders+7552) (BuildId: a9d776435b8c2dae5d84700b7af45276)
#17 0x00000000001277ec /vendor/lib64/hw/vulkan.hvgr_v200.so (BuildId: 2dd0d5421137d613f3cad2d5a5fc4e37)
#18 0x0000000000122ce4 /vendor/lib64/hw/vulkan.hvgr_v200.so (BuildId: 2dd0d5421137d613f3cad2d5a5fc4e37)
#19 0x0000000000122700 /vendor/lib64/hw/vulkan.hvgr_v200.so (BuildId: 2dd0d5421137d613f3cad2d5a5fc4e37)
#20 0x000000000036a840 /vendor/lib64/hw/vulkan.hvgr_v200.so (BuildId: 2dd0d5421137d613f3cad2d5a5fc4e37)
#21 0x00000000003547ec /vendor/lib64/hw/vulkan.hvgr_v200.so (BuildId: 2dd0d5421137d613f3cad2d5a5fc4e37)
#22 0x00000000002c79d0 /vendor/lib64/hw/vulkan.hvgr_v200.so (BuildId: 2dd0d5421137d613f3cad2d5a5fc4e37)
#23 0x00000000002ecfd0 /data/local/tmp/mlc/libtvm_runtime.so
#24 0x00000000002ec020 /data/local/tmp/mlc/libtvm_runtime.so
#25 0x00000000002f2578 /data/local/tmp/mlc/libtvm_runtime.so
#26 0x00000000002f2484 /data/local/tmp/mlc/libtvm_runtime.so
#27 0x00000000001645a0 /data/local/tmp/mlc/libtvm_runtime.so
#28 0x00000000003faf48 /data/local/tmp/mlc/gpt2-medium-q0f16-vulkan-aarch64.so
#29 0x00000000003ee650 /data/local/tmp/mlc/gpt2-medium-q0f16-vulkan-aarch64.so
#30 0x00000000001cc068 /data/local/tmp/mlc/libtvm_runtime.so
#31 0x000000000028b4a8 /data/local/tmp/mlc/libtvm_runtime.so
#32 0x000000000028e634 /data/local/tmp/mlc/libtvm_runtime.so
#33 0x000000000028d8bc /data/local/tmp/mlc/libtvm_runtime.so
#34 0x000000000028d0e8 /data/local/tmp/mlc/libtvm_runtime.so
#35 0x0000000000295d20 /data/local/tmp/mlc/libtvm_runtime.so
#36 0x000000000028b684 /data/local/tmp/mlc/libtvm_runtime.so
#37 0x00000000002969f4 /data/local/tmp/mlc/libtvm_runtime.so
#38 0x000000000037a538 /data/local/tmp/mlc/llm_benchmark
tvm::runtime::PackedFuncObj::CallPacked(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const
/home/piotr/projects/odai-meta/mlc-llm-519/3rdparty/tvm/include/tvm/runtime/packed_func.h:1256:3
tvm::runtime::TVMRetValue tvm::runtime::PackedFunc::operator()<tvm::runtime::NDArray&, tvm::runtime::NDArray&, tvm::runtime::NDArray&>(tvm::runtime::NDArray&, tvm::runtime::NDArray&, tvm::runtime::NDArray&) const
/home/piotr/projects/odai-meta/mlc-llm-519/3rdparty/tvm/include/tvm/runtime/packed_func.h:1784:9
mlc::llm::serve::GPUSampler::SampleOnGPU(tvm::runtime::NDArray, tvm::runtime::NDArray, tvm::runtime::NDArray, bool, bool, int, std::__ndk1::vector<int, std::__ndk1::allocator<int>> const&)
/home/piotr/projects/odai-meta/mlc-llm-519/cpp/serve/sampler/gpu_sampler.cc:582:36
#39 0x0000000000378cd0 /data/local/tmp/mlc/llm_benchmark
mlc::llm::serve::GPUSampler::ChunkSampleTokensImpl(tvm::runtime::NDArray, std::__ndk1::vector<int, std::__ndk1::allocator<int>> const&, tvm::runtime::Array<mlc::llm::serve::GenerationConfig, void> const&, std::__ndk1::vector<mlc::llm::RandomGenerator*, std::__ndk1::allocator<mlc::llm::RandomGenerator*>> const&, bool)
/home/piotr/projects/odai-meta/mlc-llm-519/cpp/serve/sampler/gpu_sampler.cc:464:9
#40 0x00000000003785e4 /data/local/tmp/mlc/llm_benchmark
mlc::llm::serve::GPUSampler::BatchSampleTokensImpl(tvm::runtime::NDArray, std::__ndk1::vector<int, std::__ndk1::allocator<int>> const&, tvm::runtime::Array<tvm::runtime::String, void> const&, tvm::runtime::Array<mlc::llm::serve::GenerationConfig, void> const&, std::__ndk1::vector<mlc::llm::RandomGenerator*, std::__ndk1::allocator<mlc::llm::RandomGenerator*>> const&, bool)
/home/piotr/projects/odai-meta/mlc-llm-519/cpp/serve/sampler/gpu_sampler.cc:384:24
#41 0x0000000000375aec /data/local/tmp/mlc/llm_benchmark
mlc::llm::serve::GPUSampler::BatchSampleTokensWithProbAfterTopP(tvm::runtime::NDArray, std::__ndk1::vector<int, std::__ndk1::allocator<int>> const&, tvm::runtime::Array<tvm::runtime::String, void> const&, tvm::runtime::Array<mlc::llm::serve::GenerationConfig, void> const&, std::__ndk1::vector<mlc::llm::RandomGenerator*, std::__ndk1::allocator<mlc::llm::RandomGenerator*>> const&)
/home/piotr/projects/odai-meta/mlc-llm-519/cpp/serve/sampler/gpu_sampler.cc:197:12
#42 0x00000000003148cc /data/local/tmp/mlc/llm_benchmark
mlc::llm::serve::NewRequestPrefillActionObj::Step(mlc::llm::serve::EngineState)
/home/piotr/projects/odai-meta/mlc-llm-519/cpp/serve/engine_actions/new_request_prefill.cc:245:58
#43 0x00000000002d3270 /data/local/tmp/mlc/llm_benchmark
mlc::llm::serve::EngineImpl::Step()
/home/piotr/projects/odai-meta/mlc-llm-519/cpp/serve/engine.cc:650:38
#44 0x000000000037f954 /data/local/tmp/mlc/llm_benchmark
mlc::llm::serve::ThreadedEngineImpl::RunBackgroundLoop()
/home/piotr/projects/odai-meta/mlc-llm-519/cpp/serve/threaded_engine.cc:182:29
#45 0x0000000000213b70 /data/local/tmp/mlc/llm_benchmark
benchmark_llm(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)::$_1::operator()() const
/home/piotr/projects/odai-meta/mlc-llm-519/cpp/llm_benchmark.cpp:64:17
decltype(std::declval<benchmark_llm(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)::$_1>()()) std::__ndk1::__invoke[abi:v170000]<benchmark_llm(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)::$_1>(benchmark_llm(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)::$_1&&)
/home/piotr/android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__functional/invoke.h:394:23
void std::__ndk1::__thread_execute[abi:v170000]<std::__ndk1::unique_ptr<std::__ndk1::__thread_struct, std::__ndk1::default_delete<std::__ndk1::__thread_struct>>, benchmark_llm(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)::$_1>(std::__ndk1::tuple<std::__ndk1::unique_ptr<std::__ndk1::__thread_struct, std::__ndk1::default_delete<std::__ndk1::__thread_struct>>, benchmark_llm(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)::$_1>&, std::__ndk1::__tuple_indices<>)
/home/piotr/android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/thread:282:5
void* std::__ndk1::__thread_proxy[abi:v170000]<std::__ndk1::tuple<std::__ndk1::unique_ptr<std::__ndk1::__thread_struct, std::__ndk1::default_delete<std::__ndk1::__thread_struct>>, benchmark_llm(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>> const&)::$_1>>(void*)
/home/piotr/android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/thread:293:5
#46 0x00000000000fc370 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+176) (BuildId: 82f181b5d9da8999785cca84af3dad4b)
#47 0x000000000009a4fc /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+40) (BuildId: 82f181b5d9da8999785cca84af3dad4b)
Crash dump is completed
Similar setup on vulkan, on x86 is working.
–edit3–
I think the problem is with spirv. It has sources, and headers, and not-cmake in NDK. I think it can be build with similarly to desribet here Vulkan shader compilers on Android | Android NDK | Android Developers. I have compiled SPIRV-Tools, but the error is the same. Btw. this are lines in cmake to include SPIRV:
SET(VULKAN_LIBRARY_PATH "${ANDROID_NDK}/sources/third_party/shaderc/third_party/spirv-tools")
SET(Vulkan_INCLUDE_DIRS "${ANDROID_NDK}/sources/third_party/shaderc/third_party/spirv-tools/include")
find_library(Vulkan_SPIRV_TOOLS_LIBRARY SPIRV-Tools
HINTS ${__use_khronos_spirv}/lib ${VULKAN_LIBRARY_PATH} ${VULKAN_LIBRARY_PATH}/spirv-tools ${VULKAN_SDK}/lib ${VULKAN_LIBRARY_PATH}/obj/local/arm64-v8a/)
find_path(_libspirv libspirv.h HINTS ${__use_khronos_spirv}/include ${Vulkan_INCLUDE_DIRS}/ PATH_SUFFIXES vulkan spirv-tools)
find_path(_spirv spirv.hpp HINTS ${__use_khronos_spirv}/include ${VULKAN_LIBRARY_PATH}/external/spirv-headers/include/ PATH_SUFFIXES vulkan SPIRV spirv/unified1 spirv-headers)
find_path(_glsl_std GLSL.std.450.h HINTS ${VULKAN_LIBRARY_PATH}/external/spirv-headers/include/ PATH_SUFFIXES vulkan SPIRV spirv/unified1 spirv-headers)