Skip to content

Commit

Permalink
Merge branch 'main' into update-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
MTCam authored Apr 18, 2023
2 parents 5e3c7e1 + f6b8924 commit d58a60a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions mirgecom/logging_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,6 @@ def __init__(self, name: Optional[str] = None) -> None:
super().__init__(name, "MByte", description="Memory usage (GPU)")

import ctypes
self.free = ctypes.c_size_t()
self.total = ctypes.c_size_t()

try:
# See https://gist.github.com/f0k/63a664160d016a491b2cbea15913d549#gistcomment-3654335 # noqa
Expand All @@ -421,14 +419,23 @@ def __call__(self) -> Optional[float]:
return None

import ctypes
ret = self.mem_func(ctypes.byref(self.free), ctypes.byref(self.total))
free = ctypes.c_size_t()
total = ctypes.c_size_t()
ret = self.mem_func(ctypes.byref(free), ctypes.byref(total))

if ret != 0:
from warnings import warn
warn(f"cudaMemGetInfo failed with error {ret}.")
return None
else:
return (self.total.value - self.free.value) / 1024 / 1024
if free.value / total.value < 0.1:
from warnings import warn
warn(
"The memory usage on the GPU is approaching the memory "
f"size, with less than 10% free of "
f"{total.value // 1024 // 1024} MByte total. "
"This may lead to slowdowns or crashes.")
return (total.value - free.value) / 1024 / 1024


class MempoolMemoryUsage(MultiPostLogQuantity):
Expand Down

0 comments on commit d58a60a

Please sign in to comment.