Benckmark TensorRT Engine
(engine_file: str, steps: int = 10000)
| 281 | |
| 282 | |
| 283 | def 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 | |
| 306 | def Profiling(engine_file: str, steps: int = 1000): |
no test coverage detected