# Copyright (c) 2024 Justin Davis (davisjustin302@gmail.com)## MIT Licensefrom__future__importannotationsfromfunctoolsimportlru_cachefrompathlibimportPath
[docs]@lru_cache(maxsize=None)deffind_trtexec()->Path:""" Find an instance of the trtexec binary on the system. Requires the locate command to be installed on the system. As such, only works on Unix-like systems. Returns ------- Path The path to the trtexec binary Raises ------ FileNotFoundError If the trtexec binary is not found on the system """possible_dirs:list[Path]=[Path("/usr/src/tensorrt/bin"),Path("/usr/local/TensorRT/bin"),Path("/usr/local/tensorrt/bin"),]forrootinpossible_dirs:ifnotroot.exists():continueifnotroot.is_dir():continuetrtexec_path=root/"trtexec"iftrtexec_path.exists():returntrtexec_path# could not find trtexec in the default locationserr_msg="trtexec binary not found on system"raiseFileNotFoundError(err_msg)