Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offload functions with optional attribute and other offloaded function calls #2852

Open
sergisiso opened this issue Jan 15, 2025 · 1 comment

Comments

@sergisiso
Copy link
Collaborator

sergisiso commented Jan 15, 2025

In NEMO we need to bring to the GPU the functions like:

  elemental function q_sat_sclr(pta, ppa, l_ice)
    real(kind=wp), intent(in) :: pta
    real(kind=wp), intent(in) :: ppa
    LOGICAL, INTENT(IN), OPTIONAL :: l_ice
    real(kind=wp) :: q_sat_sclr
    real(kind=wp) :: ze_s
    logical :: lice

    lice = .false.
    if (PRESENT(l_ice)) then
      lice = l_ice
    end if
    if (lice) then
      ze_s = e_sat_ice(pta)
    else
      ze_s = e_sat(pta)
    end if
    q_sat_sclr = reps0 * ze_s / (ppa - (1._wp - reps0) * ze_s)

  end function q_sat_sclr

(from sbc_phy.f90)

We typically do this with "declare target" or "inline" but we can not do that for this case because of the OPTIONAL attribute.
For inlining there is #2801. But for declare target we could also create a copy of the function with the attribute being mandatory.

Another problem is that it is not transitive, so:

  elemental function dq_sat_dt_ice_sclr(pta, ppa)
    real(kind=wp), intent(in) :: pta
    real(kind=wp), intent(in) :: ppa
    real(kind=wp) :: dq_sat_dt_ice_sclr
    real(kind=wp) :: ze_s
    real(kind=wp) :: zde_s_dt
    real(kind=wp) :: ztmp
    ze_s = e_sat_ice_sclr(pta)
    zde_s_dt = de_sat_dt_ice(pta)
    ztmp = (reps0 - 1._wp) * ze_s + ppa
    dq_sat_dt_ice_sclr = reps0 * ppa * zde_s_dt / (ztmp * ztmp)

  end function dq_sat_dt_ice_sclr

Is not on the GPU because it calls 'e_sat_ice_sclr' and 'de_sat_dt_ice', but this could be "declare target" in turn.

@sergisiso sergisiso changed the title Offload functions Offload functions with optional attribute and other offloaded function calls Jan 15, 2025
@arporter
Copy link
Member

Martin has a PR ready for review that adds support for optional arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants