Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Thrsu opened this issue Oct 24, 2024 · 1 comment
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug

Comments

@Thrsu
Copy link
Contributor

Thrsu commented Oct 24, 2024

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.

@Thrsu Thrsu added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug labels Oct 24, 2024
@Cookiee235
Copy link
Contributor

I came across a similar bug with the crash message: TVMError: unknown intrinsic Op(tir.acos)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug
Projects
None yet
Development

No branches or pull requests

2 participants