Skip to content

Commit b40e5b5

Browse files
committed
Fixed memory reporting to MB.
1 parent 14e8894 commit b40e5b5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

scalene/scalene_apple_gpu.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _read_apple_gpu_stats_and_cores() -> Tuple[float, float, int]:
9494
(device_util, in_use_mem, gpu_core_count)
9595
where:
9696
- device_util is a fraction [0..1].
97-
- in_use_mem is in bytes.
97+
- in_use_mem is in megabytes.
9898
- gpu_core_count is an integer from top-level "gpu-core-count".
9999
"""
100100
matching_dict = IOServiceMatching(b"IOAccelerator")
@@ -156,7 +156,7 @@ def _read_apple_gpu_stats_and_cores() -> Tuple[float, float, int]:
156156
val_container_64 = ctypes.c_longlong(0)
157157
success = CFNumberGetValue(mem_val_ref, kCFNumberSInt64Type, ctypes.byref(val_container_64))
158158
if success:
159-
in_use_mem = float(val_container_64.value)
159+
in_use_mem = float(val_container_64.value) / 1048576.0
160160

161161
IOObjectRelease(cf_key_util)
162162
IOObjectRelease(cf_key_mem)
@@ -196,7 +196,7 @@ def get_num_cores(self) -> int:
196196
return self.core_count
197197

198198
def get_stats(self) -> Tuple[float, float]:
199-
"""Returns a tuple of (utilization%, memory in use in bytes)."""
199+
"""Returns a tuple of (utilization%, memory in use in megabytes)."""
200200
if not self.has_gpu():
201201
return (0.0, 0.0)
202202
try:
@@ -221,7 +221,7 @@ def _get_num_cores(self) -> int:
221221
cores = gpu.get_num_cores()
222222
print(
223223
f"GPU Utilization: {util*100:.1f}%, "
224-
f"In-Use GPU Memory: {mem} bytes, "
224+
f"In-Use GPU Memory: {mem} megabytes, "
225225
f"GPU Core Count: {cores}"
226226
)
227227
time.sleep(2)

0 commit comments

Comments
 (0)