Skip to content

Host/Device Constexpr Warning in Vector Reduction Identities #513

Description

@aaadelmann

Avoid CUDA Host/Device Constexpr Warning in Vector Reduction Identities

Problem

When building IPPL with CUDA on GH200, BareField tests emit warning #20013-D from the Kokkos::reduction_identity<ippl::Vector<T, Dim>> specialization in src/Field/BareField.hpp.

The warning is triggered by calling std::numeric_limits<T>::infinity() inside KOKKOS_FORCEINLINE_FUNCTION methods:

KOKKOS_FORCEINLINE_FUNCTION static ippl::Vector<T, Dim> min() {
    return ippl::Vector<T, Dim>(std::numeric_limits<T>::infinity());
}

KOKKOS_FORCEINLINE_FUNCTION static ippl::Vector<T, Dim> max() {
    return ippl::Vector<T, Dim>(-std::numeric_limits<T>::infinity());
}

NVCC diagnoses this because std::numeric_limits<T>::infinity() is treated as a constexpr host function being called from a host-device function.

We should avoid requiring the compiler workaround:

--expt-relaxed-constexpr

Proposed Fix

Delegate the scalar identity values back to Kokkos:

KOKKOS_FORCEINLINE_FUNCTION static ippl::Vector<T, Dim> min() {
    return ippl::Vector<T, Dim>(Kokkos::reduction_identity<T>::min());
}

KOKKOS_FORCEINLINE_FUNCTION static ippl::Vector<T, Dim> max() {
    return ippl::Vector<T, Dim>(Kokkos::reduction_identity<T>::max());
}

This matches Kokkos reduction semantics and keeps vector field reductions consistent with scalar field reductions. For float and double, Kokkos uses finite extrema (FLT_MAX, DBL_MAX) rather than infinities, which avoids the CUDA host/device constexpr warning.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions