gemini-code-assist[bot] commented on code in PR #18772:
URL: https://github.com/apache/tvm/pull/18772#discussion_r2802513091
##########
tests/python/codegen/test_target_codegen_llvm.py:
##########
@@ -370,6 +370,30 @@ def main(A: T.Buffer((64,), "int32"), C: T.Buffer((64,),
"float32")):
tvm.testing.assert_allclose(c.numpy(), c_np)
[email protected]_llvm
+def test_llvm_cast_float_to_bool():
+ @I.ir_module
+ class Module:
+ @T.prim_func
+ def main(A: T.Buffer((4,), "float32"), C: T.Buffer((4,), "bool")):
+ T.func_attr({"tir.noalias": True})
+ for i in range(4):
+ with T.sblock("C"):
+ v_i = T.axis.spatial(4, i)
+ T.reads(A[v_i])
+ T.writes(C[v_i])
+ C[v_i] = T.Cast("bool", A[v_i])
+
+ n = 4
+ f = tvm.compile(Module, target="llvm")
+ dev = tvm.cpu(0)
+ a = tvm.runtime.tensor(np.array([0.0, 1.0, np.nan, np.inf],
dtype="float32"), dev)
+ c = tvm.runtime.empty((n,), dtype="bool", device=dev)
+ f(a, c)
+ c_np = np.array([False, True, True, True], dtype="bool")
+ tvm.testing.assert_allclose(c.numpy(), c_np)
Review Comment:

This is a great test for verifying the new behavior. To improve test
coverage, consider parameterizing it to run against different float types
(`float16`, `float32`, `float64`), since the change in `codegen_llvm.cc`
affects all float types.
```python
@tvm.testing.requires_llvm
@pytest.mark.parametrize("dtype", ["float16", "float32", "float64"])
def test_llvm_cast_float_to_bool(dtype):
@I.ir_module
class Module:
@T.prim_func
def main(A: T.Buffer((4,), dtype), C: T.Buffer((4,), "bool")):
T.func_attr({"tir.noalias": True})
for i in range(4):
with T.sblock("C"):
v_i = T.axis.spatial(4, i)
T.reads(A[v_i])
T.writes(C[v_i])
C[v_i] = T.Cast("bool", A[v_i])
n = 4
f = tvm.compile(Module, target="llvm")
dev = tvm.cpu(0)
a = tvm.runtime.tensor(np.array([0.0, 1.0, np.nan, np.inf],
dtype=dtype), dev)
c = tvm.runtime.empty((n,), dtype="bool", device=dev)
f(a, c)
c_np = np.array([False, True, True, True], dtype="bool")
tvm.testing.assert_allclose(c.numpy(), c_np)
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]