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).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | label |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=int64), | private | :: | free_b | ||||
| integer(kind=int64), | private | :: | total_b | ||||
| integer(kind=int64), | private | :: | used_b |
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