conda-forge / libtvm-feedstock

A conda-smithy repository for libtvm.
BSD 3-Clause "New" or "Revised" License
0 stars 7 forks source link

`target.build.llvm` is not enabled #7

Closed Krovatkin closed 2 years ago

Krovatkin commented 4 years ago

Issue:

First of all, thank you very much for this work! I love the idea of being able to just install python bindings for tvm with conda and experiment with schedules. Unfortunately, I can't seem to run it.

Hi, I was wondering if there are tvm packages that also bundle llvm?

 python example.py
<class 'tvm.te.tensor.Tensor'>
Traceback (most recent call last):
  File "example.py", line 35, in <module>
    fadd = tvm.build(s, [A, B, C], tgt, target_host=tgt_host, name="myadd")
  File "/usr/local/anaconda3/envs/tvm/lib/python3.8/site-packages/tvm/driver/build_module.py", line 418, in build
    rt_mod_host = codegen.build_module(mod_host_all, target_host)
  File "/usr/local/anaconda3/envs/tvm/lib/python3.8/site-packages/tvm/target/codegen.py", line 39, in build_module
    return _ffi_api.Build(mod, target)
  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
tvm._ffi.base.TVMError: Traceback (most recent call last):
  [bt] (3) 4   libtvm.dylib                        0x0000000117ecb444 TVMFuncCall + 84
  [bt] (2) 3   libtvm.dylib                        0x000000011788388e void tvm::runtime::TypedPackedFunc<tvm::runtime::Module (tvm::IRModule, tvm::Target)>::AssignTypedLambda<tvm::runtime::Module (*)(tvm::IRModule, tvm::Target)>(tvm::runtime::Module (*)(tvm::IRModule, tvm::Target))::'lambda'(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)::operator()(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*) const + 622
  [bt] (1) 2   libtvm.dylib                        0x000000011787fd5e tvm::codegen::Build(tvm::IRModule, tvm::Target) + 1038
  [bt] (0) 1   libtvm.dylib                        0x000000011717987f dmlc::LogMessageFatal::~LogMessageFatal() + 111
  File "../src/target/codegen.cc", line 58
TVMError: Check failed: bf != nullptr: target.build.llvm is not enabled


Environment (conda list):

``` $ conda list # packages in environment at /usr/local/anaconda3/envs/tvm: # # Name Version Build Channel attrs 20.2.0 pyh9f0ad1d_0 conda-forge backtrace 20201001 hb0a8c7a_0 conda-forge c-ares 1.16.1 haf1e3a3_3 conda-forge ca-certificates 2020.10.14 0 certifi 2020.6.20 py38_0 chardet 3.0.4 curl 7.71.1 hcb81553_8 conda-forge decorator 4.4.2 py_0 conda-forge dlpack 0.3 h4a8c4bd_1 conda-forge dmlc 0.4 h2427b36_1 conda-forge idna 2.10 iniconfig 1.1.1 py_0 krb5 1.17.1 h75d18d8_3 conda-forge libblas 3.9.0 0_openblas conda-forge libcblas 3.9.0 0_openblas conda-forge libcurl 7.71.1 h9bf37e3_8 conda-forge libcxx 11.0.0 h439d374_0 conda-forge libedit 3.1.20191231 h1de35cc_1 libev 4.33 haf1e3a3_1 conda-forge libffi 3.3 hb1e8313_2 libgfortran 5.0.0 h7cc5361_13 conda-forge libgfortran5 9.3.0 h7cc5361_13 conda-forge liblapack 3.9.0 0_openblas conda-forge libnghttp2 1.41.0 h7580e61_2 conda-forge libopenblas 0.3.12 openmp_h54245bb_1 conda-forge libssh2 1.9.0 h8a08a2b_5 conda-forge libtvm 0.7.0 hb1e8313_0 conda-forge llvm-openmp 11.0.0 h73239a0_1 conda-forge more-itertools 8.5.0 py_0 ncurses 6.2 h0a44026_1 numpy 1.19.2 py38ha98150c_1 conda-forge openssl 1.1.1h haf1e3a3_0 packaging 20.4 py_0 pip 20.2.4 py38_0 pluggy 0.13.1 py38_0 psutil 5.7.2 py38h94c058a_1 conda-forge py 1.9.0 py_0 pyparsing 2.4.7 py_0 pytest 6.1.1 py38_0 python 3.8.5 h26836e1_1 python-slugify 4.0.1 python_abi 3.8 1_cp38 conda-forge rang 3.1.0 0 conda-forge readline 8.0 h1de35cc_0 requests 2.24.0 scipy 1.5.2 py38h9bd2513_2 conda-forge setuptools 50.3.0 py38h0dc7051_1 six 1.15.0 py_0 sqlite 3.33.0 hffcf06c_0 text-unidecode 1.3 tk 8.6.10 hb0a8c7a_0 toml 0.10.1 py_0 tvm-py 0.7.0 py38h6be0db6_0 conda-forge typed-ast 1.4.1 py38h0b31af3_0 conda-forge urllib3 1.25.11 wheel 0.35.1 py_0 xz 5.2.5 h1de35cc_0 zlib 1.2.11 h1de35cc_3 ```


