MCPcopy
hub / github.com/OpenPPL/ppq / Benchmark

Function Benchmark

ppq/utils/TensorRTUtil.py:283–303  ·  view source on GitHub ↗

Benckmark TensorRT Engine

(engine_file: str, steps: int = 10000)

Source from the content-addressed store, hash-verified

281
282
283def Benchmark(engine_file: str, steps: int = 10000) -> float:
284 """ Benckmark TensorRT Engine """
285 logger = trt.Logger(trt.Logger.INFO)
286 import pycuda.autoinit
287
288 with open(engine_file, 'rb') as f, trt.Runtime(logger) as runtime:
289 engine = runtime.deserialize_cuda_engine(f.read())
290
291 with engine.create_execution_context() as context:
292 inputs, outputs, bindings, stream = allocate_buffers(context.engine)
293 for input in inputs:
294 input.host = convert_any_to_numpy(torch.rand(input.host.shape).float())
295
296 tick = time.time()
297 for _ in tqdm(range(steps), desc='TensorRT is running...'):
298 do_inference_v2(
299 context, bindings=bindings, inputs=inputs,
300 outputs=outputs, stream=stream)
301 tok = time.time()
302 print(f'Time span: {tok - tick : .4f} sec')
303 return tick - tok
304
305
306def Profiling(engine_file: str, steps: int = 1000):

Callers 3

yolo_5.pyFile · 0.90
02_Quantization.pyFile · 0.90

Calls 3

convert_any_to_numpyFunction · 0.90
allocate_buffersFunction · 0.70
do_inference_v2Function · 0.70

Tested by

no test coverage detected