Repository navigation
Conversation
The reflector batch A and scalars tau are read-only and disjoint from the written panel B/C. Annotate the kernel pointers (and the BatchView data member used by the strided variant) __restrict so the no-alias guarantee is explicit: the compiler may then keep the w0..w3 reduction accumulators in registers across the two i-sweeps without inserting reload-for-aliasing of ak[i]/b*[kk]. A genuine zero-cost annotation -- correctness is unchanged (the portable kernel test passes on both GCC and Clang) and, on compilers whose alias analysis is weaker than GCC 13 / Clang at -O3 (which already emit identical code here), it removes a scheduling barrier in the hot loop. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WUZVMR8mGYWqPxnjzaLNoc
A view is a non-owning accessor and should not carry an aliasing contract: putting __restrict on BatchView::data overloads the type's meaning and would apply to every use, not just these kernels. Revert that and keep the annotation on the local pointers at the point of use (the contiguous kernel's A/tau/B and the strided kernel's tau). The strided A/C disjointness is left to the compiler's alias analysis. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WUZVMR8mGYWqPxnjzaLNoc
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WUZVMR8mGYWqPxnjzaLNoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change adds
__restrictqualifiers to pointer variables in the QR decomposition helper functions to enable better compiler optimizations by indicating that these pointers do not alias with other pointers in the same scope.Key Changes
__restrictqualifier to pointersA,tau, andBinormqr_compact_group()function__restrictqualifier to pointertauinormqr_compact_group_strided()functionImplementation Details
The
__restrictkeyword is a C99 feature that tells the compiler that a pointer is the only way to access the object it points to within a given scope. This allows the compiler to perform more aggressive optimizations such as:These changes are particularly beneficial in performance-critical linear algebra routines where the compiler can now safely assume no aliasing between the input matrix
A, the Householder reflector coefficientstau, and the output matrixB.https://claude.ai/code/session_01WUZVMR8mGYWqPxnjzaLNoc