Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TensorIR] CreatePrimFunc from TE #7987

Merged
merged 1 commit into from
May 7, 2021
Merged

[TensorIR] CreatePrimFunc from TE #7987

merged 1 commit into from
May 7, 2021

Conversation

Hzfengsy
Copy link
Member

@Hzfengsy Hzfengsy commented May 6, 2021

This PR introduces a method to create PrimFunc (and further TensorIR schedule) from Tensor Expression. (e.g. te.compute)

cc @tqchen @junrushao1994 @comaniac @jcf94 @xqdan

@tkonolige
Copy link
Contributor

Would it be possible to add a name field to the create_prim_func function? That way when we print out primfuncs for debugging, they aren't all called "main".

@tqchen
Copy link
Member

tqchen commented May 6, 2021

Create prim_func returns a PrimFunc, the name is attached in module creation process, we can likely recompose by

mod = IRModule({"mycoolname": create_prim_func())

Note such name is different from the global_symbol(name of generated function), which can be set by create_prim_func().with_attr("tir.global_symbol", global_symbol)

python/tvm/te/operation.py Show resolved Hide resolved
@tkonolige
Copy link
Contributor

Instead of create_prim_func().with_attr("tir.global_symbol", global_symbol), I think we should just make create_prim_func take a name parameter. I was working on autoscheduler earlier and all the primfuncs it had were called "main". Having a name parameter encourages the user to name their functions and makes debugging easier.

@tqchen
Copy link
Member

tqchen commented May 6, 2021

If we really want to encourage the name, and given IRModule is the first class item for running exchange between passes. Let us consider make the function return an IRModule instead, in this case, perhaps we should rename to create_tir (coming back to another old name)

@junrushao
Copy link
Member

@tkonolige The mechanism causing the issue you mentioned is that when constructing a tir::Schedule class, and the input is a PrimFunc, then it will put that PrimFunc into an IRModule with the default name main, so that the schedule is always IRModule-based.

@junrushao
Copy link
Member

@tqchen The problem of creating an IRModule instead is that we might want to an IRModule that contains multiple PrimFuncs, e.g.:

mod = IRModule({
  "func_1": create_prim_func(...),
  "func_2": create_prim_func(...),
})

Co-authored-by: Tianqi Chen <tqchen@users.noreply.github.com>
Co-authored-by: Wuwei Lin <wuwei@apache.org>
Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com>
@tqchen
Copy link
Member

tqchen commented May 7, 2021

I see, i now agree that we can go with the compositional style API. While I agree with @tkonolige that naming functions is going to be useful. We can do that through the compositional API and when creating example tutorials for scheduling. Thanks @junrushao1994 @Hzfengsy

@junrushao
Copy link
Member

Thanks for the great discussion @tkonolige @tqchen @Hzfengsy! I am going to merge it in given there is no objection :-)

@junrushao junrushao merged commit 4122a6a into apache:main May 7, 2021
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request May 19, 2021
Co-authored-by: Tianqi Chen <tqchen@users.noreply.github.com>
Co-authored-by: Wuwei Lin <wuwei@apache.org>
Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com>
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Jun 17, 2021
Co-authored-by: Tianqi Chen <tqchen@users.noreply.github.com>
Co-authored-by: Wuwei Lin <wuwei@apache.org>
Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com>
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Jun 17, 2021
Co-authored-by: Tianqi Chen <tqchen@users.noreply.github.com>
Co-authored-by: Wuwei Lin <wuwei@apache.org>
Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants