Skip to content

Refactor: extract shared compact kernel machinery to common header - #29

Merged
ivan-pi merged 4 commits into
mainfrom
claude/rename-ormqr-files-z0fhcd
Aug 7, 2026
Merged

Refactor: extract shared compact kernel machinery to common header#29
ivan-pi merged 4 commits into
mainfrom
claude/rename-ormqr-files-z0fhcd

Conversation

@ivan-pi

@ivan-pi ivan-pi commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

This PR refactors the compact (interleaved-batch) kernel infrastructure by extracting shared machinery into a dedicated common header file. This eliminates code duplication across multiple kernel implementations (geqrf, potrf, ormqr, trsm) and improves maintainability.

Key Changes

  • New file cqr_compact_common.hpp: Centralizes shared machinery previously duplicated in individual kernel headers:

    • pack<T,V> template: the V-wide SIMD element type with GNU vector attributes
    • vsqrt() and broadcast() lane-wise vector helpers
    • BatchView template: strided 2-D view for interleaved matrix groups
    • make_view() and make_const_view() factory functions
  • Renamed and refactored kernel headers:

    • cqr_compact.hppcqr_ormqr_compact.hpp (now ormqr-specific)
    • Removed duplicate definitions of pack, BatchView, vsqrt, broadcast
    • Added #include "cqr_compact_common.hpp" to import shared types
    • Updated internal documentation to reference the common header
  • Updated other kernel headers to include the common header:

    • cqr_geqrf_compact.hpp
    • cqr_potrf_compact.hpp
    • cqr_trsm_compact.hpp
  • Renamed dispatch and implementation files for clarity:

    • cqr_compact_dispatch.cppcqr_ormqr_compact_dispatch.cpp
    • cqr_mkl_ext.cppcqr_mkl_ormqr.cpp
    • test_cqr_compact.cpptest_cqr_ormqr_compact.cpp
    • test_cqr_mkl_ext.cpptest_cqr_ormqr_mkl.cpp
  • Updated CMakeLists.txt and documentation (README.md, PLANS.md) to reflect new file names and structure

Implementation Details

The refactoring maintains full API and ABI compatibility while improving code organization. The common header is included by all compact kernel implementations, ensuring consistent definitions of the V-wide pack type and addressing machinery across geqrf, potrf, ormqr, and trsm kernels. File naming now explicitly indicates which routine each file implements (e.g., cqr_ormqr_compact.hpp vs generic cqr_compact.hpp).

https://claude.ai/code/session_01CbYs39BXPvFUejjDq7kYsD

claude added 4 commits August 6, 2026 13:37
Rename the ormqr implementation files to the project's per-routine
naming scheme, matching geqrf/potrf/trsm:

  cqr_compact.hpp          -> cqr_ormqr_compact.hpp
  cqr_compact_dispatch.cpp -> cqr_ormqr_compact_dispatch.cpp
  cqr_mkl_ext.cpp          -> cqr_mkl_ormqr.cpp
  test_cqr_compact.cpp     -> test_cqr_ormqr_compact.cpp
  test_cqr_mkl_ext.cpp     -> test_cqr_ormqr_mkl.cpp

The shared C API headers (cqr_mkl_ext.h, cqr_compact.h) and the
cqr_mkl_ext library target keep their umbrella names.

Split the common helpers and the packed vector type out of the old
cqr_compact.hpp into a new cqr_compact_common.hpp, shared by every
routine header: pack<T,V>, vsqrt, broadcast, BatchView, and the
make_view/make_const_view factories. cqr_ormqr_compact.hpp now holds
only the ormqr-specific Direction enum and kernels and includes the
common header the same way geqrf/potrf/trsm already do.

Update the CMake sources and ctest names (portable_kernel ->
portable_ormqr, mkl_compact_suites -> mkl_ormqr_suites) and the
README/PLANS references.

Verified: full MKL build (11/11 ctest) and portable -DCQR_WITH_MKL=OFF
build (4/4 ctest) pass; clang-format clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CbYs39BXPvFUejjDq7kYsD
The MKL adapter switches on MKL_COMPACT_PACK directly (like potrf's row
already states) rather than unwrapping it to a runtime interleave width
V; align the file-table description with the code.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CbYs39BXPvFUejjDq7kYsD
BatchView::operator() cast both indices to size_t before scaling by the
strides, forcing the strided sweep's address arithmetic to 64-bit. The
batch and matrix dimensions all fit in the kernel's Int (the compact
format targets many small matrices), so type the element strides as Int
and compute i*special + p*panel in Int -- no widening of the loop
induction variables, keeping the strided sweep vectorizable. make_view /
make_const_view take Int strides to match, and the four routine drivers
drop their (size_t) element-stride casts. The large per-group base
offset stays size_t and is applied to the pointer before the view is
built. Mark operator() inline.

No behavior change; full MKL suite (11/11) and portable -DCQR_WITH_MKL=OFF
suite (4/4) pass, clang-format clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CbYs39BXPvFUejjDq7kYsD
Both MKL adapters switch on MKL_COMPACT_PACK directly, like potrf and
ormqr; drop the older "unwraps -> V" wording so all four cqr_mkl_*.cpp
file-table rows describe the dispatch the same way. Each row still names
the specific modes its adapter maps (geqrf: MKL_LAYOUT; trsm: the full
MKL enum set).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CbYs39BXPvFUejjDq7kYsD
@ivan-pi
ivan-pi merged commit c3fe692 into main Aug 7, 2026
2 of 6 checks passed
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