Details about conda and system ( conda info ):

``` $ conda info conda info active environment : tvm active env location : /usr/local/anaconda3/envs/tvm shell level : 1 user config file : /Users/villedepommes/.condarc populated config files : conda version : 4.5.12 conda-build version : 3.17.6 python version : 3.7.1.final.0 base environment : /usr/local/anaconda3 (writable) channel URLs : https://repo.anaconda.com/pkgs/main/osx-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/free/osx-64 https://repo.anaconda.com/pkgs/free/noarch https://repo.anaconda.com/pkgs/r/osx-64 https://repo.anaconda.com/pkgs/r/noarch https://repo.anaconda.com/pkgs/pro/osx-64 https://repo.anaconda.com/pkgs/pro/noarch package cache : /usr/local/anaconda3/pkgs /Users/villedepommes/.conda/pkgs envs directories : /usr/local/anaconda3/envs /Users/villedepommes/.conda/envs platform : osx-64 user-agent : conda/4.5.12 requests/2.21.0 CPython/3.7.1 Darwin/19.6.0 OSX/10.15.6 UID:GID : 308130403:1876110778 netrc file : None offline mode : False ```
marcelotrevisani commented 3 years ago

I am not sure what might be happening there, especially that osx is not my cup of tea I believe would be better to post that on the tvm repository, they might give you a better explanation and we can recreate the package for osx following their instructions

marcelotrevisani commented 3 years ago

You can try to workaround it installing llvm conda install llvm

chayitw commented 3 years ago

hi Marcelo, i meet the same issue. It seems not work for

  1. conda install llvm
  2. conda install tvm-py

thanks, -chayi

Details about conda and system ( conda info ):

active environment : tvm active env location : /home/chayi/miniconda3/envs/tvm shell level : 1 user config file : /home/chayi/.condarc populated config files : /home/chayi/.condarc conda version : 4.9.2 conda-build version : not installed python version : 3.8.5.final.0 virtual packages : glibc=2.12=0 unix=0=0 __archspec=1=x86_64 base environment : /home/chayi/miniconda3 (writable) channel URLs : https://conda.anaconda.org/conda-forge/linux-64 https://conda.anaconda.org/conda-forge/noarch https://repo.anaconda.com/pkgs/main/linux-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/linux-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /home/chayi/miniconda3/pkgs /home/chayi/.conda/pkgs envs directories : /home/chayi/miniconda3/envs /home/chayi/.conda/envs platform : linux-64 user-agent : conda/4.9.2 requests/2.25.1 CPython/3.8.5 Linux/2.6.32-754.35.1.el6.x86_64 centos/6.10 glibc/2.12 UID:GID : 1013:1013 netrc file : None offline mode : False

Environment (conda list):

packages in environment at /home/chayi/miniconda3/envs/tvm:

#

Name Version Build Channel

