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

bool cast kernel #1391

Merged
merged 1 commit into from
Mar 1, 2024
Merged

bool cast kernel #1391

merged 1 commit into from
Mar 1, 2024

Conversation

louisfd
Copy link
Member

@louisfd louisfd commented Mar 1, 2024

In wgpu, bools are u32, where false is zero and true is anything else.
Sometimes it can be an optimization to not change the bits, for instance in
passing from 1_f32 which has bit representation 00111111 10000000 00000000 00000000
to the bool true and using afterwards for inplace operations, it's practical to not have to change the bits to 00000000 00000000 00000000 00000001

However, when we explicitly casted bool to something else, we used a kernel that did not know we were using bool, it just knew it had a u32, so it was treated like an integer.

Hence, 1_f32 became true, which in turn became 1065353216 or 1065353216.0 (which is 00111111 10000000 00000000 00000000 as a u32).

The fix is to call a new cast kernel who explicitly knows it must consider its u32 inputs as bools.

Fix #1315
Fix #1388

Copy link
Collaborator

@antimora antimora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you for fixing it.

Copy link

codecov bot commented Mar 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.49%. Comparing base (ec490cc) to head (d500127).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1391      +/-   ##
==========================================
- Coverage   85.56%   85.49%   -0.07%     
==========================================
  Files         594      594              
  Lines       67997    68095      +98     
==========================================
+ Hits        58180    58217      +37     
- Misses       9817     9878      +61     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nathanielsimard nathanielsimard merged commit 9a0b2d6 into main Mar 1, 2024
15 checks passed
@nathanielsimard nathanielsimard deleted the fix/wgpu/bool_cast branch March 1, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants