Skip to content

[RFC] [Hybrid Script] A hybrid script backend #2432

@were

Description

@were

Sorry to change my mind again and again, and I will never use the term "finally". Making ideas is endless.

An IR Dumper #2288 , is more heavy-weighted than I supposed before.
I now decide to break this issue into 2 steps:

We already have Halide's IRPrinter to do a statical sanity check, and also the lowered IRs are too low-level to give good readability. Overall, what I want becomes something which is both runnable and gives full control to the IR body.

  1. The current Halide IRPrinter has bad support to the double-name thing.
    This is because currently, TVM uses "unique pointer" to differentiate objects.
    For example, these 2 tensors below share the same name, but they are essentially two different tensors.
    However, if users use these 2 tensors to build a module, and see the lowered body, it will be extremely confusing. IRPrinter just dumps these tensors without checking double-name.
a = tvm.placeholder(shape)
b = tvm.placeholder(shape)

Also, he current IRDump dumps results of each pass to files whose suffixes are .cc. I guess the point of doing this is to borrow the syntax highlight of .cc. However, the contents dumped have nothing to do with C, so I believe migrating the text format to Python, and using Python suffix will be better.

  1. Thus, What's more, dumping IR as Python snippet will not suffice. Dumping a complete hybrid script function will be highly desirable.
    Something which is both runnable and contains its source code is exactly what module is in TVM.
    Finally, I decided to extend a hybrid module looks like this:
#sch is a schedule of abitary op node
with tvm.target.create('hybrid'): #this with stmt is required by special lower passes
    module = tvm.build(sch, tvm_args) #a hybrid module is returned
hybrid_op = module(*tvm_args) #hybrid compilation
np_res = module(*np_args) #software emulation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions