MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / EnginePlan

Class EnginePlan

tools/experimental/trt-engine-explorer/trex/engine_plan.py:33–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32
33class EnginePlan:
34 def __init__(self,
35 graph_file: str,
36 profiling_file: str=None,
37 profiling_metadata_file: str=None,
38 build_metadata_file: str=None,
39 name: str=None,
40 profile_id: int=None,
41 ):
42 def path_leaf(path):
43 head, tail = ntpath.split(path)
44 return tail or ntpath.basename(head)
45
46 def create_layers(self, raw_layers):
47 layers = [Layer(raw_layer) for raw_layer in raw_layers]
48 self.layers = fold_no_ops(layers, self.bindings)
49 self.all_layers = deepcopy(self.layers)
50 self.constants = [layer for layer in self.layers if layer.type == 'Constant']
51 self.layers = [layer for layer in self.layers if layer.type != 'Constant']
52 return raw_layers
53
54 def process_profiling_file(profiling_file, ignore_layers):
55 if not profiling_file:
56 return None
57 raw_perf = read_profiling_file(profiling_file)
58 raw_perf = [perf_rec for perf_rec in raw_perf if
59 perf_rec['name'] not in ignore_layers]
60 return raw_perf
61
62 def merge_profiling_data(graph_df, raw_perf):
63 def add_zero_perf(graph_df):
64 df = graph_df
65 df['latency.pct_time'] = [0] * len(df)
66 df['latency.avg_time'] = [0] * len(df)
67 df['latency.median_time'] = [0] * len(df)
68 df['latency.time'] = [0] * len(df)
69 return df
70
71 if raw_perf is not None:
72 perf_df = pd.DataFrame.from_dict(raw_perf)
73 perf_df.drop(columns=['name'], inplace=True)
74 perf_df.rename(columns={
75 'percentage': 'latency.pct_time',
76 'averageMs': 'latency.avg_time',
77 'medianMs': 'latency.median_time',
78 'timeMs': 'latency.time',
79 }, inplace=True)
80 if len(graph_df) == len(perf_df):
81 df = graph_df.join(perf_df)
82 else:
83 warnings.warn(
84 "Ignoring profiling data: The number of layers in the engine "
85 "graph does not match the number of layers in the performance "
86 "JSON.\n"
87 "This can happen if you're not using the first shape-profile.")
88 df = add_zero_perf(graph_df)
89 else:
90 warnings.warn("Profiling data was not provided.")

Callers 3

planFunction · 0.90
plan2Function · 0.90
draw_engineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected