Skip to content

Pr501 hosg final#569

Open
aaadelmann wants to merge 6 commits into
masterfrom
pr501-hosg-final
Open

Pr501 hosg final#569
aaadelmann wants to merge 6 commits into
masterfrom
pr501-hosg-final

Conversation

@aaadelmann

Copy link
Copy Markdown
Member

Summary

This PR extracts the higher-order scatter/gather and autotuning part of the original PR #501 into a finite, reviewable branch.

It adds a new interpolation framework for particle-to-grid scatter and grid-to-particle gather, including:

  • runtime-selectable scatter/gather frontends
  • NGP, linear/CIC, quadratic, cubic, and quartic interpolation kernels
  • particle binning support for sorted interpolation paths
  • atomic, tiled, and output-focused scatter implementations
  • atomic gather and sorted gather support
  • runtime scatter/gather configuration objects
  • tile-size cache and autotune preset plumbing
  • built-in autotune preset loading at ippl::initialize()
  • regression tests for binning and higher-order gather/scatter behavior

User-Facing API

The new API is based on explicit kernel and config objects.

Example scatter:

using T = double;
constexpr unsigned Dim = 3;

ippl::Interpolation::LinearKernel<T> kernel;

ippl::Interpolation::ScatterConfig<Dim> cfg;
cfg.method = ippl::Interpolation::ScatterMethod::Atomic;
cfg.sort = true;

auto scatter = ippl::Scatter<decltype(kernel), Dim>(kernel, cfg);
scatter(field, bunch.R, bunch.Q);

Example gather:

ippl::Interpolation::LinearKernel<T> kernel;

ippl::Interpolation::GatherConfig<Dim> cfg;
cfg.method = ippl::Interpolation::GatherMethod::Atomic;

auto gather = ippl::Gather<decltype(kernel), Dim>(kernel, cfg);
gather(field, bunch.R, bunch.E);

Available kernels include:

ippl::Interpolation::NGPKernel<T>
ippl::Interpolation::LinearKernel<T>
ippl::Interpolation::QuadraticKernel<T>
ippl::Interpolation::CubicKernel<T>
ippl::Interpolation::QuarticKernel<T>

Autotuning

The PR adds CMake support for bundled autotune preset CSV files. These are configured into a generated IpplAutoTunePresets.h header and seeded during ippl::initialize().

At runtime, ippl::Interpolation::AutoTune::initialize() seeds scatter/gather defaults and can run autotuning sweeps when requested through the existing environment mechanism.

Regression Tests

Added:

  • unit_tests/Interpolation/Binning.cpp
  • unit_tests/Interpolation/KernelGatherScatterTest.cpp

The tests cover:

  • bin permutation validity
  • bin-offset consistency
  • sorted particle grouping
  • empty and single-particle binning cases
  • scatter conservation
  • gather from constant fields
  • periodic boundary behavior
  • convergence for NGP, linear, quadratic, and cubic kernels
  • complex scatter/gather adjointness
  • sorted versus unsorted scatter consistency
  • scatter/gather roundtrip behavior

Supporting Changes

BareField::innerProduct now handles complex-valued fields using Hermitian convention:

f1 * conj(f2)

for Kokkos::complex<T>, while preserving the existing real-valued behavior.

This is required for the complex adjointness checks in the new scatter/gather regression tests.

A small VectorTraits<Vector<T, Dim>> helper was added to expose:

real_type = T
dim       = Dim

for generic interpolation code.

Commits

b03763d Add VectorTraits helper for vector-valued interpolation support
b451224 Add HOSG interpolation regression tests
4701b08 Update CIC helpers for Kokkos device use
5f5d11c Initialize interpolation autotune runtime state
1a77948 Add higher-order scatter/gather interpolation framework
cfbecd3 Add autotune preset plumbing for scatter/gather

Master was kept as the source of truth for newer fixes in particle communication, boundary conditions, halo handling, and current-deposition tests.

Verification

Tested locally with the OpenMP unit-test build:

cmake --build build-pr501-hosg-step1-openmp -j 8
ctest --test-dir build-pr501-hosg-step1-openmp --output-on-failure

Result:

39/39 tests passed

Add CMake support for selecting architecture-specific scatter/gather
autotune preset CSVs at configure time. The new AutoTunePresets module
detects the active backend/architecture tag, copies matching preset files
into the build tree, and generates IpplAutoTunePresets.h with the resolved
preset path and architecture label.

Add initial preset CSVs for:
- gfx90a
- sm_80
- sm_90

Wire the preset configuration into the top-level CMake flow without touching
FEL handling or the existing CUDA/HeFFTe architecture logic.

Verification:
- Configured a fresh OpenMP Release build.
- Confirmed the generated IpplAutoTunePresets.h uses the openmp tag.
- Built the ippl target successfully.
Add the core higher-order scatter/gather infrastructure used by the
interpolation autotune path:

- binning support for sorted particle traversal
- interpolation coordinate/kernel utilities
- gather dispatch/configuration types
- scatter dispatch/configuration types
- atomic, tiled, and grid-parallel scatter backends
- autotune and tile-size cache implementation
- Gaussian-process helper used by the autotune sweep

Wire the new interpolation sources into the IPPL target and add the generated
autotune preset include directory to the library target.

Add two small support hooks required by the new framework:
- FieldTraits for deducing Field dimension/view type
- a per-bin cursor buffer in SortBuffer for counting-sort binning

Verification:
- Configured OpenMP Release build with unit tests and FFT enabled.
- Built the full unit-test tree successfully.
- Ran ctest: 37/37 tests passed.
Initialize the scatter/gather autotune cache after Kokkos startup so the
runtime can seed backend defaults, load configured preset CSVs, or run the
autotune sweep when requested through IPPL_AUTO_TUNE.

Also release the shared bin-sort buffers before Kokkos finalization. The
higher-order scatter/gather path keeps reusable binning buffers by memory
space, so they need to be cleared while Kokkos memory spaces are still valid.

Verification:
- Built the OpenMP Release tree with unit tests enabled.
- Ran ctest: 37/37 tests passed.
Add an explicit Kokkos_Core include to the CIC implementation header and
remove unreachable fallback returns from the constexpr interpolation helper
functions.

The fallback returns were only present to silence earlier device-code
warnings, but all branches are now covered by the compile-time conditions.
Keeping the helpers branch-clean matches the HOSG interpolation code path
being merged from PR 501.

Verification:
- cmake --build build-pr501-hosg-step1-openmp -j 8
- ctest --test-dir build-pr501-hosg-step1-openmp --output-on-failure
  - 37/37 tests passed
Add the HOSG interpolation unit tests from PR 501 and register them in the
interpolation test suite.

The new tests cover:
- particle binning and bin-offset consistency
- gather/scatter conservation
- periodic-boundary behavior
- constant-field gather
- gather/scatter convergence for NGP, linear, quadratic, and cubic kernels
- scatter/gather adjointness
- high-density particle cases
- sorted versus unsorted scatter consistency
- scatter/gather roundtrip behavior

Also update BareField::innerProduct for complex-valued fields. The HOSG
adjointness tests use complex fields and particle attributes, and require the
field inner product to use the same Hermitian convention as the particle-side
test helper. For real-valued fields the existing bilinear behavior is unchanged.
For complex-valued fields, the reduction now accumulates f1 * conj(f2) and
reduces real and imaginary parts separately across MPI ranks.

Without the complex inner-product update, KernelGatherScatterTest compiles but
all complex adjointness checks fail for every tested kernel and dimension.

Verification:
- cmake --build build-pr501-hosg-step1-openmp -j 8
- ctest --test-dir build-pr501-hosg-step1-openmp -R KernelGatherScatterTest --output-on-failure
  - passed
- ctest --test-dir build-pr501-hosg-step1-openmp --output-on-failure
  - 39/39 tests passed
Add ippl::detail::VectorTraits<Vector<T, Dim>> as a lightweight compile-time
helper that exposes the scalar type and dimension of an IPPL Vector.

For example:

  VectorTraits<Vector<double, 3>>::real_type == double
  VectorTraits<Vector<double, 3>>::dim       == 3

This is useful for generic interpolation code that receives only a vector type
and needs to recover its component scalar type and dimensionality without
duplicating partial-specialization logic at each call site.

The helper has no runtime cost and does not change Vector behavior. It is a
supporting type-trait for the higher-order scatter/gather work, especially for
future vector-valued field and particle interpolation paths.

Add some documentation

Verification:
- cmake --build build-pr501-hosg-step1-openmp -j 8
- ctest --test-dir build-pr501-hosg-step1-openmp --output-on-failure
  - 39/39 tests passed
@aaadelmann
aaadelmann requested a review from srikrrish July 17, 2026 13:01
@aaadelmann aaadelmann self-assigned this Jul 17, 2026
@aaadelmann aaadelmann added documentation Improvements or additions to documentation enhancement New feature or request add/modify doc Used to label issues that need modifications to the documentation (manual or wiki) cleanup labels Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add/modify doc Used to label issues that need modifications to the documentation (manual or wiki) cleanup documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants