Trace Reading Codegen
Code in neutrino/utils/trace_reading.py
.
To facilitate trace analysis, we provide code generation for trace reading based on the map defintion. Based on the script, you can easily parse the trace into Python data structure.
We are considering upgrading it to Numpy Structured Array. Please contact us if you are interested.
Codegen Example
Following is an example of reading code for block_sched.py
, the core is the parse
function that
receives the path to raw trace (.bin
) and returns:
TraceHeader
: global information, contains thegridDim
s,blockDim
s,sharedMemBytes
andnum_probes
List[TraceSection]
: map-specific informations, contains thesize
(per records),warpDiv
, andoffset
Dict[str, List[List[NamedTuple]]]
: trace datas, use the map name as reference.
# Neutrino Auto-Generated Code for Trace Reading
import struct
from typing import NamedTuple, List, Tuple, Dict
from neutrino import TraceHeader, TraceSection
class block_sched(NamedTuple):
start: int
elapsed: int
cuid: int
def parse(path: str) -> Tuple[TraceHeader, List[TraceSection], Dict[str, List[List[NamedTuple]]]]:
with open(path, "rb") as f:
header: TraceHeader = TraceHeader(*struct.unpack("iiiiiiii", f.read(32)))
sections: List[TraceSection] = []
for _ in range(header.numProbes):
sections.append(TraceSection(*struct.unpack("IIQ", f.read(16))))
gridSize = header.gridDimX * header.gridDimY * header.gridDimZ
blockSize = header.blockDimX * header.blockDimY * header.blockDimZ
records: Dict[str, List[List[NamedTuple]]] = dict()
# Read block_sched
records["block_sched"] = []
f.seek(sections[0].offset)
for i in range(gridSize):
records["block_sched"].append([])
for j in range(blockSize // sections[0].warpDiv):
records["block_sched"][-1].append([])
for k in range(sections[0].size // 16):
records["block_sched"][i][j].append(block_sched(*struct.unpack("qII", f.read(16))))
return header, sections, records
# END of Neutrino Auto-Generated Code for Trace Reading
Usage
Trace reading code generation is enabled by default and you can find the generated read.py
in the trace directory (the one with event.log
).
If you want to use it manually, the tool in neutrino/utils/trace_read.py
also expose CLI usage by
python neutrino/utils.trace_reading.py <path/to/probe>
And the trace reading code will be printed out to the shell.