-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[ARM] Support NCHWc alter layout in the fallback mode #10724
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1aa40b2
[ARM] Support NCHWc alter layout in the fallback mode
masahi 45946ab
remove fallback path
masahi fc2d9ef
add test
masahi 88a2e02
fixed int32_lanes and add channel check
masahi d6f3574
fixed schedule dispatch bug
masahi c8b14e1
add workaround fallback path for NHWC im2col based GEMM schedule
masahi 0beacdf
int32_lanes=4 by default
masahi f43aabd
typo
masahi 77d1694
update test
masahi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,11 @@ | |
| # under the License. | ||
| import sys | ||
| from typing import List | ||
| import numpy as np | ||
|
|
||
| import pytest | ||
| import tvm | ||
| from tvm import relay | ||
| from tvm import meta_schedule as ms | ||
| from tvm.ir.module import IRModule | ||
| from tvm.meta_schedule.database import PyDatabase, TuningRecord, Workload | ||
|
|
@@ -149,5 +151,49 @@ def extract_task_qbert(): | |
| assert "vnni" in annotations["schedule_rule"] | ||
|
|
||
|
|
||
| def extract_task_arm_conv2d_nchwc(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure this runs @masahi? There's no
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops thanks for pointing this out, I added a fix in #10773 |
||
| data_shape = (1, 64, 128, 128) | ||
| weight_shape = (32, 64, 1, 1) | ||
| bias_shape = (weight_shape[0],) | ||
| padding = (1, 1) | ||
|
|
||
| data = relay.var("data", shape=data_shape, dtype="int8") | ||
| weight = relay.var("weight", shape=weight_shape, dtype="int8") | ||
| bias = relay.var("bias", shape=bias_shape, dtype="int32") | ||
| conv2d = relay.nn.conv2d( | ||
| data=data, | ||
| weight=weight, | ||
| kernel_size=weight_shape[2:], | ||
| channels=weight_shape[0], | ||
| padding=padding, | ||
| strides=(1, 1), | ||
| out_dtype="int32", | ||
| ) | ||
| bias_add = relay.nn.bias_add(conv2d, bias) | ||
| relay_mod = tvm.IRModule.from_expr(bias_add) | ||
|
|
||
| weight_np = np.random.uniform(1, 10, size=weight_shape).astype("int8") | ||
| bias_np = np.random.uniform(1, 10, size=bias_shape).astype("int32") | ||
|
|
||
| params = {"weight": weight_np, "bias": bias_np} | ||
|
|
||
| target = "llvm -device arm_cpu -mtriple aarch64-linux-gnu -mattr=+neon" | ||
| extracted_tasks = extract_task_from_relay(relay_mod, target, params) | ||
| tune_tasks = list( | ||
| filter( | ||
| lambda task: "conv2d" in task.task_name, | ||
| extracted_tasks, | ||
| ) | ||
| ) | ||
|
|
||
| assert len(tune_tasks) == 1 | ||
|
|
||
| relay_func = list(tune_tasks[0].mod.functions.values())[0] | ||
| out_type = relay_func.body.checked_type | ||
|
|
||
| # Check that the output is in NCHWc layout | ||
| assert list(out_type.shape) == [1, 8, 130, 130, 4] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(pytest.main([__file__] + sys.argv[1:])) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope it's safe to remove this. The x86 counterpart doesn't have thing like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are you testing it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I can pass the CI with this change, I assume it is safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mousius - could you please look at this given you've recently been turning on topi tests on aarch64 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to remove this code because it always makes
alter_layoutnop in the fallback mode. In contrast, in the x86 schedule,alter_layoutalways fires.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI has passed. I found that Giuseppe's im2col based conv2d implementation can fail to tensorize in the fallback mode, so I partially restored the fallback return path above.