tvm.instrument#
Common pass instrumentation across IR variants.
- class tvm.instrument.DumpIR(dump_dir: Path | str, refresh: bool = False)[源代码]#
Dump the IR after the pass runs.
- class tvm.instrument.PassInstrument[源代码]#
A pass instrument implementation.
To use, a user class can either subclass from PassInstrument directly, or can apply the
pass_instrument()wrapper. In either case, the enter_pass_ctx, exit_pass_ctx, should_run, run_before_pass, and run_after_pass methods can be defined to adjust the instrument's behavior. See the no-op implementations in this class definition for more information on each.- run_after_pass(mod, info)[源代码]#
Instrument after the pass runs.
Called once for each pass that is run while the instrumented context is active.
- 参数:
mod (tvm.ir.module.IRModule) -- The module on which an optimization pass is being run.
info (tvm.transform.PassInfo) -- The pass information.
- 返回类型:
None
- run_before_pass(mod, info)[源代码]#
Instrument before the pass runs.
Called once for each pass that is run while the instrumented context is active.
- 参数:
mod (tvm.ir.module.IRModule) -- The module on which an optimization pass is being run.
info (tvm.transform.PassInfo) -- The pass information.
- 返回类型:
None
- should_run(mod, info)[源代码]#
Determine whether to run the pass or not.
Called once for each pass that is run while the instrumented context is active.
- 参数:
mod (tvm.ir.module.IRModule) -- The module on which an optimization pass is being run.
info (tvm.transform.PassInfo) -- The pass information.
- 返回:
should_run -- True to run the pass, or False to skip the pass.
- 返回类型:
bool
- class tvm.instrument.PassPrintingInstrument(print_before_pass_names, print_after_pass_names)[源代码]#
A pass instrument to print if before or print ir after each element of a named pass.
- class tvm.instrument.PassTimingInstrument[源代码]#
A wrapper to create a passes time instrument that implemented in C++
- static render()[源代码]#
Retrieve rendered time profile result :returns: string -- The rendered string result of time profiles :rtype: string
示例
timing_inst = PassTimingInstrument() with tvm.transform.PassContext(instruments=[timing_inst]): relax_mod = relax.transform.FuseOps()(relax_mod) # before exiting the context, get profile results. profiles = timing_inst.render()
- class tvm.instrument.Path(*args, **kwargs)[源代码]#
PurePath subclass that can make system calls.
Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.
- absolute()[源代码]#
Return an absolute version of this path by prepending the current working directory. No normalization or symlink resolution is performed.
Use resolve() to get the canonical path to a file.
- exists(*, follow_symlinks=True)[源代码]#
Whether this path exists.
This method normally follows symlinks; to check whether a symlink exists, add the argument follow_symlinks=False.
- expanduser()[源代码]#
Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)
- glob(pattern, *, case_sensitive=None)[源代码]#
Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.
- hardlink_to(target)[源代码]#
Make this path a hard link pointing to the same file as target.
Note the order of arguments (self, target) is the reverse of os.link's.
- classmethod home()[源代码]#
Return a new path pointing to the user's home directory (as returned by os.path.expanduser('~')).
- is_file()[源代码]#
Whether this path is a regular file (also True for symlinks pointing to regular files).
- iterdir()[源代码]#
Yield path objects of the directory contents.
The children are yielded in arbitrary order, and the special entries '.' and '..' are not included.
- lchmod(mode)[源代码]#
Like chmod(), except if the path points to a symlink, the symlink's permissions are changed, rather than its target's.
- lstat()[源代码]#
Like stat(), except if the path points to a symlink, the symlink's status information is returned, rather than its target's.
- open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)[源代码]#
Open the file pointed to by this path and return a file object, as the built-in open() function does.
- read_text(encoding=None, errors=None)[源代码]#
Open the file in text mode, read it, and close the file.
- rename(target)[源代码]#
Rename this path to the target path.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- replace(target)[源代码]#
Rename this path to the target path, overwriting if that path exists.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- resolve(strict=False)[源代码]#
Make the path absolute, resolving all symlinks on the way and also normalizing it.
- rglob(pattern, *, case_sensitive=None)[源代码]#
Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.
- samefile(other_path)[源代码]#
Return whether other_path is the same or not as this file (as returned by os.path.samefile()).
- stat(*, follow_symlinks=True)[源代码]#
Return the result of the stat() system call on this path, like os.stat() does.
- symlink_to(target, target_is_directory=False)[源代码]#
Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.
- touch(mode=438, exist_ok=True)[源代码]#
Create this file with the given access mode, if it doesn't exist.
- unlink(missing_ok=False)[源代码]#
Remove this file or link. If the path is a directory, use rmdir() instead.
- class tvm.instrument.PrintAfterAll(*args, **kwargs)[源代码]#
Print the name of the pass, the IR, only after passes execute.
- class tvm.instrument.PrintBeforeAll(*args, **kwargs)[源代码]#
Print the name of the pass, the IR, only before passes execute.
- tvm.instrument.pass_instrument(pi_cls=None)[源代码]#
Decorate a pass instrument.
- 参数:
pi_class (class) -- Instrument class. See example below.
示例
@tvm.instrument.pass_instrument class SkipPass: def __init__(self, skip_pass_name): self.skip_pass_name = skip_pass_name # Uncomment to customize # def enter_pass_ctx(self): # pass # Uncomment to customize # def exit_pass_ctx(self): # pass # If pass name contains keyword, skip it by return False. (return True: not skip) def should_run(self, mod, pass_info) if self.skip_pass_name in pass_info.name: return False return True # Uncomment to customize # def run_before_pass(self, mod, pass_info): # pass # Uncomment to customize # def run_after_pass(self, mod, pass_info): # pass skip_annotate = SkipPass("AnnotateSpans") with tvm.transform.PassContext(instruments=[skip_annotate]): tvm.compile(mod, "llvm")