[OpenCL][Adreno] Fix conv2d when output channels < 4#14996
Merged
masahi merged 1 commit intoapache:mainfrom Jun 1, 2023
Merged
[OpenCL][Adreno] Fix conv2d when output channels < 4#14996masahi merged 1 commit intoapache:mainfrom
masahi merged 1 commit intoapache:mainfrom
Conversation
When the number of output channels is less than 4, then we cannot pack such convolution to textures, although we can repack and extend tensors from 4d to 5d in runtime. It is happened because function `PropBoundToInputs` is invoked for all stages in when InferBound pass or LowerSchedule function is called. `PropBoundToInputs` has a logic in it that helps to developer to avoid out of bound access. And based on the output shape, it propagates it to inputs. Imagine that we want to transform a 4d tensor with 3 channels to 5d, extend its number of channels to 4 and then transform it back to 4d tensor with number of channels equal to 3. Example below: ``` [1, 3, 6, 6] -> [1, 1, 6, 6, 4] -> [1, 3, 6, 6] ``` In this case, we might write a boundary check in the repacking and extending compute function to handle the case when the iterator by the channels is out of bounds for the intermediate tensor. To avoid such problem, `PropBoundToInputs` has a logic which propagates a bounds from output tensor to input. In case when it is a possible situation that the compute has out of bounds access, then the range is decreased to value when such situation cannot be achieved. That means that for the example above the loop by channels which should filling intermediate tensor will iterate in range [0, 2] instead of [0, 3]. As it was mentioned, to avoid such problem we use buffers and cuda schedules instead of textures for cases when number of output channels is less than 4 and we cannot pack such tensor to texture. I evaluated performance of such approach and it doesn't introduce any performance degradation. For such small convolutions performance with buffers even a bit better than with textures.
Collaborator
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment. Generated by tvm-bot |
elvin-n
approved these changes
May 31, 2023
Contributor
Author
|
@masahi, @csullivan could you please review this PR? |
masahi
approved these changes
Jun 1, 2023
Contributor
|
Thanks for the PR @echuraev . |
mei-ye
pushed a commit
to mei-ye/tvm
that referenced
this pull request
Jun 1, 2023
When the number of output channels is less than 4, then we cannot pack such convolution to textures, although we can repack and extend tensors from 4d to 5d in runtime. It is happened because function `PropBoundToInputs` is invoked for all stages in when InferBound pass or LowerSchedule function is called. `PropBoundToInputs` has a logic in it that helps to developer to avoid out of bound access. And based on the output shape, it propagates it to inputs. Imagine that we want to transform a 4d tensor with 3 channels to 5d, extend its number of channels to 4 and then transform it back to 4d tensor with number of channels equal to 3. Example below: ``` [1, 3, 6, 6] -> [1, 1, 6, 6, 4] -> [1, 3, 6, 6] ``` In this case, we might write a boundary check in the repacking and extending compute function to handle the case when the iterator by the channels is out of bounds for the intermediate tensor. To avoid such problem, `PropBoundToInputs` has a logic which propagates a bounds from output tensor to input. In case when it is a possible situation that the compute has out of bounds access, then the range is decreased to value when such situation cannot be achieved. That means that for the example above the loop by channels which should filling intermediate tensor will iterate in range [0, 2] instead of [0, 3]. As it was mentioned, to avoid such problem we use buffers and cuda schedules instead of textures for cases when number of output channels is less than 4 and we cannot pack such tensor to texture. I evaluated performance of such approach and it doesn't introduce any performance degradation. For such small convolutions performance with buffers even a bit better than with textures.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When the number of output channels is less than 4, then we cannot pack such convolution to textures, although we can repack and extend tensors from 4d to 5d in runtime.
It is happened because function
PropBoundToInputsis invoked for all stages in when InferBound pass or LowerSchedule function is called.PropBoundToInputshas a logic in it that helps to developer to avoid out of bound access. And based on the output shape, it propagates it to inputs.Imagine that we want to transform a 4d tensor with 3 channels to 5d, extend its number of channels to 4 and then transform it back to 4d tensor with number of channels equal to 3. Example below:
In this case, we might write a boundary check in the repacking and extending compute function to handle the case when the iterator by the channels is out of bounds for the intermediate tensor.
To avoid such problem,
PropBoundToInputshas a logic which propagates a bounds from output tensor to input. In case when it is a possible situation that the compute has out of bounds access, then the range is decreased to value when such situation cannot be achieved. That means that for the example above the loop by channels which should filling intermediate tensor will iterate in range [0, 2] instead of [0, 3].As it was mentioned, to avoid such problem we use buffers and cuda schedules instead of textures for cases when number of output channels is less than 4 and we cannot pack such tensor to texture. I evaluated performance of such approach and it doesn't introduce any performance degradation. For such small convolutions performance with buffers even a bit better than with textures.