apache / tvm

Open deep learning compiler stack for cpu, gpu and specialized accelerators
https://tvm.apache.org/
Apache License 2.0
11.58k stars 3.43k forks source link

[Bug] Crash in tvm.build when constructing the tir.isnan expression manually by tir.Call #9406

Open syang-ng opened 2 years ago

syang-ng commented 2 years ago

I try to construct the tir.Call expression manually, but after I execute the tvm.build, the program crashes.

Expected behavior

Execute tvm.build() successfully.

Actual behavior

The program will crash if we construct the tir.isnan manually.

And another interesting thing is that GDB can not print the whole backtraces, just like the image listed below: image

Environment

Ubuntu18.04, cmake 3.18.2, llvm 12, tested on latest git 4087e72

Steps to reproduce

Here is the script to reproduce the bug:

import tvm

v = tvm.tir.Var('v', 'float32')
value = tvm.tir.isnan(v)
op = value.op

buf = tvm.tir.buffer.decl_buffer((1,))
value = tvm.tir.Call('int32', op, [0])
s = tvm.tir.Store(buf.data, value, 0)
f = tvm.tir.PrimFunc({buf.data}, s)

tvm.build(f)
wrongtest-intellif commented 2 years ago
import tvm

v = tvm.tir.Var('v', 'float32')
value = tvm.tir.isnan(v)
op = value.op
buf = tvm.tir.buffer.decl_buffer((1,), "bool")
value = tvm.tir.Call('bool', op, [0.0])
s = tvm.tir.Store(buf.data, value, 0)
f = tvm.tir.PrimFunc({buf.data}, s)
tvm.build(f)

Above is what works for me, isnan() seems buggy with integer type now

syang-ng commented 2 years ago

Thanks for your reply! I found a similar issue discussed in the forum, it seems that isnan / sqrt / ... are designed for floating-point numbers. Though these functions accept a floating-point number, they don't check the date type of parameters, and then cause such crash in codegen. Maybe it would be better to tell the developers that they are floating-point specific functions in the document or somewhere else😂