Error while building TVM with USE_ANTLR

i am trying to build TVM with the USE_ANTLR, but i am facing issues while building, errors are as below,

CMake Warning (dev) at cmake/util/FindANTLR.cmake:64:
Syntax Warning in cmake code at column 27

Argument not separated from preceding token by whitespace.
Call Stack (most recent call first):
CMakeLists.txt:10 (include)
This warning is for project developers. Use -Wno-dev to suppress it.

– Build with RPC support…
– Build with Graph runtime support…
– Build VTA runtime with target: sim
– Link with dynamic LLVM library
– Found LLVM_INCLUDE_DIRS=/usr/lib/llvm-6.0/include
– Found LLVM_DEFINITIONS=-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
– Found TVM_LLVM_VERSION=60
– Build with LLVM 6.0.0
– Set TVM_LLVM_VERSION=60
– Using Java at /usr/lib/jvm/java-11-openjdk-amd64//bin/java
CMake Error at cmake/util/FindANTLR.cmake:57 (list):
list GET given empty list
Call Stack (most recent call first):
cmake/modules/ANTLR.cmake:18 (find_antlr)
CMakeLists.txt:246 (include)

– ANTLR4=/usr/lib/jvm/java-11-openjdk-amd64//bin/java-jar
– Build with micro.standalone_runtime
– Build with contrib.sort
– Build with contrib.hybriddump
– Build with c++11
– Build with thread support…
– Configuring incomplete, errors occurred!

I had similar problems on Linux. After I installed version 4 of antlr the compilation worked. You will still see the warning though.

What is your config.cmake setting ANTLR? It is looking for antlr-*-complete.jar. By default, it looks in /usr/local/lib. If you have this jar in a different location, you can set this to the path to the jar directly.

i have installed antlr also but still i have same issues

Can you make sure the jar file is in /usr/local/lib? What does your config.cmake look like?

have same problem
i set the antlr path in config.cmake, but still see this error.

set(USE_CUDA OFF)
set(USE_ROCM OFF)
set(USE_SDACCEL OFF)
set(USE_AOCL OFF)
set(USE_OPENCL OFF)
set(USE_METAL OFF)
set(USE_VULKAN OFF)
set(USE_OPENGL OFF)
set(USE_MICRO OFF)
set(USE_SGX OFF)
set(SGX_MODE “SIM”)
set(RUST_SGX_SDK “/path/to/rust-sgx-sdk”)
set(USE_RPC ON)
set(USE_STACKVM_RUNTIME OFF)
set(USE_GRAPH_RUNTIME ON)
set(USE_GRAPH_RUNTIME_DEBUG OFF)
set(USE_VM_PROFILER OFF)
set(USE_MICRO_STANDALONE_RUNTIME ON)
set(USE_LLVM ON)
set(USE_BLAS none)
set(USE_MKL_PATH none)
set(USE_OPENMP none)
set(USE_RANDOM OFF)
set(USE_NNPACK OFF)
set(USE_CUDNN OFF)
set(USE_CUBLAS OFF)
set(USE_MIOPEN OFF)
set(USE_MPS OFF)
set(USE_ROCBLAS OFF)
set(USE_SORT ON)
set(USE_ANTLR ON)
set(USE_RELAY_DEBUG OFF)
set(USE_VTA_FSIM ON)
set(USE_VTA_TSIM ON)
set(USE_VTA_FPGA OFF)

This is something i have used for build also it finds the antlr.jar while building

set USE_ANTLR to a specific path,
and the stdout of

## in file  cmake/util/FindANTLR.cmake
message(STATUS "ANTLR4="${ANTLR4})

had no spaces, same as the author

-- Set TVM_LLVM_VERSION=90
-- JAVA_HOME is not defined. Set it to ensure proper use
-- Using Java at /usr/bin/java
-- ANTLR4=/usr/bin/java-jar/home/kim/software/antlr/antlr-4.7.2-complete.jar
-- Build with micro.standalone_runtime
-- Build with contrib.sort
-- Build with contrib.hybriddump
-- Build with c++11
-- Build with thread support...
-- Configuring done

could above info help, could u have a look https://github.com/dmlc/tvm/pull/4176

1 Like

My make file is able to find the antlr-4.7.2-complete.jar while compiling so I am not sure why it asks again after building the TVM. it gives out same error as asking to TURN ON antlr and build again.

this is not right , no “space” in ANTLR4 's value right case is “/usr/bin/java -jar /path/antlr.jar”

this what i am getting while building

– ANTLR4=/usr/bin/java-jar/usr/local/lib/antlr-4.5-complete.jar
– Build with micro.standalone_runtime
– Build with contrib.sort

In my experience, the error to “turn on ANTLR and build again” can be fixed by installing the ANTLR4 Python package.

The set() line should be unchanged in this change, it is just moved to FindANTLR.cmake.

Can you please confirm if installing the Python package fixes the issue? You can get the instructions on the right package to install in the installation docs at docs.tvm.ai.

Hi, we confirm i have installed the needed python packages.
complete log

