apache / apache/tvm

[Bug] TVMError: unknown intrinsic Op(tir.atan) during relax.build with custom atan TIR function

Open
#17,487 2 comments 0 reactions 0 assignees View on GitHub
needs-triage type: bug
Dominant language
Python
Stars
13.7k
Forks
4k
Avg merge
2d 19h
Merged PRs (30d)
111

Description

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

```python
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reproduction using relax.build(mod, target='llvm') and inspect src/target/llvm/codegen_llvm.cc at line 1491, where Op(tir.atan) is reported as unknown. Trace how T.atan is lowered and registered for the LLVM target, then verify that the provided float16 custom TIR function builds without the error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.