Skip to content

KOKKOS: remove silent fp32/fp64 conversions package-wide - #49

Closed
stanmoore1 wants to merge 1 commit into
developfrom
claude/lammps-kokkos-warnings-mrmmdp
Closed

KOKKOS: remove silent fp32/fp64 conversions package-wide#49
stanmoore1 wants to merge 1 commit into
developfrom
claude/lammps-kokkos-warnings-mrmmdp

Conversation

@stanmoore1

@stanmoore1 stanmoore1 commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Summary

Removes silent fp32/fp64 conversions throughout the KOKKOS package, continuing the work started in lammps#4754 and extending it to the full set of packages that provide KOKKOS styles.

The conversions were found by compiling with clang and -Wall -Wextra -Wimplicit-float-conversion -Wdouble-promotion -pedantic, then making every flagged conversion explicit. 227 files under src/KOKKOS/ are touched. Both the single- and mixed-precision builds now compile with zero -Wimplicit-float-conversion and -Wdouble-promotion warnings, where previously there were roughly 13,700 (single) and 2,950 (mixed) unique flagged locations.

All changes are casts and local-copy declarations only. No algorithm or control flow is changed, and every cast is a no-op in the default double-precision build.

Related Issue(s)

Follow-up to lammps#4754, applying the same technique to the remaining KOKKOS styles.

Author(s)

Stan Moore (SNL)

Licensing

By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).

Artificial Intelligence (AI) Tools Usage

AI tools were used for this pull request. Claude Code (Anthropic) performed the compiler-warning triage and applied the resulting casts across src/KOKKOS/, working from a fixed set of rules and verifying every file against the compiler. The conventions the changes follow — using Kokkos:: math overloads, KK_ACC_FLOAT for accumulators versus KK_FLOAT elsewhere, and the _kk local-copy idiom — were specified by a human, as was the decision on the TIP4P virial noted under Implementation Notes. The changes are mechanical and repetitive by nature; each file was verified by compiling it in both the single- and mixed-precision configurations and confirming zero warnings and zero errors, and human review of the resulting diff is expected.

Backward Compatibility

Yes, backward compatible. No input scripts, commands, keywords, or file formats are affected. In the default double-precision build (KOKKOS_PREC=double) every added cast is a no-op, so results are bitwise unchanged.

Implementation Notes

The changes fall into a small number of repeated patterns:

  1. Bare libm math calls on KK_FLOAT (sqrt, pow, exp, log, sin, cos, erfc, fabs, ...) resolve to the double overload and promote. These are qualified with Kokkos:: so the float overload is used. Note Kokkos::pow(x, 2) with an integer exponent still promotes, so such exponents are cast to KK_FLOAT.
  2. Double literals and constants (1.0, 0.5, MY_PIS, EWALD_P, A1A5, MY_EPSILON, ...) mixed into KK_FLOAT math are wrapped in a static_cast to KK_FLOAT, which folds at compile time.
  3. Base-class double scalar members used inside device kernels get a single local copy near the top of the function, following the existing _kk suffix convention.
  4. Values reaching an accumulator — EV_FLOAT fields, per-atom d_eatom/d_vatom, atomic force and torque views — are cast to KK_ACC_FLOAT; everything else uses KK_FLOAT. The direction was decided per site from the destination view type (t_kkacc_* versus t_kkfloat_*). This distinction only has an effect in the mixed build, which is why that configuration was built and cleaned separately.
  5. Host-side reductions into the base-class double members (eng_vdwl, eng_coul, virial[]) are cast to double.

Two changes go slightly beyond adding a cast:

  • pair_table_kokkos: compute_fpair, compute_evdwl and compute_ecoul now take and return KK_FLOAT like every other pair style, instead of double. The table interpolation itself still runs in double internally via an explicit local, and the conversion happens at the return. Previously this style's double interface leaked into the shared PairComputeFunctor in pair_kokkos.h and forced rsq to promote there for every style. The STACKPARAMS cutoff comparison in pair_kokkos.h is now wrapped in a static_cast to KK_FLOAT, which is a no-op for the styles whose cutsq is already KK_FLOAT.
  • pair_tip4p_kokkos.h: in apply_site_force() the O-branch per-pair force components fOx/fHx are declared KK_FLOAT rather than KK_ACC_FLOAT, matching fdx in the same function and the sibling non-O branch directly above. This forms the virial products in KK_FLOAT and widens once at the accumulator. It is the one change that is not bit-identical: in the mixed build only, those virial products are now formed in float rather than double. Single and double builds are unaffected.