_libgcc_mutex 0.1 conda_forge conda-forge _openmp_mutex 4.5 1_gnu conda-forge attrs 20.3.0 pyhd3deb0d_0 conda-forge backtrace 20210212 h27826a3_0 conda-forge binutils_impl_linux-64 2.31.1 h7fc9f1b_5 conda-forge binutils_linux-64 2.31.1 h6176602_9 conda-forge bzip2 1.0.8 h7f98852_4 conda-forge c-ares 1.17.1 h7f98852_1 conda-forge ca-certificates 2020.12.5 ha878542_0 conda-forge certifi 2020.12.5 py36h5fab9bb_1 conda-forge cmake 3.18.2 ha30ef3c_0 anaconda curl 7.75.0 h979ede3_0 conda-forge decorator 4.4.2 py_0 conda-forge dlpack 0.3 he1b5a44_1 conda-forge dmlc 0.4 h7fccf02_1 conda-forge expat 2.2.9 he1b5a44_2 conda-forge gcc_impl_linux-64 7.3.0 habb00fd_1 gcc_linux-64 7.3.0 h553295d_9 importlib-metadata 3.7.2 pypi_0 pypi iniconfig 1.1.1 pypi_0 pypi krb5 1.17.2 h926e7f8_0 conda-forge ld_impl_linux-64 2.34 h53a641e_7 conda-forge libblas 3.9.0 8_openblas conda-forge libcblas 3.9.0 8_openblas conda-forge libcurl 7.75.0 hc4aaa36_0 conda-forge libedit 3.1.20191231 he28a2e2_2 conda-forge libev 4.33 h516909a_1 conda-forge libffi 3.3 h58526e2_2 conda-forge libgcc 7.2.0 h69d50b8_2 libgcc-ng 9.3.0 h2828fa1_18 conda-forge libgfortran-ng 9.3.0 hff62375_18 conda-forge libgfortran5 9.3.0 hff62375_18 conda-forge libgomp 9.3.0 h2828fa1_18 conda-forge liblapack 3.9.0 8_openblas conda-forge libllvm10 10.0.1 hbcb73fb_5 libnghttp2 1.43.0 h812cca2_0 conda-forge libopenblas 0.3.12 pthreads_h4812303_1 conda-forge libssh2 1.9.0 ha56f1ee_6 conda-forge libstdcxx-ng 9.3.0 h6de172a_18 conda-forge libtvm 0.7.0 he1b5a44_0 conda-forge libuv 1.41.0 h7f98852_0 conda-forge llvm 10.0.1 h21ff451_5 lz4-c 1.9.2 he1b5a44_3 conda-forge ncurses 6.2 h58526e2_4 conda-forge numpy 1.19.5 py36h2aa4a07_1 conda-forge openssl 1.1.1j h7f98852_0 conda-forge packaging 20.9 pypi_0 pypi pip 21.0.1 pyhd8ed1ab_0 conda-forge pluggy 0.13.1 pypi_0 pypi psutil 5.8.0 py36h8f6f2f9_1 conda-forge py 1.10.0 pypi_0 pypi pyparsing 2.4.7 pypi_0 pypi pytest 6.2.2 pypi_0 pypi python 3.6.13 hdb3f193_0 python_abi 3.6 1_cp36m conda-forge rang 3.1.0 0 conda-forge readline 8.0 he28a2e2_2 conda-forge rhash 1.4.1 h7f98852_0 conda-forge scipy 1.5.3 py36h9e8f40b_0 conda-forge setuptools 49.6.0 py36h5fab9bb_3 conda-forge sqlite 3.34.0 h74cdb3f_0 conda-forge tk 8.6.10 h21135ba_1 conda-forge toml 0.10.2 pypi_0 pypi tvm-py 0.7.0 py36hd87012b_1 conda-forge typed-ast 1.4.2 py36h8f6f2f9_0 conda-forge typing-extensions 3.7.4.3 pypi_0 pypi wheel 0.36.2 pyhd3deb0d_0 conda-forge xz 5.2.5 h516909a_1 conda-forge zipp 3.4.1 pypi_0 pypi zlib 1.2.11 h516909a_1010 conda-forge zstd 1.4.5 h6597ccf_2 conda-forge

1.relay_quick_start.zip

ngam commented 2 years ago

I will enable llvm here soon. It is strongly recommended to enable it anyway... stay tuned for that in the next few days

ngam commented 2 years ago

https://tvm.apache.org/docs/install/from_source.html#build-the-shared-library

Krovatkin commented 2 years ago

@ngam amazing!!! thank you very much!! so if I do conda install tvm-py I should be able to actually run kernels on CPU?

ngam commented 2 years ago

