Search code examples
pythondockertvmapache-tvm

No libtvm.so and libtvm_runtime.so found in TVM Docker Container


I am new to Apache TVM.

I tried to build and launch a docker image named tvm.ci_cpu:latest as described in the tutorial https://tvm.apache.org/docs/install/docker.html#docker-source.

I tried to use the python application tvmc inside docker container as described in the tutorial https://tvm.apache.org/docs/tutorial/tvmc_command_line_driver.html#using-tvmc.

Then I got the following error:

$ tvmc --help

bash: tvmc: command not found

I tried to use the other method mentioned in the article above, but I got the following new error:

$ python3 -m tvm.driver.tvmc --help

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/opt/share0/bob/project/tvm/python/tvm/__init__.py", line 26, in <module>
    from ._ffi.base import TVMError, __version__, _RUNTIME_ONLY
  File "/opt/share0/bob/project/tvm/python/tvm/_ffi/__init__.py", line 28, in <module>
    from .base import register_error
  File "/opt/share0/bob/project/tvm/python/tvm/_ffi/base.py", line 71, in <module>
    _LIB, _LIB_NAME = _load_lib()
  File "/opt/share0/bob/project/tvm/python/tvm/_ffi/base.py", line 51, in _load_lib
    lib_path = libinfo.find_lib_path()
  File "/opt/share0/bob/project/tvm/python/tvm/_ffi/libinfo.py", line 146, in find_lib_path
    raise RuntimeError(message)
RuntimeError: Cannot find libraries: ['libtvm.so', 'libtvm_runtime.so']
List of candidates:
/opt/sgxsdk/lib64/libtvm.so
/opt/share0/bob/project/tvm/libtvm.so
/usr/local/sbin/libtvm.so
/usr/local/bin/libtvm.so
/usr/sbin/libtvm.so
/usr/bin/libtvm.so
/sbin/libtvm.so
/bin/libtvm.so
/opt/rust/bin/libtvm.so
/usr/lib/go-1.10/bin/libtvm.so
/opt/share0/bob/project/tvm/python/tvm/libtvm.so
/opt/share0/bob/project/libtvm.so
/opt/sgxsdk/lib64/libtvm_runtime.so
/opt/share0/bob/project/tvm/libtvm_runtime.so
/usr/local/sbin/libtvm_runtime.so
/usr/local/bin/libtvm_runtime.so
/usr/sbin/libtvm_runtime.so
/usr/bin/libtvm_runtime.so
/sbin/libtvm_runtime.so
/bin/libtvm_runtime.so
/opt/rust/bin/libtvm_runtime.so
/usr/lib/go-1.10/bin/libtvm_runtime.so
/opt/share0/bob/project/tvm/python/tvm/libtvm_runtime.so
/opt/share0/bob/project/libtvm_runtime.so

I tried to pull and use the following third-party docker images instead of the ones I built myself:

However, I still met same problems as before.

WHY? I had no idea at all.

Any suggestion? Thanks.


Solution

  • I found pingsutw's answer in https://discuss.tvm.apache.org/t/import-tvm-returns-runtime-error-cant-find-libtvm-so-when-using-docker-demo-cpu-image/5110. After referring to his advice, I tried rebuilding tvm in a container launched from the image tvm.ci_cpu:latest which built by myself.

    pushd path/to/tvm && \
        chmod +x 3rdparty/libbacktrace/configure && \
        mkdir -p cmake-build && \
        cmake -H. -Bcmake-build -DUSE_LLVM=ON && \
        cmake --build cmake-build --target all -- -j 4 && \
        mv cmake-build build && \
        popd
    

    After the above, I tried typing the command python3 -m tvm.driver.tvmc --help and got the following output.

    usage: tvmc [-v] [--version] [-h] {run,tune,compile} ...
    
    TVM compiler driver
    
    optional arguments:
      -v, --verbose       increase verbosity
      --version           print the version and exit
      -h, --help          show this help message and exit.
    
    commands:
      {run,tune,compile}
        run               run a compiled module
        tune              auto-tune a model
        compile           compile a model.
    
    TVMC - TVM driver command-line interface
    

    As you can see it works now.

    Surprisingly, libtvm.so and libtvm_runtime.so are not pre-built in the tvm docker image. Maybe the third-party tvm docker image is broken. Maybe the Dockerfile for building tvm docker image should be updated. Maybe it is designed to be flexibly compiled to meet various needs.