yizhihenpidehou opened a new issue, #17238:
URL: https://github.com/apache/tvm/issues/17238

   Thanks for participating in the TVM community! We use https://discuss.tvm.ai 
for any general usage questions and discussions. The issue tracker is used for 
actionable items such as feature proposals discussion, roadmaps, and bug 
tracking.  You are always welcomed to post on the forum first :smile_cat:
   
   Issues that are inactive for a period of time may get closed. We adopt this 
policy so that we won't lose track of actionable issues that may fall at the 
bottom of the pile. Feel free to reopen a new one if you feel there is an 
additional problem that needs attention when an old one gets closed.
   
   ### Expected behavior
   
   I want to run the code:
   `
   rt_lib = tvm.build(MyModule, target="llvm")
   `
   
   ### Actual behavior
   
   Traceback (most recent call last):
     File 
"/Users/yizhihenpidehou/Desktop/tvm_experiment/lecture2_TensorIR/main.py", line 
40, in <module>
       rt_lib = tvm.build(MyModule, target="llvm")
     File 
"/Users/yizhihenpidehou/Desktop/fdu/eg/tvm/python/tvm/driver/build_module.py", 
line 297, in build
       rt_mod_host = _driver_ffi.tir_to_runtime(annotated_mods, target_host)
     File 
"/Users/yizhihenpidehou/Desktop/fdu/eg/tvm/python/tvm/_ffi/_ctypes/packed_func.py",
 line 240, in __call__
       raise_last_ffi_error()
     File "/Users/yizhihenpidehou/Desktop/fdu/eg/tvm/python/tvm/_ffi/base.py", 
line 481, in raise_last_ffi_error
       raise py_err
   tvm.error.InternalError: Traceback (most recent call last):
     File "/Users/yizhihenpidehou/Desktop/fdu/eg/tvm/src/target/codegen.cc", 
line 72
   InternalError: Check failed: (bf != nullptr) is false: target.build.llvm is 
not enabled
   
   ### Environment
   
   tvm path: /Users/yizhihenpidehou/Desktop/fdu/eg/tvm/python/tvm/__init__.py
   Operating System: macOS M2 arm;  
   TVM version:0.18.dev0
   <img width="423" alt="image" 
src="https://github.com/user-attachments/assets/c24a2735-3189-43be-abca-4a3e69d41dbe";>
   
   ### Steps to reproduce
   1. build tvm from source code; 
   2. set(USE_LLVM "/opt/homebrew/opt/llvm/bin/llvm-config --link-static") in 
cmake.config
   3. cmake ..  & make
   4. cd /python subfolder in tvm, and python setup.py install, but I got such 
error 
   <img width="561" alt="image" 
src="https://github.com/user-attachments/assets/c301f5ad-3782-4afa-b9df-68a5457f4151";>
   5. follow Building with a Conda Environment follow [conda install 
link](https://tvm.apache.org/docs/install/from_source.html#python-package-installation:~:text=with%20a%20Conda-,Environment,-%C2%B6)
   6. run my code
   
   `
   import sys
   import numpy as np
   import tvm
   from tvm.ir.module import IRModule
   from tvm.script import tir as T
   print("tvm path:",tvm.__file__)
   print("tvm version:",tvm.__version__)
   dtype = "float32"
   a_np = np.random.rand(128, 128).astype(dtype)
   b_np = np.random.rand(128, 128).astype(dtype)
   c_mm_relu = np.maximum(a_np @ b_np, 0)
   
   @tvm.script.ir_module
   class MyModule:
       @T.prim_func
       def mm_relu(A: T.Buffer((128, 128), "float32"),
                   B: T.Buffer((128, 128), "float32"),
                   C: T.Buffer((128, 128), "float32")):
           T.func_attr({"global_symbol": "mm_relu", "tir.noalias": True})
           Y = T.alloc_buffer((128, 128), dtype="float32")
           for i, j, k in T.grid(128, 128, 128):
               with T.block("Y"):
                   # [block_axis] = T.axis.[axis_type]([axis_range], 
[mapped_value])
                   vi = T.axis.spatial(128, i)
                   vj = T.axis.spatial(128, j)
                   vk = T.axis.reduce(128, k)
                   with T.init():
                       Y[vi, vj] = T.float32(0)
                   Y[vi, vj] = Y[vi, vj] + A[vi, vk] * B[vk, vj]
           for i, j in T.grid(128, 128):
               with T.block("C"):
                   vi = T.axis.spatial(128, i)
                   vj = T.axis.spatial(128, j)
                   C[vi, vj] = T.max(Y[vi, vj], T.float32(0))
   
   
   rt_lib = tvm.build(MyModule, target="llvm")
   
   a_nd = tvm.nd.array(a_np)
   b_nd = tvm.nd.array(b_np)
   c_nd = tvm.nd.empty((128, 128), dtype="float32")
   print(type(c_nd))
   
   func_mm_relu = rt_lib["mm_relu"]
   func_mm_relu(a_nd, b_nd, c_nd)
   
   np.testing.assert_allclose(c_mm_relu, c_nd.numpy(), rtol=1e-5)
   
   import tvm
   from tvm import te
   import IPython
   
   A = te.placeholder((128, 128), "float32", name="A")
   B = te.placeholder((128, 128), "float32", name="B")
   k = te.reduce_axis((0, 128), "k")
   Y = te.compute((128, 128), lambda i, j: te.sum(A[i, k] * B[k, j], axis=k), 
name="Y")
   C = te.compute((128, 128), lambda i, j: te.max(Y[i, j], 0), name="C")
   
   te_func = te.create_prim_func([A, B, C]).with_attr({"global_symbol": 
"mm_relu"})
   MyModuleFromTE = tvm.IRModule({"mm_relu": te_func})
   print(IPython.display.Code(MyModuleFromTE.script(), language="python"))
   `
   
   ### Triage
   
   Please refer to the list of label tags 
[here](https://github.com/apache/tvm/wiki/Issue-Triage-Labels) to find the 
relevant tags and add them below in a bullet format (example below).
   
   * needs-triage
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to