Skip to content

Separate GPU symmetry filters and align callbacks with loop order - #21

Open
maki49 wants to merge 5 commits into
abacusmodeling:masterfrom
maki49:symfilter_refactor
Open

maki49 wants to merge 5 commits into
abacusmodeling:masterfrom
maki49:symfilter_refactor

Conversation

@maki49

@maki49 maki49 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

GPU contractions use different atom-loop orders from CPU contractions. This keeps a separate GPU symmetry policy and passes every callback its enclosing-loop order, while screening the same final output atom pair and relative cell.

Filter selection now happens once before each backend's OpenMP/atom loops. LRI::filter_atom is an optional callable returning const Filter_Atom*; LRI has no symmetry-specific state, concrete policy includes, casts or allocation rules. Inner loops call the selected filter directly.

  • Cherry-pick maintainer linpz's wrapper commit from #22, retaining authorship, and adapt it into a callable selector. The wrapper does not inherit from Filter_Atom and has no forwarding filter_for* methods.
  • Exx/GW/RPA::set_symmetry constructs a wrapper containing CPU and (in GPU builds) GPU policies. Repeated contractions select those existing objects. An empty selector disables filtering.
  • The wrapper owns shared immutable copies of period and sector, so temporary caller data and copied LRI/selector objects do not leave dangling references. Calling set_symmetry updates configuration.
  • LRI_Cal_Mode remains in its original location in LRI.h, and inner callbacks retain pointer/-> access. Both CPU modes select the CPU policy. Direct backend calls select their own mode before entering loops, independently of the public cal_mode field.
  • Restore Filter_Atom_Symmetry to its pre-Fix real-space symmetry filtering in GPU contractions #16 form; retain Filter_Atom_Symmetry_GPU and the validated GPU callback argument order. Keep the original accumulation tests enabled.

Validation (latest callable-wrapper implementation):

Check Result
CPU-only build; 1/4 threads, both CPU modes, all 18 labels plus sum, real/complex Pass
GPU-enabled build Pass
GPU numerical regression, 1/4 threads, all labels, sectors and seeded accumulation Pass: job 3993469, exit 0:0; 456 checks per thread count, including 152 GPU checks
Exactly one selector invocation per contraction, stable selected-filter identity, backend switching, caller configuration lifetime, copied selector and symmetry disable Covered by numerical regression assertions
Exx/GW/RPA set_symmetry template compilation Pass
Callback arguments match GPU loop nesting 112/112 pass

GPU job: 3993469, df1, V100 16GB. Logs and matching header/test hashes: ~/work/lr-grad/filter-wrapper-pointer-20261110/validation-3993469.tar.gz. No additional ABACUS runs are required for this wrapper-only change; the material results previously recorded for the earlier implementation are not claimed as validation of this revision.

GPU symmetry callback contract

Arguments follow the enclosing loops from outermost to innermost. filter_for31
always returns false (intermediate construction); filter_for32 rejects only
output pairs outside the sector. Bold argument tuples changed in this refactor.

Label Family filter_for31 arguments filter_for32 arguments Output pair screened by filter_for32
a0b0_a1b1 a01b01_a01b01 (Aa01, Ab01, Ab2) (Aa01, Aa2, Ab2) (Aa2, Ab2)
a0b1_a1b0 a01b01_a01b01 (Aa01, Ab01, Ab2) (Aa01, Aa2, Ab2) (Aa2, Ab2)
a0b0_a1b2 a01b01_a01b2 (Ab01, Ab2, Aa01) (Aa01, Ab01, Aa2) (Aa2, Ab01)
a0b1_a1b2 a01b01_a01b2 (Ab01, Ab2, Aa01) (Aa01, Ab01, Aa2) (Aa2, Ab01)
a0b2_a1b0 a01b01_a01b2 (Ab01, Ab2, Aa01) (Aa01, Ab01, Aa2) (Aa2, Ab01)
a0b2_a1b1 a01b01_a01b2 (Ab01, Ab2, Aa01) (Aa01, Ab01, Aa2) (Aa2, Ab01)
a0b0_a2b1 a01b01_a2b01 (Aa01, Aa2, Ab01) (Aa01, Ab01, Ab2) (Aa01, Ab2)
a0b1_a2b0 a01b01_a2b01 (Aa01, Aa2, Ab01) (Aa01, Ab01, Ab2) (Aa01, Ab2)
a1b0_a2b1 a01b01_a2b01 (Aa01, Aa2, Ab01) (Aa01, Ab01, Ab2) (Aa01, Ab2)
a1b1_a2b0 a01b01_a2b01 (Aa01, Aa2, Ab01) (Aa01, Ab01, Ab2) (Aa01, Ab2)
a0b0_a2b2 a01b01_a2b2 (Aa01, Aa2, Ab2) (Aa01, Ab01, Ab2) (Aa01, Ab01)
a0b1_a2b2 a01b01_a2b2 (Aa01, Aa2, Ab2) (Aa01, Ab01, Ab2) (Aa01, Ab01)
a1b0_a2b2 a01b01_a2b2 (Aa01, Aa2, Ab2) (Aa01, Ab01, Ab2) (Aa01, Ab01)
a1b1_a2b2 a01b01_a2b2 (Aa01, Aa2, Ab2) (Aa01, Ab01, Ab2) (Aa01, Ab01)
a1b2_a2b1 a01b2_a2b01 (Ab01, Ab2, Aa01) (Aa01, Aa2, Ab01) (Aa01, Ab01)
a0b2_a2b0 a01b2_a2b01 (Ab01, Ab2, Aa01) (Aa01, Aa2, Ab01) (Aa01, Ab01)
a0b2_a2b1 a01b2_a2b01 (Ab01, Ab2, Aa01) (Aa01, Aa2, Ab01) (Aa01, Ab01)
a1b2_a2b0 a01b2_a2b01 (Ab01, Ab2, Aa01) (Aa01, Aa2, Ab01) (Aa01, Ab01)

filter_for1(Aa01) is a no-op for the first two families (Aa01 is intermediate),
and checks left-output membership for the other three. filter_for1(Ab01) checks
right-output membership wherever it occurs. All filter_for2 calls are no-ops
except the final (Aa01, Ab01) stage of a01b2_a2b01, which checks that output
pair. In that family's second stage, the former inner
filter_for2(Aa01, Ab01) check is absorbed into
filter_for32(Aa01, Aa2, Ab01); Aa2 remains an unrestricted summation atom.

For two cell-bearing output atoms the relative cell is (Rb - Ra) % period;
with Aa01 at the origin it is Rb % period. An empty sector retains the existing
unrestricted behavior. The numerical regression also disables symmetry on a copied selector after each
filtered run to verify independent configuration of copied LRI objects.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 15:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@maki49
maki49 force-pushed the symfilter_refactor branch from d31699a to 2ed47de Compare November 10, 2026 09:19
@maki49
maki49 force-pushed the symfilter_refactor branch from 2ed47de to ab77f0b Compare November 10, 2026 09:41
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.

3 participants