Skip to content

[WIP] Direct current deposition: constant-memory shape factors#6705

Open
RemiLehe wants to merge 1 commit intoBLAST-WarpX:developmentfrom
RemiLehe:table-driven-shape-factors
Open

[WIP] Direct current deposition: constant-memory shape factors#6705
RemiLehe wants to merge 1 commit intoBLAST-WarpX:developmentfrom
RemiLehe:table-driven-shape-factors

Conversation

@RemiLehe
Copy link
Copy Markdown
Member

@RemiLehe RemiLehe commented Mar 24, 2026

Summary

  • Replace compile-time if constexpr shape factor evaluation in the direct current deposition kernel (doDepositionShapeNKernel) with a table-driven Horner's method approach
  • Pre-computed polynomial coefficients are stored in GPU constant memory (for CUDA), reducing register pressure and enabling fast lookups
  • Shape factors are computed on-the-fly in the deposition loops, eliminating all intermediate shape factor arrays
  • Inspired by Hi-PACE++ PR #1328, which reported ~7.5% overall speedup
  • Only the direct current deposition is modified; Esirkepov, Villasenor, Vay, and shared-memory deposition are unchanged for now
  • Supports all existing interpolation orders (0–4) and all geometries (1D, 2D, 3D, RZ, RCylinder, RSphere)

Test plan

  • Compiles on CPU
  • test_3d_langmuir_multi_nodal passes (run + analysis + checksum), confirming numerical equivalence with the original implementation
  • GPU compilation and performance benchmarks (to be done separately)

🤖 Generated with Claude Code

…ethod

Use pre-computed polynomial coefficients stored in GPU constant memory
(for CUDA) instead of evaluating shape factor formulas with if-constexpr
branches. Shape factors are now computed on-the-fly in the deposition
loops via Horner's method, eliminating all intermediate shape factor
arrays. This reduces register pressure on GPU and enables faster access
through constant memory. Inspired by Hi-PACE++ PR BLAST-WarpX#1328.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@RemiLehe RemiLehe changed the title Direct current deposition: table-driven shape factors with Horner's method [WIP] Direct current deposition: constant-memory shape factors Mar 24, 2026
@RemiLehe
Copy link
Copy Markdown
Member Author

RemiLehe commented Mar 25, 2026

Tests on Perlmutter's A100 did not seem to give a speedup.

Here are the timings for WarpXParticleContainer::DepositCurrent::CurrentDeposition:

  2D (128×128, 4×4 ppc)

  ┌───────┬───────────┬───────────┬──────────┬──────────┬────────────────────┐
  │ Shape │ Dev run 1 │ Dev run 2 │ PR run 1 │ PR run 2 │ Avg ratio (PR/Dev) │
  ├───────┼───────────┼───────────┼──────────┼──────────┼────────────────────┤
  │ 1     │ 0.01040   │ 0.01106   │ 0.01189  │ 0.01050  │ ~1.00×             │
  ├───────┼───────────┼───────────┼──────────┼──────────┼────────────────────┤
  │ 2     │ 0.01211   │ 0.01257   │ 0.01187  │ 0.01312  │ ~1.03×             │
  ├───────┼───────────┼───────────┼──────────┼──────────┼────────────────────┤
  │ 3     │ 0.01440   │ 0.01416   │ 0.01474  │ 0.01399  │ ~1.00×             │
  └───────┴───────────┴───────────┴──────────┴──────────┴────────────────────┘

  3D (64×64×64, 4×4×4 ppc)

  ┌───────┬───────────┬───────────┬──────────┬──────────┬────────────────────┐
  │ Shape │ Dev run 1 │ Dev run 2 │ PR run 1 │ PR run 2 │ Avg ratio (PR/Dev) │
  ├───────┼───────────┼───────────┼──────────┼──────────┼────────────────────┤
  │ 1     │ 0.2534    │ 0.2299    │ 0.2636   │ 0.2414   │ 1.05× slower       │
  ├───────┼───────────┼───────────┼──────────┼──────────┼────────────────────┤
  │ 2     │ 0.7735    │ 0.7748    │ 0.9190   │ 0.9176   │ 1.19× slower       │
  ├───────┼───────────┼───────────┼──────────┼──────────┼────────────────────┤
  │ 3     │ 1.9930    │ 1.9930    │ 2.0110   │ 2.0080   │ 1.01×.               │
  └───────┴───────────┴───────────┴──────────┴──────────┴────────────────────┘

inputs_base_3d.txt
inputs_base_2d.txt

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