KOKKOS: remove silent fp32/fp64 conversions package-wide - #49
Closed
stanmoore1 wants to merge 1 commit into
Closed
Conversation
stanmoore1
force-pushed
the
claude/lammps-kokkos-warnings-mrmmdp
branch
2 times, most recently
from
August 24, 2026 15:12
8cbed5f to
a076359
Compare
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
force-pushed
the
claude/lammps-kokkos-warnings-mrmmdp
branch
from
August 24, 2026 15:26
a076359 to
708e1db
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 undersrc/KOKKOS/are touched. Both the single- and mixed-precision builds now compile with zero-Wimplicit-float-conversionand-Wdouble-promotionwarnings, 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 — usingKokkos::math overloads,KK_ACC_FLOATfor accumulators versusKK_FLOATelsewhere, and the_kklocal-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:
KK_FLOAT(sqrt,pow,exp,log,sin,cos,erfc,fabs, ...) resolve to the double overload and promote. These are qualified withKokkos::so the float overload is used. NoteKokkos::pow(x, 2)with an integer exponent still promotes, so such exponents are cast toKK_FLOAT.1.0,0.5,MY_PIS,EWALD_P,A1–A5,MY_EPSILON, ...) mixed intoKK_FLOATmath are wrapped in astatic_casttoKK_FLOAT, which folds at compile time.doublescalar members used inside device kernels get a single local copy near the top of the function, following the existing_kksuffix convention.EV_FLOATfields, per-atomd_eatom/d_vatom, atomic force and torque views — are cast toKK_ACC_FLOAT; everything else usesKK_FLOAT. The direction was decided per site from the destination view type (t_kkacc_*versust_kkfloat_*). This distinction only has an effect in the mixed build, which is why that configuration was built and cleaned separately.doublemembers (eng_vdwl,eng_coul,virial[]) are cast todouble.Two changes go slightly beyond adding a cast:
pair_table_kokkos:compute_fpair,compute_evdwlandcompute_ecoulnow take and returnKK_FLOATlike every other pair style, instead ofdouble. 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 sharedPairComputeFunctorinpair_kokkos.hand forcedrsqto promote there for every style. TheSTACKPARAMScutoff comparison inpair_kokkos.his now wrapped in astatic_casttoKK_FLOAT, which is a no-op for the styles whosecutsqis alreadyKK_FLOAT.pair_tip4p_kokkos.h: inapply_site_force()the O-branch per-pair force componentsfOx/fHxare declaredKK_FLOATrather thanKK_ACC_FLOAT, matchingfdxin the same function and the sibling non-O branch directly above. This forms the virial products inKK_FLOATand 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:
make check-whitespaceandmake check-permissionspass.examples/melt,examples/micelle,examples/crackandexamples/meamrun correctly with-sf kkin both configurations. Forin.meam.shearthe KOKKOS single-precision run tracks the double-precision CPU run to the expected single-precision tolerance.Post Submission Checklist
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.