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

Better track output buffer lifetime and initialized state via types in GEMM internals #481

Merged
merged 2 commits into from
Dec 24, 2024

Conversation

robertknight
Copy link
Owner

For performance the GEMM internals use raw pointers for output tiles, which may be uninitialized if beta is zero. Add lifetimes to OutputTiles and make more use of MaybeUninit<OutT> to track the initialization status of each output tile through the implementation.

This has to use raw pointers because different parts of the output may be
concurrently updated by multiple threads, but it can at least use lifetimes to
tell Rust that it mutably borrows from the input.
If `beta` is zero then the output is potentially uninitialized. This was
represented in the public API (`GemmExecutor::gemm_uninit`) but not internally
as the output was always transmuted to `&mut [OutT]` before calling `gemm_impl`.
Change the internals to use `MaybeUninit<OutT>` everywhere that the output is
potentially uninitialized.

This will help to avoid mistakes like the one fixed in
143f0a3.
@robertknight robertknight merged commit 8c5e4e6 into main Dec 24, 2024
2 checks passed
@robertknight robertknight deleted the output-tiles-lifetimes branch December 24, 2024 08:15
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.

1 participant