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

[lang] Broken ti.math.sign implementations #8077

Closed
bobcao3 opened this issue May 25, 2023 · 2 comments
Closed

[lang] Broken ti.math.sign implementations #8077

bobcao3 opened this issue May 25, 2023 · 2 comments
Assignees
Labels
bug We've confirmed that this is an BUG

Comments

@bobcao3
Copy link
Collaborator

bobcao3 commented May 25, 2023

import taichi as ti

@ti.kernel
def test(val : ti.f32) -> ti.f32:
    return ti.math.sign(val)

ti.init(arch=ti.gpu)

print(test(0.5))
print(test(-0.5))
print(test(0.0))

Under LLVM backends, prints:

1.0
1.0
0.0

Under GFX backends, crash with

Assertion failed: type->AsInteger(), file C:\Users\bobca\source\repos\taichi\external\SPIRV-Tools\source\opt\folding_rules.cpp, line 86
@bobcao3 bobcao3 added the bug We've confirmed that this is an BUG label May 25, 2023
@github-project-automation github-project-automation bot moved this to Untriaged in Taichi Lang May 25, 2023
@jim19930609 jim19930609 moved this from Untriaged to Todo in Taichi Lang May 26, 2023
@ailzhang
Copy link
Contributor

Took a quick look that it seems to be related to we feed a u1 to somewhere requires a 32bits int. Transferring to @listerily to send a fix, thanks!

@ailzhang ailzhang assigned listerily and unassigned ailzhang May 26, 2023
ailzhang pushed a commit that referenced this issue May 26, 2023
Issue: #8077 

### Brief Summary

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 5c77628</samp>

Fix `sign` function bug for negative values and add unit test. The bug
caused `sign` to return wrong signs for negative values on LLVM and
causes crashes on gfx. The unit test checks `sign` for various inputs in
`test_unary_ops.py`.

### Walkthrough

<!--
copilot:walkthrough
-->
### <samp>🤖 Generated by Copilot at 5c77628</samp>

* Fix bug in `sign` function that caused incorrect results or crashes
for negative values
([link](https://github.com/taichi-dev/taichi/pull/8082/files?diff=unified&w=0#diff-5b3923516b48467202850afb384ef9901ecefae0173f03bcc9055adffe96d738L276-R276))
* Add unit test for `sign` function to verify its behavior for positive,
negative, and zero values
([link](https://github.com/taichi-dev/taichi/pull/8082/files?diff=unified&w=0#diff-8ac29975a96f4251587f71dff241aa3724d26d4fcbf7b757901076205924bba5R145-R155))
@ailzhang
Copy link
Contributor

Closing via #8082, thanks @listerily !

@github-project-automation github-project-automation bot moved this from Todo to Done in Taichi Lang May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug We've confirmed that this is an BUG
Projects
Status: Done
Development

No branches or pull requests

3 participants