Profiling TensorRT Engine
(engine_file: str, steps: int = 1000)
| 304 | |
| 305 | |
| 306 | def Profiling(engine_file: str, steps: int = 1000): |
| 307 | """ Profiling TensorRT Engine """ |
| 308 | logger = trt.Logger(trt.Logger.ERROR) |
| 309 | import pycuda.autoinit |
| 310 | |
| 311 | with open(engine_file, 'rb') as f, trt.Runtime(logger) as runtime: |
| 312 | engine = runtime.deserialize_cuda_engine(f.read()) |
| 313 | |
| 314 | with engine.create_execution_context() as context: |
| 315 | context.profiler = MyProfiler(steps) |
| 316 | inputs, outputs, bindings, stream = allocate_buffers(context.engine) |
| 317 | |
| 318 | for input in inputs: |
| 319 | input.host = convert_any_to_numpy(torch.rand(input.host.shape).float()) |
| 320 | |
| 321 | for _ in tqdm(range(steps), desc='TensorRT is running...'): |
| 322 | do_inference_v2( |
| 323 | context, bindings=bindings, inputs=inputs, |
| 324 | outputs=outputs, stream=stream) |
| 325 | context.profiler.report() |
| 326 | |
| 327 | |
| 328 | def TestAlignment(engine_file: str, graph: BaseGraph, samples: Iterable, collate_fn: Callable = None) -> dict: |
no test coverage detected