Skip to content

Move the allocates of AoT codegen to be TVMBAWs - #9065

Merged
leandron merged 2 commits into
apache:mainfrom
manupak:move_aot_allocates_global_workspace
Sep 24, 2021
Merged

Move the allocates of AoT codegen to be TVMBAWs#9065
leandron merged 2 commits into
apache:mainfrom
manupak:move_aot_allocates_global_workspace

Conversation

@manupak

Copy link
Copy Markdown
Contributor

This commit introduces changes to aot_executor_codegen.cc
to place tir.allocate to use storage_scope = 'global.workspace'.
The lower_tvm_builtin pass is modified slightly to generate
TVMBAW calls.

@manupak

Copy link
Copy Markdown
ContributorAuthor

cc : @areusch@mbs-octoml@tqchen



def test_aot_codegen_backend_alloc_workspace_calls():
dtype = "float32"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a brief docstring explaining what this test asserts?

inputs = OrderedDict([("data", i_data), ("weight", w1_data)])
output_list = generate_ref_data(mod, inputs)

compiled_runtime_modules = compile_models(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to assert that all the tir.allocate nodes are correctly tagged somewhere?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it is a bit cumbersome to do that :), Instead I used relay in primitive form so its clear that main function should only have three allocates.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbs-octoml@denise-k can we add a tracking/cleanup task to make this kind of assert easier to write? And flag to cleanup this test?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@areusch roadmap item and task tracking have been created.

@mbs-octomlmbs-octoml left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (FWIW). Thanks I learned from this one.

Comment threadsrc/tir/transforms/lower_tvm_builtin.cc
for (auto kv : storage_device_map_) {
for (auto sid : kv.second->storage_ids) {
// The buffer_var is created with storage_scope to be global.workspace to be serviced by
// TVMBAWs, explicitly. The reasoning being the executor allocates should be serviced by

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For poor folks like me: use TVMBackendAllocWorkspace at least once.

Comment threadsrc/tir/transforms/storage_rewrite.cc
@jroesch

Copy link
Copy Markdown
Member

@csullivan@mbrookhart@junrushao1994 can you guys sign off on this one as well to make sure this won't break anyone?

@jroesch

Copy link
Copy Markdown
Member

LGTM, will just ping other core compiler folks to make sure this works for them.

True,
)

source = compiled_runtime_modules[0].lib.imported_modules[0].get_source()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AoT codegen for main ends up as an imported module? Naively I would expect the TVMBackendAllocateWorkspace calls in the imported_modules list to be intra-op only, e.g. for the conv2d, not AoT main.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can understand the reasoning but the current flow just creates per target IRModules just before runtime.Modules are created. Therefore all host_target (i.e. CPU) PrimFuncs end up in a single runtime.Module.

@manupak
manupakforce-pushed the move_aot_allocates_global_workspace branch from 1f2a365 to db37329CompareSeptember 22, 2021 17:24

@manupakmanupak left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed the comments now. PTAL.

Comment threadsrc/tir/transforms/lower_tvm_builtin.cc
Comment threadsrc/tir/transforms/storage_rewrite.cc
inputs = OrderedDict([("data", i_data), ("weight", w1_data)])
output_list = generate_ref_data(mod, inputs)

compiled_runtime_modules = compile_models(

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it is a bit cumbersome to do that :), Instead I used relay in primitive form so its clear that main function should only have three allocates.

True,
)

source = compiled_runtime_modules[0].lib.imported_modules[0].get_source()

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can understand the reasoning but the current flow just creates per target IRModules just before runtime.Modules are created. Therefore all host_target (i.e. CPU) PrimFuncs end up in a single runtime.Module.

@manupak
manupakforce-pushed the move_aot_allocates_global_workspace branch from db37329 to 321ba2cCompareSeptember 22, 2021 20:33
@manupak

Copy link
Copy Markdown
ContributorAuthor

This is failing CI on an unrelated error (I think due to : #9013). I think #9076 should fix it (Thanks @mbs-octoml ). Therefore it would be great if we can get an approval if this looks good as it is blocking our work -- so that once #9076 lands we could merge this.

@jroesch

Copy link
Copy Markdown
Member

@manupa-arm@junrushao1994 and I landed the other patch, if you guys are still working today can you rebase before you log off and I will try and merge before end of day pacific time?

@manupak
manupakforce-pushed the move_aot_allocates_global_workspace branch from 321ba2c to 14f3cf4CompareSeptember 23, 2021 17:04
@manupak

Copy link
Copy Markdown
ContributorAuthor

Thanks! Done.

This commit introduces changes to aot_executor_codegen.cc
to place tir.allocate to use storage_scope = 'global.workspace'.
The lower_tvm_builtin pass is modified slightly to generate
TVMBAW calls.
Change-Id: Iba4ba437c1431c5197bf11abb826e03807bbcf66
*Adding more comments and descriptions
*Modified the test case to use primitive relay
Change-Id: Ia18a169d94bded3f81af7b3081c7d1ac29c669bc
@manupak
manupakforce-pushed the move_aot_allocates_global_workspace branch from 14f3cf4 to bfa7944CompareSeptember 24, 2021 05:46
@leandron
leandron merged commit 7c6a334 into apache:mainSep 24, 2021
ylc pushed a commit to ylc/tvm that referenced this pull request Sep 29, 2021
* Move the allocates of AoT codegen to be TVMBAWs
This commit introduces changes to aot_executor_codegen.cc
to place tir.allocate to use storage_scope = 'global.workspace'.
The lower_tvm_builtin pass is modified slightly to generate
TVMBAW calls.
Change-Id: Iba4ba437c1431c5197bf11abb826e03807bbcf66
* Move the allocates of AoT codegen to be TVMBAWs
*Adding more comments and descriptions
*Modified the test case to use primitive relay
Change-Id: Ia18a169d94bded3f81af7b3081c7d1ac29c669bc
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
* Move the allocates of AoT codegen to be TVMBAWs
This commit introduces changes to aot_executor_codegen.cc
to place tir.allocate to use storage_scope = 'global.workspace'.
The lower_tvm_builtin pass is modified slightly to generate
TVMBAW calls.
Change-Id: Iba4ba437c1431c5197bf11abb826e03807bbcf66
* Move the allocates of AoT codegen to be TVMBAWs
*Adding more comments and descriptions
*Modified the test case to use primitive relay
Change-Id: Ia18a169d94bded3f81af7b3081c7d1ac29c669bc
Sign up for freeto 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.

7 participants

@manupak@jroesch@leandron@areusch@csullivan@denise-k@mbs-octoml