Building Rust example

Hey, more troubleshooting on my end. I want to build resnet, the rust example. I just built TVM with LLVM, and now running cargo build gives me the following error:

cgyurgyik@MacBook-Pro resnet % cargo build
   Compiling resnet v0.0.0 (/Users/cgyurgyik/Projects/rust-tvm/rust/tvm/examples/resnet)
   Compiling scroll v0.10.2
   Compiling thiserror v1.0.21
   Compiling inventory v0.1.9
   Compiling tvm-sys v0.1.0 (/Users/cgyurgyik/Projects/rust-tvm/rust/tvm-sys)
   Compiling tiff v0.2.2
   Compiling rayon v1.4.1
   Compiling pyo3 v0.11.1
   Compiling goblin v0.2.3
error: failed to run custom build command for `resnet v0.0.0 (/Users/cgyurgyik/Projects/rust-tvm/rust/tvm/examples/resnet)`

Caused by:
  process didn't exit successfully: `/Users/cgyurgyik/Projects/rust-tvm/rust/target/debug/build/resnet-06179279a60f6303/build-script-build` (exit code: 101)
  --- stdout
  2020-10-13 13:55:13,649 - __main__ - INFO - Compiling the model to graph runtime.
  Traceback (most recent call last):
    File "/Users/cgyurgyik/Projects/rust-tvm/rust/tvm/examples/resnet/src/build_resnet.py", line 154, in <module>
      build(build_dir)
    File "/Users/cgyurgyik/Projects/rust-tvm/rust/tvm/examples/resnet/src/build_resnet.py", line 80, in build
      graph, lib, params = relay.build(func, target, params=params)
    File "/Users/cgyurgyik/.local/lib/python3.8/site-packages/tvm/relay/build_module.py", line 255, in build
      graph_json, mod, params = bld_mod.build(mod, target, target_host, params)
    File "/Users/cgyurgyik/.local/lib/python3.8/site-packages/tvm/relay/build_module.py", line 121, in build
      self._build(mod, target, target_host)
    File "tvm/_ffi/_cython/./packed_func.pxi", line 321, in tvm._ffi._cy3.core.PackedFuncBase.__call__
    File "tvm/_ffi/_cython/./packed_func.pxi", line 256, in tvm._ffi._cy3.core.FuncCall
    File "tvm/_ffi/_cython/./packed_func.pxi", line 245, in tvm._ffi._cy3.core.FuncCall3
    File "tvm/_ffi/_cython/./base.pxi", line 160, in tvm._ffi._cy3.core.CALL
  AttributeError: Traceback (most recent call last):
    [bt] (8) 9   libtvm.dylib                        0x0000000110b3f643 tvm::relay::ExprMutator::VisitExpr_(tvm::relay::FunctionNode const*) + 883
    [bt] (7) 8   libtvm.dylib                        0x0000000110b3e119 tvm::relay::MixedModeMutator::VisitExpr(tvm::RelayExpr const&) + 649
    [bt] (6) 7   libtvm.dylib                        0x0000000110b3db5f tvm::relay::MixedModeMutator::VisitLeaf(tvm::RelayExpr const&) + 239
    [bt] (5) 6   libtvm.dylib                        0x0000000110b44817 tvm::relay::PostOrderRewriter::DispatchVisitExpr(tvm::RelayExpr const&) + 55
    [bt] (4) 5   libtvm.dylib                        0x00000001109385d5 tvm::relay::ExprRewriter::Rewrite(tvm::RelayExpr const&, tvm::RelayExpr const&) + 149
    [bt] (3) 4   libtvm.dylib                        0x0000000110938e6a tvm::NodeFunctor<tvm::RelayExpr (tvm::runtime::ObjectRef const&, tvm::relay::ExprRewriter*, tvm::RelayExpr const&)>::operator()(tvm::runtime::ObjectRef const&, tvm::relay::ExprRewriter*, tvm::RelayExpr const&) const + 266
    [bt] (2) 3   libtvm.dylib                        0x000000011093a499 tvm::relay::ExprRewriter::InitVTable()::'lambda4'(tvm::runtime::ObjectRef const&, tvm::relay::ExprRewriter*, tvm::RelayExpr const&)::__invoke(tvm::runtime::ObjectRef const&, tvm::relay::ExprRewriter*, tvm::RelayExpr const&) + 25
    [bt] (1) 2   libtvm.dylib                        0x0000000110a2008f tvm::relay::legalize::Legalizer::Rewrite_(tvm::relay::CallNode const*, tvm::RelayExpr const&) + 1247
    [bt] (0) 1   libtvm.dylib                        0x0000000110bcb2a5 std::__1::__function::__func<TVMFuncCreateFromCFunc::$_2, std::__1::allocator<TVMFuncCreateFromCFunc::$_2>, void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)>::operator()(tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&) + 213
    File "/Users/cgyurgyik/.local/lib/python3.8/site-packages/tvm/target/codegen.py", line 73, in llvm_version_major
      return _ffi_api.llvm_version_major()
    File "tvm/_ffi/_cython/./packed_func.pxi", line 55, in tvm._ffi._cy3.core.tvm_callback
    File "/Users/cgyurgyik/.local/lib/python3.8/site-packages/tvm/relay/op/nn/_nn.py", line 118, in legalize_conv2d
      return topi.nn.conv2d_legalize(attrs, inputs, types)
    File "<decorator-gen-52>", line 2, in conv2d_legalize
    File "/Users/cgyurgyik/.local/lib/python3.8/site-packages/tvm/target/generic_func.py", line 267, in dispatch_func
      return dispatch_dict[k](*args, **kwargs)
    File "/Users/cgyurgyik/.local/lib/python3.8/site-packages/topi/x86/conv2d_alter_op.py", line 266, in _conv2d_legalize
      if is_int8_hw_support(data_dtype, kernel_dtype):
    File "/Users/cgyurgyik/.local/lib/python3.8/site-packages/topi/x86/conv2d_int8.py", line 66, in is_int8_hw_support
      llvm_version = tvm.target.codegen.llvm_version_major()
    File "/Users/cgyurgyik/.local/lib/python3.8/site-packages/tvm/target/codegen.py", line 77, in llvm_version_major
      raise RuntimeError(
  AttributeError: module 'tvm.target._ffi_api' has no attribute 'llvm_version_major'
  During handling of the above exception, another exception occurred:

  RuntimeError: LLVM version is not available, please check if you build with LLVM

  --- stderr
  thread 'main' panicked at 'Failed to execute build script', tvm/examples/resnet/build.rs:33:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
println!("cargo:rustc-link-search=native={}", build_path)

Maybe I’m missing this? I’m not sure what this is asking for me to do. What is the build_path?

Seems you don’t have LLVM installed in the path. Make sure

  1. You have LLVM installed for building TVM
  2. Build TVM shared object
  3. Follow the instructions