[16:20:41] /home/kim/source/tvm/src/relay/ir/module.cc:286: Importing: /home/kim/repo/tf1.14.0/lib/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/std/prelude.rly
Traceback (most recent call last):

  File "./tvm_complie.py", line 60, in <module>
    fire.Fire(main)

  File "/usr/local/lib/python3.6/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)

  File "/usr/local/lib/python3.6/site-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)

  File "/usr/local/lib/python3.6/site-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)

  File "./tvm_complie.py", line 53, in main
    mod, params = tvm.relay.frontend.from_tensorflow(sub_graph_FPN)

  File "/home/kim/repo/tf1.14.0/lib64/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/frontend/tensorflow.py", line 2484, in from_tensorflow
    g = GraphProto()

  File "/home/kim/repo/tf1.14.0/lib64/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/frontend/tensorflow.py", line 1965, in __init__
    self._prelude = Prelude(self._mod)

  File "/home/kim/repo/tf1.14.0/lib64/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/prelude.py", line 533, in __init__
    self.load_prelude()

  File "/home/kim/repo/tf1.14.0/lib64/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/prelude.py", line 549, in load_prelude
    self.mod.import_from_std("prelude.rly")

  File "/home/kim/repo/tf1.14.0/lib64/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/module.py", line 239, in import_from_std
    return _module.Module_ImportFromStd(self, file_to_import)

  File "tvm/_ffi/_cython/./function.pxi", line 304, in tvm._ffi._cy3.core.FunctionBase.__call__

  File "tvm/_ffi/_cython/./function.pxi", line 239, in tvm._ffi._cy3.core.FuncCall

  File "tvm/_ffi/_cython/./function.pxi", line 228, in tvm._ffi._cy3.core.FuncCall3

  File "tvm/_ffi/_cython/./base.pxi", line 160, in tvm._ffi._cy3.core.CALL

tvm._ffi.base.TVMError: Traceback (most recent call last):
  [bt] (5) /home/kim/repo/tf1.14.0/lib/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(TVMFuncCall+0x4c) [0x7f23c7a1670c]
  [bt] (4) /home/kim/repo/tf1.14.0/lib/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x13b5e52) [0x7f23c792de52]
  [bt] (3) /home/kim/repo/tf1.14.0/lib/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::ModuleNode::ImportFromStd(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x14d) [0x7f23c792dc6d]
  [bt] (2) /home/kim/repo/tf1.14.0/lib/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::ModuleNode::Import(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x12a) [0x7f23c792da6a]
  [bt] (1) /home/kim/repo/tf1.14.0/lib/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(tvm::relay::FromText(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0xb7) [0x7f23c79290d7]
  [bt] (0) /home/kim/repo/tf1.14.0/lib/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/libtvm.so(+0x1499927) [0x7f23c7a11927]
  File "/home/kim/repo/tf1.14.0/lib64/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/_parser.py", line 38, in <module>
    from .grammar.py3.RelayVisitor import RelayVisitor
  File "tvm/_ffi/_cython/./function.pxi", line 55, in tvm._ffi._cy3.core.tvm_callback
  File "/home/kim/repo/tf1.14.0/lib64/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/parser.py", line 25, in fromtext
    from tvm.relay import _parser
  File "/home/kim/repo/tf1.14.0/lib64/python3.6/site-packages/tvm-0.6.dev0-py3.6-linux-x86_64.egg/tvm/relay/_parser.py", line 42, in <module>
    raise Exception("Couldn't find ANTLR parser. Try building with USE_ANTLR=ON.")
ModuleNotFoundError: No module named 'tvm.relay.grammar.py3'
During handling of the above exception, another exception occurred:

Exception: Couldn't find ANTLR parser. Try building with USE_ANTLR=ON.

https://github.com/dmlc/tvm/issues/4215 find this issue maybe help

Which ANTLR package did you install? Can you please confirm with a pip list and post it here?

I’ve never tried using the TVM package, I’ve only set PYTHONPATH. However, it looks like there is no __init__.py under grammar/py3 and the __init__.py doesn’t import it. If you find a fix feel free to send a PR.

If it helps I installed antlr4 package through apt (apt install antlr4) I did also install: pip3 install mypy orderedset antlr4-python3-runtime as indicated by the documentation. After that it compiled with no errors, I tried the latest TVM version (as of yesterday).

Have tried the above both on a Mac and Linux box.

1 Like

Hi @jonso

Can we use antlr-4.7.2-complete.jar directly instead of installing antlr4 by apt?

Using antlr-4.7.2-complete.jar directly in cmake and I don’t get any error when building tvm, however, I get errors when parsing relay

>>> func = relay.parser.fromtext(expr_text)
Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/root/tvm/python/tvm/_ffi/_ctypes/function.py", line 207, in __call__
    raise get_last_ffi_error()

tvm._ffi.base.TVMError: Traceback (most recent call last):
  [bt] (1) /root/tvm/build/libtvm.so(TVMFuncCall+0x65) [0x7ffba6e99875]
  [bt] (0) /root/tvm/build/libtvm.so(+0x13c086b) [0x7ffba6e9486b]
  File "/root/tvm/python/tvm/relay/_parser.py", line 38, in <module>
    from .grammar.py3.RelayVisitor import RelayVisitor
  File "/root/tvm/python/tvm/relay/grammar/py3/RelayVisitor.py", line 2, in <module>
    from antlr4 import *
  File "/root/tvm/python/tvm/_ffi/_ctypes/function.py", line 72, in cfun
    rv = local_pyfunc(*pyargs)
  File "/root/tvm/python/tvm/relay/parser.py", line 25, in fromtext
    from tvm.relay import _parser
  File "/root/tvm/python/tvm/relay/_parser.py", line 42, in <module>
    raise Exception("Couldn't find ANTLR parser. Try building with USE_ANTLR=ON.")
ModuleNotFoundError: No module named 'antlr4'
During handling of the above exception, another exception occurred:

Exception: Couldn't find ANTLR parser. Try building with USE_ANTLR=ON.

Did you also install the antlr4 Python package?