mem_log_device_actuals Subroutine

public subroutine mem_log_device_actuals(label)

Log actual device memory after enter_data: the device-wide usage (used = total - free — includes the CUDA context and any other process on a shared device) plus the MEASURED state mapping delta (free-before-mapping minus free-now; accurate to NVHPC pool granularity, ~a few MB). Latches the post-mapping usage as the baseline for mem_log_device_growth. Silent no-op when device queries are unavailable (CPU build).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: label

Calls

proc~~mem_log_device_actuals~~CallsGraph proc~mem_log_device_actuals mem_log_device_actuals info info proc~mem_log_device_actuals->info proc~mem_device_free_bytes mem_device_free_bytes proc~mem_log_device_actuals->proc~mem_device_free_bytes proc~mem_device_total_bytes mem_device_total_bytes proc~mem_log_device_actuals->proc~mem_device_total_bytes proc~mem_format_bytes mem_format_bytes proc~mem_log_device_actuals->proc~mem_format_bytes warning warning proc~mem_log_device_actuals->warning proc~two_dp two_dp proc~mem_format_bytes->proc~two_dp

Called by

proc~~mem_log_device_actuals~~CalledByGraph proc~mem_log_device_actuals mem_log_device_actuals proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~mem_log_device_actuals proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean

Variables

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

Source Code

   subroutine mem_log_device_actuals(label)
      !! Log actual device memory after `enter_data`: the device-wide
      !! usage (`used = total - free` — includes the CUDA context and
      !! any other process on a shared device) plus the MEASURED state
      !! mapping delta (free-before-mapping minus free-now; accurate to
      !! NVHPC pool granularity, ~a few MB).  Latches the post-mapping
      !! usage as the baseline for `mem_log_device_growth`.  Silent
      !! no-op when device queries are unavailable (CPU build).
      character(len=*), intent(in) :: label
      integer(int64) :: free_b, total_b, used_b

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

      used_b = total_b - free_b
      call logger%info("device memory in use: "//mem_format_bytes(used_b)// &
                       " of "//mem_format_bytes(total_b)//" ("//trim(label)// &
                       "; includes CUDA context ~300-500 MB + other processes)")
      if (free_before_map >= 0_int64) then
         block
            integer(int64) :: mapped_b, tol_b
            mapped_b = max(free_before_map - free_b, 0_int64)
            call logger%info("  state mapped: ~"//mem_format_bytes(mapped_b)// &
                             " (device-measured; shared-device activity can perturb)")

            ! Reconcile the MEASURED mapping against the COUNTED footprint.
            ! Overshoot past the tolerance means the device mapped more than
            ! every bytes() term accounts for — a state array is almost
            ! certainly missing from the count (the drift the counted total
            ! would otherwise hide).  Under-count from lazy/host-only arrays
            ! is expected and stays silent.
            if (counted_state_bytes > 0_int64) then
               tol_b = counted_state_bytes + &
                       int(COUNT_RECONCILE_FRAC*real(counted_state_bytes, wp), int64) + &
                       COUNT_RECONCILE_FLOOR
               if (mapped_b > tol_b) then
                  call logger%warning("device mapped ~"//mem_format_bytes(mapped_b)// &
                                      " but only ~"//mem_format_bytes(counted_state_bytes)// &
                                      " counted — a state array is likely missing from a "// &
                                      "bytes() term (memory-accounting drift)")
               end if
            end if
         end block
      end if

      ! Baselines for post-setup growth reporting.
      used_after_map = used_b
      used_steady = -1_int64
      growth_warned = .false.
   end subroutine mem_log_device_actuals