taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.56k stars 2.29k forks source link

Unnecessary "Possible loss of precision" warning #8559

Open agravier opened 4 months ago

agravier commented 4 months ago

Describe the bug When assigning a constant to a field cell, Taichi emits a warning about possible loss of precision even though it's possible to determine at compile time that this is not the case

To Reproduce

import taichi as ti

ti.init(arch=ti.gpu)
init = ti.field(ti.i8, shape=(2, 3))
init[0, 0] = 1

Log/Screenshots

$ python tests/assign_precision.py
[Taichi] version 1.7.1, llvm 15.0.7, commit 0f143b2f, osx, python 3.10.9
[Taichi] Starting on arch=arm64
[W 07/10/24 11:33:51.553 33474852]
Assign may lose precision: unknown <- i8

Additional comments Maybe I can just disable this check and runtime warning? It has a performance impact as it's emitted each time I do such an assignment.

niuiniuin commented 3 months ago

I met the exactly same situation. My wild guess is that the type of field cells probably is not recognized in the python scope. Doing the assignment in a taichi kernel can circumvent the warning.

import taichi as ti
ti.init(arch=ti.gpu, offline_cache=False)

init = ti.field(ti.i8, shape=(2, 3))

# init[0, 0] = 1
# print(init)

@ti.kernel
def assign_a_cell():
    init[0, 0] = ti.cast(1, ti.i8)
assign_a_cell()
print(init)
niuiniuin commented 2 months ago

Maybe this issue can be closed. They have fixed this bug in version 1.7.2 (#8553).

OmidGhotbi commented 2 months ago

i still can see the issue in taichi 1.7.2 [Taichi] version 1.7.2, llvm 15.0.1, commit 0131dce9, win, python 3.10.13 cmolcore imported v1.14.5

[W 09/22/24 01:31:04.204 39092] TaichiWarning
While compiling `snode_deactivate_c40_0`, File "D:\Blender 3.6\3.6\python\lib\site-packages\taichi\_kernels.py", line 267, in snode_deactivate:
        deactivate(b, I)
        ^^^^^^^^^^^^^^^^
Field index 0 not int32, casting into int32 implicitly
[W 09/22/24 01:31:04.204 39092] TaichiWarning
While compiling `snode_deactivate_c40_0`, File "D:\Blender 3.6\3.6\python\lib\site-packages\taichi\_kernels.py", line 267, in snode_deactivate:
        deactivate(b, I)