tvm.instrument
跨 IR 变体的通用 pass instrumentation。
- class tvm.instrument.PassInstrument
Pass instrument 实现。
要使用,用户类可以直接从 PassInstrument 子类化,或者可以应用
pass_instrument()
包装器。 在任何一种情况下,都可以定义 enter_pass_ctx、exit_pass_ctx、should_run、run_before_pass 和 run_after_pass 方法来调整 instrument 的行为。 有关每个方法的更多信息,请参阅此类定义中的 no-op 实现。- enter_pass_ctx()
在进入 instrumented 上下文时调用。
- 返回类型:
None
- exit_pass_ctx()
在退出 instrumented 上下文时调用。
- 返回类型:
None
- should_run(mod, info)
确定是否运行 pass。
对于在 instrumented 上下文处于活动状态时运行的每个 pass,都会调用一次。
- 参数:
mod (tvm.ir.module.IRModule) – 正在运行优化 pass 的模块。
info (tvm.transform.PassInfo) – pass 信息。
- 返回:
should_run – True 表示运行 pass,False 表示跳过 pass。
- 返回类型:
- run_before_pass(mod, info)
在 pass 运行之前进行 instrument。
对于在 instrumented 上下文处于活动状态时运行的每个 pass,都会调用一次。
- 参数:
mod (tvm.ir.module.IRModule) – 正在运行优化 pass 的模块。
info (tvm.transform.PassInfo) – pass 信息。
- 返回类型:
None
- run_after_pass(mod, info)
在 pass 运行之后进行 instrument。
对于在 instrumented 上下文处于活动状态时运行的每个 pass,都会调用一次。
- 参数:
mod (tvm.ir.module.IRModule) – 正在运行优化 pass 的模块。
info (tvm.transform.PassInfo) – pass 信息。
- 返回类型:
None
- class tvm.instrument.PassPrintingInstrument(print_before_pass_names, print_after_pass_names)
一个 pass instrument,用于在命名 pass 的每个元素之前打印或之后打印 ir。
- class tvm.instrument.PassTimingInstrument
一个包装器,用于创建在 C++ 中实现的 pass 时间 instrument
- static render()
检索渲染的时间 profile 结果 :returns: string – 时间 profile 的渲染字符串结果 :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.PrintAfterAll(*args, **kwargs)
仅在 pass 执行后打印 pass 的名称、IR。
- class tvm.instrument.PrintBeforeAll(*args, **kwargs)
仅在 pass 执行之前打印 pass 的名称、IR。
- tvm.instrument.pass_instrument(pi_cls=None)
装饰 pass instrument。
- 参数:
pi_class (class) – Instrument 类。 请参阅下面的示例。
示例
@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")