Skip to content

Commit 6c9f759

Browse files
author
OutlyingWest
committed
display_graph_for_all moved to extension; gpu_avail moved to context
1 parent a786bd6 commit 6c9f759

3 files changed

Lines changed: 55 additions & 42 deletions

File tree

src/jumper/context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
@dataclass
77
class KernelContext:
8-
nodelist: list = None
8+
# will be set to True as soon as GPU data is received
9+
gpu_avail = False
910
perfdata_handler = PerformanceDataHandler()
1011

1112

src/jumper/kernel.py

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ def __init__(self, **kwargs):
9393
self.writefile_scorep_binding_args = []
9494
self.writefile_multicell = False
9595

96-
# will be set to True as soon as GPU data is received
97-
self.gpu_avail = False
98-
# TODO: Temporary share perfdata_handler instance with an ipython extension
99-
# as it contains data that should be shared with the extension.
10096
self.nodelist = kernel_context.perfdata_handler.get_nodelist()
10197

10298
self.scorep_available_ = shutil.which("scorep")
@@ -558,7 +554,7 @@ def report_perfdata(self, performance_data_nodes, duration):
558554
)
559555

560556
if gpu_util[0] and gpu_mem[0]:
561-
self.gpu_avail = True
557+
kernel_context.gpu_avail = True
562558
self.cell_output(
563559
"--GPU Util and Mem per GPU--\n", "stdout"
564560
)
@@ -971,39 +967,10 @@ async def do_execute(
971967
perfvis.draw_performance_graph(
972968
self.nodelist,
973969
kernel_context.perfdata_handler.get_perfdata_history()[-1],
974-
self.gpu_avail,
970+
kernel_context.gpu_avail,
975971
time_indices,
976972
)
977973
return self.standard_reply()
978-
elif code.startswith("%%display_graph_for_index"):
979-
if len(code.split(" ")) == 1:
980-
self.cell_output(
981-
"No index specified. Use: %%display_graph_for_index index",
982-
"stdout",
983-
)
984-
index = int(code.split(" ")[1])
985-
if index >= len(kernel_context.perfdata_handler.get_perfdata_history()):
986-
self.cell_output(
987-
"Tracked only "
988-
+ str(len(kernel_context.perfdata_handler.get_perfdata_history()))
989-
+ " cells. This index is not available."
990-
)
991-
else:
992-
time_indices = kernel_context.perfdata_handler.get_time_indices()[index]
993-
if time_indices:
994-
sub_idxs = [x[0] for x in time_indices[0]]
995-
self.cell_output(
996-
f"Cell seemed to be tracked in multi cell"
997-
" mode. Got performance data for the"
998-
f" following sub cells: {sub_idxs}"
999-
)
1000-
perfvis.draw_performance_graph(
1001-
self.nodelist,
1002-
kernel_context.perfdata_handler.get_perfdata_history()[index],
1003-
self.gpu_avail,
1004-
time_indices,
1005-
)
1006-
return self.standard_reply()
1007974

1008975
elif code.startswith("%%display_code_for_index"):
1009976
if len(code.split(" ")) == 1:

src/magic_extension/magic.py

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ def __init__(self, shell):
1616
super(KernelMagics, self).__init__(shell)
1717
self.mode = KernelMode.DEFAULT
1818

19-
# will be set to True as soon as GPU data is received
20-
self.gpu_avail = False
2119
self.nodelist = kernel_context.perfdata_handler.get_nodelist()
2220

2321
@cell_magic
@@ -32,13 +30,57 @@ def display_graph_for_all(self, line):
3230
perfvis.draw_performance_graph(
3331
self.nodelist,
3432
data,
35-
self.gpu_avail,
33+
kernel_context.gpu_avail,
3634
time_indices,
3735
)
3836

3937
@line_magic
4038
def display_graph_for_index(self, line):
41-
pass
39+
"""
40+
Display performance graph for a given index.
41+
Usage:
42+
%display_graph_for_index 2
43+
"""
44+
45+
if not line.strip():
46+
self.cell_output(
47+
"No index specified. Use: %display_graph_for_index index",
48+
"stderr"
49+
)
50+
return
51+
52+
try:
53+
index = int(line.strip())
54+
except ValueError:
55+
self.cell_output(
56+
"Invalid index. Please provide an integer.",
57+
"stderr"
58+
)
59+
return
60+
61+
history = kernel_context.perfdata_handler.get_perfdata_history()
62+
if index >= len(history):
63+
self.cell_output(
64+
f"Tracked only {len(history)} cells. This index is not available.",
65+
"stderr"
66+
)
67+
return
68+
69+
time_indices = kernel_context.perfdata_handler.get_time_indices()[index]
70+
71+
if time_indices:
72+
sub_idxs = [x[0] for x in time_indices[0]]
73+
self.cell_output(
74+
f"📈 Cell seemed to be tracked in multi-cell mode. "
75+
f"Got performance data for the following sub-cells: {sub_idxs}"
76+
)
77+
78+
perfvis.draw_performance_graph(
79+
self.nodelist,
80+
history[index],
81+
kernel_context.gpu_avail,
82+
time_indices,
83+
)
4284

4385

4486
@cell_magic
@@ -71,15 +113,18 @@ def set_perfmonitor(self, line, code):
71113
+ str(self.nodelist)
72114
)
73115
except Exception as e:
74-
self.cell_output(f"Error setting monitor\n{e}", "stderr")
116+
self.cell_output(
117+
f"Error setting monitor\n{e}",
118+
"stderr"
119+
)
75120
else:
76121
self.cell_output(
77122
f"KernelWarning: Currently in {self.mode}, command ignored.",
78123
"stderr",
79124
)
80125

81126
@staticmethod
82-
def cell_output(string, stream="stdout"):
127+
def cell_output(string: str, stream="stdout"):
83128
if stream == "stderr":
84129
print(string, file=sys.stderr)
85130
else:

0 commit comments

Comments
 (0)