Skip to content

Commit c0991fd

Browse files
committed
reset _marker to allow many benchmarked function calls in one script not interfering
1 parent 21eec69 commit c0991fd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pylops_mpi/utils/benchmark.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
cupy_message = deps.cupy_import("benchmark module")
99
if cupy_message is None:
1010
import cupy as cp
11-
has_cupy = True
11+
if cp.cuda.runtime.getDeviceCount() == 0:
12+
has_cupy = False
13+
print(UserWarning("CuPy is installed, but no CUDA-capable device is available."))
14+
else:
15+
has_cupy = True
1216
else:
1317
has_cupy = False
1418

@@ -31,6 +35,7 @@ def _parse_output_tree(markers: List[str]):
3135
markers: :obj:`list`, optional
3236
A list of markers/labels generated from the benchmark call
3337
"""
38+
global _markers
3439
output = []
3540
stack = []
3641
i = 0
@@ -53,13 +58,14 @@ def _parse_output_tree(markers: List[str]):
5358
if next_level >= level:
5459
stack.append(markers[i])
5560
i += 1
61+
# reset markers, allowing other benchmarked function to start fresh
62+
_markers = []
5663
return output
5764

5865

5966
def _sync():
6067
"""Synchronize all MPI processes or CUDA Devices"""
6168
if has_cupy:
62-
cp.cuda.get_current_stream().synchronize()
6369
# this is ok to call even if CUDA runtime is not initialized
6470
cp.cuda.runtime.deviceSynchronize()
6571

0 commit comments

Comments
 (0)