-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmoke_test.py
More file actions
48 lines (37 loc) · 1.1 KB
/
Copy pathsmoke_test.py
File metadata and controls
48 lines (37 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
from pathlib import Path
import torch
import torch_stub_gpu
TRACE_PATH = Path("stub_gpu_trace.json")
EXPECTED_EVENTS = {
"stubGpuLaunchKernel",
"stub_gpu_hello_kernel",
"stubGpuMemcpyHtoD",
}
with torch.profiler.profile(
activities=[
torch.profiler.ProfilerActivity.CPU,
torch.profiler.ProfilerActivity.PrivateUse1,
],
) as prof:
pass
prof.export_chrome_trace(str(TRACE_PATH))
print(f"trace exported: {TRACE_PATH}")
with TRACE_PATH.open() as trace_file:
trace = json.load(trace_file)
trace_events = trace.get("traceEvents") if isinstance(trace, dict) else None
if not isinstance(trace_events, list):
raise RuntimeError("invalid trace: 'traceEvents' must be a JSON array")
found = {
event.get("name")
for event in trace_events
if isinstance(event, dict) and event.get("name") in EXPECTED_EVENTS
}
missing = EXPECTED_EVENTS - found
print("found:", sorted(found))
print("missing:", sorted(missing))
if missing:
raise RuntimeError(
"missing synthetic profiler events: " + ", ".join(sorted(missing))
)
print("trace validation passed")