mem_log_state_budget Subroutine

public subroutine mem_log_state_budget(label, host_growth_bytes)

Log the pre-mapping memory budget. Always logs the host-side allocation growth (ADVISORY — includes host-only I/O buffers + library pages, NOT a device estimate); when the device queries succeed it also logs the device number + free/total and latches the free-memory snapshot that mem_log_device_actuals turns into the measured mapping delta. Warns when the host growth (a conservative upper bound on what enter_data can map) exceeds 95% of free device memory — the regime where enter_data is likely to abort.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: label
integer(kind=int64), intent(in) :: host_growth_bytes

Calls

proc~~mem_log_state_budget~~CallsGraph proc~mem_log_state_budget mem_log_state_budget info info proc~mem_log_state_budget->info proc~device_num device_num proc~mem_log_state_budget->proc~device_num proc~mem_device_free_bytes mem_device_free_bytes proc~mem_log_state_budget->proc~mem_device_free_bytes proc~mem_device_total_bytes mem_device_total_bytes proc~mem_log_state_budget->proc~mem_device_total_bytes proc~mem_format_bytes mem_format_bytes proc~mem_log_state_budget->proc~mem_format_bytes to_string to_string proc~mem_log_state_budget->to_string warning warning proc~mem_log_state_budget->warning proc~two_dp two_dp proc~mem_format_bytes->proc~two_dp

Called by

proc~~mem_log_state_budget~~CalledByGraph proc~mem_log_state_budget mem_log_state_budget proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~mem_log_state_budget proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean

Variables

Type Visibility Attributes Name Initial
integer, private :: devnum
integer(kind=int64), private :: free_b
integer(kind=int64), private :: total_b

Source Code

   subroutine mem_log_state_budget(label, host_growth_bytes)
      !! Log the pre-mapping memory budget.  Always logs the host-side
      !! allocation growth (ADVISORY — includes host-only I/O buffers +
      !! library pages, NOT a device estimate); when the device queries
      !! succeed it also logs the device number + free/total and latches
      !! the free-memory snapshot that `mem_log_device_actuals` turns
      !! into the measured mapping delta.  Warns when the host growth
      !! (a conservative upper bound on what `enter_data` can map)
      !! exceeds 95% of free device memory — the regime where
      !! `enter_data` is likely to abort.
      character(len=*), intent(in) :: label
      integer(int64), intent(in) :: host_growth_bytes

      integer(int64) :: free_b, total_b
      integer :: devnum

      call logger%info("Memory budget ("//trim(label)//"): host allocations across setup ~ "// &
                       mem_format_bytes(host_growth_bytes)// &
                       " (RSS growth; advisory, not a device estimate)")

      free_b = mem_device_free_bytes()
      total_b = mem_device_total_bytes()
      if (free_b < 0_int64 .or. total_b < 0_int64) return  ! CPU build.

      ! Baseline for the measured mapping delta.  The property query
      ! above already forced CUDA context creation, so the delta across
      ! enter_data excludes the ~300-500 MB context cost.
      free_before_map = free_b

      devnum = device_num()
      call logger%info("  device "//to_string(devnum)//" free before mapping: "// &
                       mem_format_bytes(free_b)//" of "//mem_format_bytes(total_b)// &
                       " (host-growth upper bound: "// &
                       mem_format_bytes(host_growth_bytes)//")")

      if (real(host_growth_bytes, wp) > 0.95_wp*real(free_b, wp)) then
         call logger%warning("device memory likely insufficient — mapping <= "// &
                             mem_format_bytes(host_growth_bytes)//" with only "// &
                             mem_format_bytes(free_b)//" free")
      end if
   end subroutine mem_log_state_budget