@ngam amazing!!! thank you very much!! so if I do conda install tvm-py I should be able to actually run kernels on CPU?

I think so. Also, I am enabling metal for osx and cuda as well. Follow this PR #8 (currently messy as I am picking things to add and testing). Once this is done, I will move to the tvm-py to update it. I believe it should be done by the weekend...

ngam commented 2 years ago

@Krovatkin what's in your example.py?

ngam commented 2 years ago

should be done now, I ran their basic unit testing. If you let me know more about your use case, I can probably improve the recipe more. I want to add #15 for example

Krovatkin commented 2 years ago

@ngam

It's been awhile. I think I was simply following this tutorial : https://tvm.apache.org/docs/how_to/optimize_operators/opt_gemm.html

import tvm
import tvm.testing
from tvm import te
import numpy
import timeit

# The size of the matrix
# (M, K) x (K, N)
# You are free to try out different shapes, sometimes TVM optimization outperforms numpy with MKL.
M = 1024
K = 1024
N = 1024

# The default tensor type in tvm
dtype = "float32"

# using Intel AVX2(Advanced Vector Extensions) ISA for SIMD
# To get the best performance, please change the following line
# to llvm -mcpu=core-avx2, or specific type of CPU you use
target = "llvm"
dev = tvm.device(target, 0)

# Random generated tensor for testing
a = [tvm.nd.array](https://tvm.apache.org/docs/reference/api/python/ndarray.html#tvm.nd.array)([numpy.random.rand](https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html#numpy.random.rand)(M, K).astype(dtype), dev)
b = [tvm.nd.array](https://tvm.apache.org/docs/reference/api/python/ndarray.html#tvm.nd.array)([numpy.random.rand](https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html#numpy.random.rand)(K, N).astype(dtype), dev)

np_repeat = 100
np_runing_time = timeit.timeit(
    setup="import numpy\n"
    "M = " + str(M) + "\n"
    "K = " + str(K) + "\n"
    "N = " + str(N) + "\n"
    'dtype = "float32"\n'
    "a = numpy.random.rand(M, K).astype(dtype)\n"
    "b = numpy.random.rand(K, N).astype(dtype)\n",
    stmt="answer = [numpy.dot](https://numpy.org/doc/stable/reference/generated/numpy.dot.html#numpy.dot)(a, b)",
    number=np_repeat,
)
print("Numpy running time: %f" % (np_runing_time / np_repeat))

answer = numpy.dot(a.numpy(), b.numpy())

# Algorithm
k = [te.reduce_axis](https://tvm.apache.org/docs/reference/api/python/te.html#tvm.te.reduce_axis)((0, K), "k")
A = [te.placeholder](https://tvm.apache.org/docs/reference/api/python/te.html#tvm.te.placeholder)((M, K), name="A")
B = [te.placeholder](https://tvm.apache.org/docs/reference/api/python/te.html#tvm.te.placeholder)((K, N), name="B")
C = [te.compute](https://tvm.apache.org/docs/reference/api/python/te.html#tvm.te.compute)((M, N), lambda m, n: [te.sum](https://tvm.apache.org/docs/reference/api/python/te.html#tvm.te.sum)(A[m, k] * B[k, n], axis=k), name="C")

# Default schedule
s = [te.create_schedule](https://tvm.apache.org/docs/reference/api/python/te.html#tvm.te.create_schedule)(C.op)
func = [tvm.build](https://tvm.apache.org/docs/reference/api/python/driver.html#tvm.build)(s, [A, B, C], target=target, name="mmult")
assert func

c = [tvm.nd.array](https://tvm.apache.org/docs/reference/api/python/ndarray.html#tvm.nd.array)([numpy.zeros](https://numpy.org/doc/stable/reference/generated/numpy.zeros.html#numpy.zeros)((M, N), dtype=dtype), dev)
func(a, b, c)
tvm.testing.assert_allclose(c.numpy(), answer, rtol=1e-5)

evaluator = func.time_evaluator(func.entry_name, dev, number=1)
print("Baseline: %f" % evaluator(a, b, c).mean)
ngam commented 2 years ago

Thanks, this works completely fine now: mamba install tvm-py pytest should run it without errors. Closing, but feel free to reopen or open a new issue :)