host_data use_device with enter data/exit data on 15.3

I’m using 15.3 and the following code snippet

!$acc data copy(thermal_energy_updated), copy(planetary_thermal_energy), copy(surface_thermal_energy), &
!$acc& copy(thermal_energy_current)

  time = start_time
  call time_profiling_ini()
  call getTime(t_start_output_cycle)
  call getTime(t_start_output_cycle_w_io)
  do while (.true.)
   if (modulo(time + 0.001d0, output_timestep) < 0.01d0) then
   call write_data(thermal_energy_current, "thermal_energy", time)
   end if
   call run_physics(thermal_energy_current, surface_thermal_energy, planetary_thermal_energy)
   if (use_c) then



!$acc host_data use_device(thermal_energy_current,thermal_energy_updated)
   call diffuse_c(thermal_energy_updated, thermal_energy_current, nx, ny, nz)
!$acc end host_data



   else
   call diffuse (thermal_energy_updated, thermal_energy_current)
   end if
   thermal_energy_temp => thermal_energy_updated
   thermal_energy_updated => thermal_energy_current
   thermal_energy_current => thermal_energy_temp
   time = time + timestep
  end do
!$acc end data

compiles fine, but the same one with enter/exit data does not:

!$acc enter data copyin(thermal_energy_updated), copyin(planetary_thermal_energy), copyin(surface_thermal_energy), &
!$acc& copyin(thermal_energy_current)

  time = start_time
  call time_profiling_ini()
  call getTime(t_start_output_cycle)
  call getTime(t_start_output_cycle_w_io)
  do while (.true.)
   if (modulo(time + 0.001d0, output_timestep) < 0.01d0) then
   call write_data(thermal_energy_current, "thermal_energy", time)
   end if
   call run_physics(thermal_energy_current, surface_thermal_energy, planetary_thermal_energy)
   if (use_c) then
!$acc host_data use_device(thermal_energy_current,thermal_energy_updated)
   call diffuse_c(thermal_energy_updated, thermal_energy_current, nx, ny, nz)
!$acc end host_data
   else
   call diffuse (thermal_energy_updated, thermal_energy_current)
   end if
   thermal_energy_temp => thermal_energy_updated
   thermal_energy_updated => thermal_energy_current
   thermal_energy_current => thermal_energy_temp
   time = time + timestep
   if (time > end_time) then
!$acc exit data copyout(thermal_energy_updated), copyout(planetary_thermal_energy), copyout(surface_thermal_energy), &
!$acc& copyout(thermal_energy_current)
   return
   end if
  end do
!$acc exit data copyout(thermal_energy_updated), copyout(planetary_thermal_energy), copyout(surface_thermal_energy), &
!$acc& copyout(thermal_energy_current)

Compiler output:

pgf90 -Mcuda=cc3x -fast -ta=nvidia,cc3x -Minfo=accel,inline,ipa -Mneginfo -DGPU -c simple_weather.f90 -o simple_weather.o
PGF90-S-0528-Argument number 1 to diffuse_c: device attribute mismatch (simple_weather.f90: 97)
PGF90-S-0528-Argument number 2 to diffuse_c: device attribute mismatch (simple_weather.f90: 97)
  0 inform,   0 warnings,   2 severes, 0 fatal for simulate

Am I guessing correctly that this was fixed somewhere in between 15.3 and 15.7? At least I’ve seen that working on 15.7 with pgc++ at the Lugano Hackathon.

There were a couple of fixes to host_data that went into PGI 15.4. This case likely falls into one of those.

I was just able to test on Linux PGI 15.7 - the compiler error is still there. I’ve checked again how it worked in our hackathon C++ project: https://github.com/daverio/LATfield2_openACC/blob/master/LATfield2_PlanFFT_ACC.hpp. Then I saw the problem: It requires an “$acc data present” region around the host_data region. A bit clunky I have to say - ideally I think it should work with unstructured data regions as well, no?

I’ve been trying to recreate small reproducers for your problem and the hackathon issue and having trouble on both accounts. Can you generate a small reproducer?