Verification:

  • Both configurations built from scratch with clang 18, Serial backend, all 27 packages that contain KOKKOS styles enabled except REAXFF, ML-IAP (double only) and ML-PACE (needs a download), using the warning flags above. Final result: 0 errors and 0 in-scope warnings in each.
  • Each file was additionally compiled on its own in both configurations during development, checking for warnings and for compile errors, since a warnings-only check will not catch a broken edit.
  • Header changes were verified through more than one including translation unit, because a header's warnings depend on which templates a given TU instantiates.
  • make check-whitespace and make check-permissions pass.
  • examples/melt, examples/micelle, examples/crack and examples/meam run correctly with -sf kk in both configurations. For in.meam.shear the KOKKOS single-precision run tracks the double-precision CPU run to the expected single-precision tolerance.

Post Submission Checklist

  • The feature or features in this pull request is complete
  • Licensing information is complete
  • Corresponding author information is complete
  • The source code follows the LAMMPS formatting guidelines
  • The feature has been verified to work with the CMake based build system

Further Information, Files, and Links

Only src/KOKKOS/ is touched; no other package, no documentation and no example inputs are affected. Since the changes are numerically inert in the default double build, the existing regression and unit tests should be unchanged by this pull request.

@stanmoore1
stanmoore1 force-pushed the claude/lammps-kokkos-warnings-mrmmdp branch 2 times, most recently from 8cbed5f to a076359 Compare August 24, 2026 15:12
Continue the fp32/fp64 cleanup started in lammps#4754 and extend it to the full set
of packages that provide KOKKOS styles. The conversions were found by building
with clang and -Wall -Wextra -Wimplicit-float-conversion -Wdouble-promotion
-pedantic in both the single- and the mixed-precision configuration, and then
making every flagged conversion explicit. Both builds are now free of
-Wimplicit-float-conversion and -Wdouble-promotion warnings.

The changes follow a few repeated patterns:

- Bare libm calls (sqrt, pow, exp, log, sin, cos, erfc, fabs, ...) on KK_FLOAT
  arguments resolve to the double overload and promote, so they are qualified
  with Kokkos:: to select the float overload. Note that Kokkos::pow() with an
  integer exponent still promotes, so those exponents are cast to KK_FLOAT.
- Double literals and constants (1.0, 0.5, MY_PIS, EWALD_P, A1-A5, MY_EPSILON
  and similar) mixed into KK_FLOAT expressions are cast to KK_FLOAT, which
  folds at compile time.
- Base-class double scalars used inside kernels are copied once into a local
  KK_FLOAT, using the existing _kk suffix convention.
- Values that accumulate into EV_FLOAT fields, the per-atom eatom/vatom views
  or the atomic force and torque views are cast to KK_ACC_FLOAT, while values
  read back out of those views into float math are cast to KK_FLOAT. The
  direction was chosen per site from the declared view type. This distinction
  only matters in the mixed build, which is why it was built and cleaned as a
  separate configuration.
- Host-side reductions into the base-class double eng_vdwl, eng_coul and
  virial[] are cast to double.

Two changes go beyond adding a cast:

pair_table_kokkos compute_fpair(), compute_evdwl() and compute_ecoul() now take
and return KK_FLOAT like every other pair style instead of double. The table
interpolation still runs in double internally through an explicit local and
converts at the return. Previously this style's double interface propagated
into the shared PairComputeFunctor and forced rsq to promote there for every
style. The STACKPARAMS cutoff comparison in pair_kokkos.h is cast to KK_FLOAT
accordingly, which is a no-op for the styles whose cutsq is already KK_FLOAT.

In pair_tip4p_kokkos.h apply_site_force() the O-branch force components fOx and
fHx are declared KK_FLOAT to match fdx in the same function and the sibling
non-O branch above it, so the virial products are formed in KK_FLOAT and widened
once at the accumulator. This is the only change that is not bit-identical: in
the mixed build alone those virial products are formed in float rather than
double. The single and double builds are unaffected.

Everything else is numerically inert: in the default double build every added
cast is a no-op, so results are unchanged.
@stanmoore1
stanmoore1 force-pushed the claude/lammps-kokkos-warnings-mrmmdp branch from a076359 to 708e1db Compare August 24, 2026 15:26
@stanmoore1 stanmoore1 closed this Aug 25, 2026
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