Skip to content

cray_inline/cray_noinline in GPU_ROUTINE never emit their !DIR$ directive on Cray GPU builds #1682

Description

@sbryngelson

Summary

GPU_ROUTINE(..., cray_inline=True) and GPU_ROUTINE(..., cray_noinline=True) never emit their !DIR$ directive on a Cray GPU build. The directives are emitted only on Cray CPU builds, where a device-inlining hint has no purpose. Every current use of these options is in device code, so in practice both options are no-ops.

Where

src/common/include/parallel_macros.fpp:66-100. The cray_noinline branch expands to:

#ifdef _CRAYFTN
#if MFC_OpenACC
        $:acc_directive              ! acc routine only
#elif MFC_OpenMP
        $:omp_directive              ! omp declare target only
#else
        $:cray_noinline_directive    ! !DIR$ NOINLINE -- Cray CPU only
#endif
#elif MFC_OpenACC
        $:acc_directive
#elif MFC_OpenMP
        $:omp_directive
#endif

Under _CRAYFTN, the !DIR$ line sits in the #else arm, so it is selected only when neither MFC_OpenACC nor MFC_OpenMP is defined. The cray_inline branch immediately below has the same shape and the same problem.

Reproduction

$ printf "#:include 'parallel_macros.fpp'\nsubroutine s_t\n    \$:GPU_ROUTINE(function_name='s_t', parallelism='[seq]', cray_noinline=True)\nend subroutine\n" > /tmp/mt.fpp
$ ./build/venv/bin/fypp -I src/common/include -DMFC_COMPILER='"Cray"' -DMFC_CASE_OPTIMIZATION=False /tmp/mt.fpp
subroutine s_t

#ifdef _CRAYFTN
#if MFC_OpenACC
!$acc routine seq
#elif MFC_OpenMP
!$omp declare target device_type(any)
#else
!DIR$ NOINLINE s_t
#endif
#elif MFC_OpenACC
!$acc routine seq
#elif MFC_OpenMP

Substituting cray_inline=True produces the same structure with !DIR$ INLINEALWAYS s_t in the same unreachable arm.

Impact

  • 8 call sites use cray_noinline=True, 43 use cray_inline=True, across m_variables_conversion, m_boundary_primitives, m_riemann_state, m_qbmm, m_bubbles, m_bubbles_EL, m_bubbles_EL_kernels, m_compute_cbc, m_chemistry, m_phase_change, and m_sim_helpers.
  • All of them are device routines, so on Cray GPU builds the inlining behaviour is whatever the compiler's heuristics choose. Whatever these options were added to guarantee is not in effect there.
  • If any of them was added to work around a Cray codegen issue, that workaround has been silently inactive on Cray GPU builds.

Both !DIR$ INLINEALWAYS and !DIR$ NOINLINE are accepted by Cray ftn alongside !$acc routine / !$omp declare target, so the fix should be to emit the !DIR$ line in addition to the offload directive rather than as an alternative to it:

#ifdef _CRAYFTN
        $:cray_noinline_directive
#if MFC_OpenACC
        $:acc_directive
#elif MFC_OpenMP
        $:omp_directive
#endif
#elif MFC_OpenACC
...

Worth confirming the directive ordering Cray expects relative to !$acc routine before settling on a form.

Notes

Pre-existing; parallel_macros.fpp is unchanged on the current master and by any open PR. Found while investigating a Cray-only NaN regression on Frontier in #1679, where the inlining status of s_convert_species_to_mixture_variables_kernel (declared cray_noinline=True) mattered to the diagnosis. Whether the two are related is not established — filing separately because the macro defect stands on its own.

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