Missing llvm/ADT/SmallString.h when using NDK

Hello,

I’m using TVM to tune models for Android devices. I’m using LLVM from NDK. When I run this command to build tvm_rpc:

RUN cd /usr/tvm && \
    rm -rf build && \
    mkdir -p build && \
    cd build && \
    cmake \
        -DUSE_LLVM=/opt/android-sdk-linux/ndk/26.0.10792818/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-config \
        -DUSE_RPC=ON \
        -DUSE_CPP_RPC=ON \
        -DUSE_PROFILER=ON \
        -DUSE_GRAPH_EXECUTOR=ON \
        .. && \
    make -j10

I’m getting following problem:

520.5 [ 95%] Building CXX object CMakeFiles/tvm_objs.dir/src/target/llvm/codegen_amdgpu.cc.o
520.5 /usr/tvm/src/target/llvm/codegen_amdgpu.cc:26:10: fatal error: llvm/ADT/SmallString.h: No such file or directory
520.5    26 | #include <llvm/ADT/SmallString.h>
520.5       |          ^~~~~~~~~~~~~~~~~~~~~~~~
520.5 compilation terminated.
520.5 make[2]: *** [CMakeFiles/tvm_objs.dir/build.make:8616: CMakeFiles/tvm_objs.dir/src/target/llvm/codegen_amdgpu.cc.o] Error 1
520.5 make[2]: *** Waiting for unfinished jobs....
522.4 make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/tvm_objs.dir/all] Error 2
522.4 make: *** [Makefile:136: all] Error 2

After little searching, and debugging. I have found that very old NDK (16.1.4479499) only has this header. So when using NDK, only version 16 is able to build TVM runtime. As I see in LLVM repository this header is present in recent branches. So I think it is intentionaly removed from NDK.

Question:

  1. Do I build incorrectly?
  2. Can I build tvm for android with system LLVM?

likely you only need to build tvm runtime, so you can type make runtime instead of make.

1 Like

On host I must have runtime. So runtime for host machine I build with following command:

    cmake \
        -DUSE_LLVM=/opt/android-sdk-linux/ndk/26.0.10792818/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-config \
        -DUSE_RPC=ON \
        -DUSE_SORT=ON \
        -DUSE_GRAPH_EXECUTOR=ON \
        .. && \
    make -j10 tvm tvm_runtime

On target device(android) I need runtime, as well. So runtime for target device I crosscompile on host machine:

           cmake ..
             -DCMAKE_BUILD_TYPE=Release
             -DCMAKE_TOOLCHAIN_FILE=/opt/android-sdk-linux/ndk/26.0.10792818/build/cmake/android.toolchain.cmake
             -DCMAKE_CXX_FLAGS_RELEASE=-O3
             -DANDROID_ABI=armeabi-v7a
             -DANDROID_PLATFORM=android-28
             -DUSE_LLVM=/opt/android-sdk-linux/ndk/26.0.10792818/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-config
             -DUSE_RPC=ON
             -DUSE_CPP_RPC=ON
             -DUSE_PROFILER=ON
             -DUSE_GRAPH_EXECUTOR=ON &&
            TVM_BUILD_PATH=/usr/tvm/build make -j4 tvm_runtime tvm_rpc &&

Do I have to use the same LLVM to build runtime for host machine and target machine? LLVM from NDK is little bit different than pure LLVM.