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

Treat negative zero as equivalent to positive zero in sm90_sparse_gemm_compressor.hpp #2110

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tlrmchlsmth
Copy link

This PR handles negative zero in sm90_sparse_gemm_compressor.hpp, treating it as equivalent to positive zero. This is easy to solve by the caller before calling the compressor however it involves an extra pass of reading and writing the uncompressed sparse matrix, and it would be nice to generally remove this as a potential footgun.

@hwu36
Copy link
Collaborator

hwu36 commented Feb 19, 2025

@sklevtsov-nvidia , could you please review it?

Copy link
Contributor

@sklevtsov-nvidia sklevtsov-nvidia left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for the contribution!


// Default case - no negative zero
template <typename T>
struct has_negative_zero : std::false_type {};
Copy link
Contributor

Choose a reason for hiding this comment

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

@hwu36 to decide if we want a new file for this trait or if it fits in numeric_types.h or elsewhere

Signed-off-by: Tyler Michael Smith <[email protected]>
struct has_negative_zero : std::false_type {};

// Float types that support negative zero
// Note that this is false for float8_e4m3_t and float8_e5m2_t
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be true, otherwise how is 0x80 value interpreted for these data types? According to the paper it's -0.0, see table 1.

Copy link
Contributor

Choose a reason for hiding this comment

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

@alexsamardzic you are correct, we need to add this for all of fp8/fp6/fp4. @tlrmchlsmth feel free to do this if you can, otherwise we can fix this in #2122

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is a patch to apply on top of this PR, with FP8 and MX data types added (please check that all of them are there, and make sense here), and also minor changes from my #2122 that may be worth adding. For test/unit/transform/device/sm90_sparse_gemm_compressor_legacy.hpp, I don't think it would work with sub-byte data types, but at the moment I don't have access to hardware to test - so I've put there simpler check for negative zero, but also a static assert that would fail if a sub-byte data type used. I hope we can put the patch into this PR, and I'm closing mine now.

patch.txt

Copy link
Author

Choose a reason for hiding this comment

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

ah, you're right - I actually got confused between float8_e4m3fnuz and float8_e4m3fn on this one. I'll apply the patch, thanks!

Copy link
Author

Choose a reason for hiding this comment

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

@alexsamardzic thanks for the patch. I've applied it and it looks good to me. PTAL!

Signed-off-by: Tyler Michael Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants