-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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] Type cast problem when using torch tensor as kernel args #7915
Comments
FYI a simpler repro for this is
CPU backend produces the expected result. But I haven't looked into the root cause yet. |
In the algebraic simplification pass, Taichi combines two cast stmts when they are both cast into integral values. However, (float -> int -> int) is not equivalent to (float -> int). So maybe you can change the is_redundant_cast function to solve this issue? When I disabled the advanced optimization, the code works as expected: import taichi as ti
ti.init(arch=ti.gpu, advanced_optimization=False)
@ti.kernel
def my_cast(x: ti.f32):
y = ti.floor(x, ti.i32)
print(ti.cast(y, ti.u32))
if __name__ == "__main__":
my_cast(-1) The output is
|
@Dinngger Aha nice catch, thanks! Let me take a look there! |
Fixes #7915 ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at ed6302b</samp> Fix a bug in `alg_simp` that removed casts between signed and unsigned integers. Add a test case in `test_optimization` to check the cast simplification. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at ed6302b</samp> * Fix a bug in algebraic simplification that incorrectly removed some casts between signed and unsigned integers ([link](https://github.com/taichi-dev/taichi/pull/7944/files?diff=unified&w=0#diff-77d8ca8e4dc6081988bd6dddb74bb9a5485af28ce3e0b43bc06d123256695513L63-R66)) * Add a test case to verify the correctness of the cast simplification after the bug fix ([link](https://github.com/taichi-dev/taichi/pull/7944/files?diff=unified&w=0#diff-b8b031f0789413acece482512df4af5b8419a2a2dea3624b26114bbb9b57d334R146-R155))
Fixes taichi-dev#7915 ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at ed6302b</samp> Fix a bug in `alg_simp` that removed casts between signed and unsigned integers. Add a test case in `test_optimization` to check the cast simplification. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at ed6302b</samp> * Fix a bug in algebraic simplification that incorrectly removed some casts between signed and unsigned integers ([link](https://github.com/taichi-dev/taichi/pull/7944/files?diff=unified&w=0#diff-77d8ca8e4dc6081988bd6dddb74bb9a5485af28ce3e0b43bc06d123256695513L63-R66)) * Add a test case to verify the correctness of the cast simplification after the bug fix ([link](https://github.com/taichi-dev/taichi/pull/7944/files?diff=unified&w=0#diff-b8b031f0789413acece482512df4af5b8419a2a2dea3624b26114bbb9b57d334R146-R155))
Describe the bug
When using pytorch Tensor as kernel args, ti.cast performs wrong.
To Reproduce
Log/Screenshots
Additional comments
it's performs normal when changing torch.Tensor into torch.IntTensor.
The text was updated successfully, but these errors were encountered: