-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[TOPI][ADRENO] Add conv2d transpose nchw texture schedule #15786
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
echuraev
merged 18 commits into
apache:main
from
krishnaraj36:conv2d_transpose_adreno_texture
Nov 15, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
59c2487
[TOPI][ADRENO] Add conv2d transpose nchw texture schedule
krishnaraj36 25d446a
Fix the whitespace lint error
krishnaraj36 31c1729
Fix lint errors
krishnaraj36 2db6a34
Fix whitespace lint error
krishnaraj36 5d37af4
Removed unused variables
krishnaraj36 c5a2d58
Add more conv2dTranspose testcases
krishnaraj36 61b7f6e
empty update
krishnaraj36 cc49fc4
Update test_conv2d_transpose_nchw_texture.py
krishnaraj36 7ccfd8c
Added more testcase to check memory scopes
krishnaraj36 a438d20
Device specific alter_op_layout for conv2d_transpose
srkreddy1238 6c32b1b
Fix in virtual device setup and added test case with scope check
krishnaraj36 b2dc7b0
Add the comment conv2d algo
krishnaraj36 4dd6efd
Add the comment conv2d algo
krishnaraj36 adc75b8
Removed fp16 test case from texture
krishnaraj36 da87c61
remove opencl config change for mainline confilct
krishnaraj36 c1b4d5f
Add the test case for 3 channel input which run with cuda schecule
krishnaraj36 b95aacd
Fix in op strategy for out channel 3
krishnaraj36 d64268b
Comment in test case for memory scope
krishnaraj36 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| # pylint: disable=invalid-name,unused-variable,unused-argument,no-member | ||
| """Conv2D Transpose alter op for Qualcomm Adreno GPU""" | ||
|
|
||
| import logging | ||
|
|
||
| import re | ||
| import tvm | ||
| from tvm import te | ||
| from tvm import relay | ||
| from tvm import autotvm | ||
| from ..utils import get_const_tuple | ||
| from ..nn import conv2d_transpose_alter_layout | ||
|
|
||
| logger = logging.getLogger("topi") | ||
|
|
||
| # Number of wildcards for matching of supported layouts to be transformed | ||
| _NCHWc_matcher = re.compile("^NCHW[0-9]+c$") | ||
| _IOHWo_matcher = re.compile("^IOHW[0-9]+o$") | ||
|
|
||
|
|
||
| @conv2d_transpose_alter_layout.register("adreno") | ||
| def _alter_conv2d_transpose_layout(attrs, inputs, tinfos, out_type): | ||
| """ | ||
| Prepare of the new conv2d_transpose with proper target blocked layout attributes | ||
| OpenCL Textures supports 1d/2d/3d/4d tetures but read happens always only for 4 elements | ||
| in a line. Thus way we are supporting for now only 4d conversions on the end | ||
| NCHW -> NCHW4c & IOHW ->IOHW4o | ||
| """ | ||
| target = tvm.target.Target.current(allow_none=False) | ||
| dispatch_ctx = autotvm.task.DispatchContext.current | ||
| new_attrs = {k: attrs[k] for k in attrs.keys()} | ||
|
|
||
| # Parse the attributes. | ||
| padding = attrs.get_int_tuple("padding") | ||
| strides = attrs.get_int_tuple("strides") | ||
| dilation = attrs.get_int_tuple("dilation") | ||
| data_layout = attrs["data_layout"] | ||
| kernel_layout = attrs["kernel_layout"] | ||
| data_tensor, kernel_tensor = tinfos | ||
| data_dtype = data_tensor.dtype | ||
| out_dtype = out_type.dtype | ||
|
|
||
| if isinstance(dispatch_ctx, autotvm.task.ApplyGraphBest): | ||
| cfg = dispatch_ctx.query(target, None) | ||
| workload = cfg.workload | ||
| else: | ||
| impl, outs = relay.backend.te_compiler.select_implementation( | ||
| relay.op.get("nn.conv2d_transpose"), attrs, tinfos, out_type, target | ||
| ) | ||
| workload = autotvm.task.get_workload(outs) | ||
| cfg = dispatch_ctx.query(target, workload) | ||
|
|
||
| topi_tmpl = workload[0] | ||
|
|
||
| if "conv2d_transpose_nchwc" in topi_tmpl: # covers conv2d_transpose_nchwc | ||
| if data_layout == "NCHW" and kernel_layout == "IOHW": | ||
| batch, in_channels, in_height, in_width = data_tensor.shape | ||
| _, out_channles, kernel_h, kernel_w = kernel_tensor.shape | ||
| in_channel_block = in_channels % 4 | ||
| if in_channel_block == 0: | ||
| in_channel_block = 4 | ||
| num_filter_block = out_channles % 4 | ||
| if num_filter_block == 0: | ||
| num_filter_block = 4 | ||
|
|
||
| # no support yet for tensors that cannot be divisible by factor 4 | ||
| if num_filter_block != 4: | ||
| return None | ||
|
|
||
| batch_size, in_channel, height, width = get_const_tuple(data_tensor.shape) | ||
| in_filter_channel, out_channel, kh, kw = get_const_tuple(kernel_tensor.shape) | ||
|
|
||
| # update new attrs | ||
| new_attrs["channels"] = out_channel | ||
| if in_channel_block == 4: | ||
| new_attrs["data_layout"] = f"NCHW{in_channel_block}c" | ||
| else: | ||
| new_attrs["data_layout"] = "NCHW" | ||
| # (oc, ic, h, w) -> (ic, OC, h, w, oc) | ||
| new_attrs["kernel_layout"] = f"IOHW{num_filter_block}o" | ||
| new_attrs["out_layout"] = f"NCHW{num_filter_block}c" | ||
|
|
||
| # Store altered operator's config for applying of tuned AutoTVM statistics | ||
| if in_channel_block == 4: | ||
| new_data = te.placeholder( | ||
| (batch_size, in_channel // in_channel_block, height, width, in_channel_block), | ||
| dtype=data_dtype, | ||
| ) | ||
| else: | ||
| new_data = data_tensor | ||
| new_kernel = te.placeholder( | ||
| (in_filter_channel, out_channel // num_filter_block, kh, kw, num_filter_block), | ||
| dtype=kernel_tensor.dtype, | ||
| ) | ||
| new_workload = autotvm.task.args_to_workload( | ||
| [new_data, new_kernel, strides, padding, dilation, out_dtype], | ||
| topi_tmpl, # "conv2d_transpose_nchwc.image2d", | ||
| ) | ||
| dispatch_ctx.update(target, new_workload, cfg) | ||
| else: | ||
| assert _NCHWc_matcher.match(data_layout) | ||
| assert _IOHWo_matcher.match(kernel_layout) | ||
| return relay.nn.conv2d_transpose(*inputs, **new_attrs) | ||
|
|
||
| return None |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.