tvm
tvm copied to clipboard
[Bug] TVMError: unknown intrinsic Op(tir.atan) during relax.build with custom atan TIR function
The below code defines a custom TIR function that computes the atan of each element in a buffer of shape (20,) and then uses it within a relax function. When trying to build the module using relax.build targeting llvm, it raises an error: TVMError: unknown intrinsic Op(tir.atan).
Expected behavior
The tir.atan operation should be recognized and compiled correctly without throwing this error, as it is a common mathematical operation.
Actual behavior
File "/software/tvm/src/target/llvm/codegen_llvm.cc", line 1491
TVMError: unknown intrinsic Op(tir.atan)
Steps to reproduce
import tvm
from tvm import relax
from tvm.script import ir as I
from tvm.script import tir as T
from tvm.script import relax as R
@I.ir_module
class Module:
@T.prim_func(private=True)
def tir_atan(x: T.Buffer((T.int64(20),), "float16"), compute: T.Buffer((T.int64(20),), "float16")):
T.func_attr({"tir.noalias": T.bool(True)})
for i0 in range(T.int64(20)):
with T.block("compute"):
v_i0 = T.axis.spatial(T.int64(20), i0)
T.reads(x[v_i0])
T.writes(compute[v_i0])
compute[v_i0] = T.atan(x[v_i0])
@R.function
def main(x: R.Tensor((20,), dtype="float16")) -> R.Tensor((20,), dtype="float16"):
R.func_attr({"num_input": 1})
cls = Module
with R.dataflow():
gv = R.call_tir(cls.tir_atan, (x,), out_sinfo=R.Tensor((20,), dtype="float16"))
R.output(gv)
return gv
mod = Module
ex = relax.build(mod, target='llvm')
It is unclear if this is due to a missing intrinsic support for atan in TIR or if there is an issue with registering this intrinsic in the target. Any guidance or fixes to resolve this issue would be appreciated.
I came across a similar bug with the crash message: TVMError: unknown intrinsic Op(tir.acos)
This is because the code intrinsic not dispatch not being registered for this op