Skip to content

Add __restrict qualifiers to pointer variables in ormqr functions - #17

Open
ivan-pi wants to merge 3 commits into
mainfrom
claude/great-newton-tfmmyz
Open

ivan-pi wants to merge 3 commits into
mainfrom
claude/great-newton-tfmmyz

Conversation

@ivan-pi

@ivan-pi ivan-pi commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Summary

This change adds __restrict qualifiers 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

  • Added __restrict qualifier to pointers A, tau, and B in ormqr_compact_group() function
  • Added __restrict qualifier to pointer tau in ormqr_compact_group_strided() function

Implementation Details

The __restrict keyword 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:

  • Better instruction reordering
  • Improved vectorization
  • Reduced memory barrier constraints

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 coefficients tau, and the output matrix B.

https://claude.ai/code/session_01WUZVMR8mGYWqPxnjzaLNoc

claude added 3 commits June 24, 2026 13:39
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
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.

2 participants