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

[OpenCL] Fix type casting error #11021

Merged
merged 1 commit into from
Apr 15, 2022

Conversation

echuraev
Copy link
Contributor

Faced situation when generated OpenCL kernel contained the following if
condition:

if (uint4(...) && (int4(...) == int4(...)))

In this case, got the following error:
"can't convert between vector values of different size ('uint4' and 'int attribute((ext_vector_type(4)))')"

Added casts for binary ops. But it was necessary to modify CastFromTo
and add new method CastTo. Because with CastFromTo the following
code was generated:

if (uint4(...) && (convert_uint4(int4(...)) == convert_uint4(int4(...))))

But the OpenCL compiler still generated the same error.

This is why added new method CastTo. In this method we don't check the
current type of op and just add cast to a new type.

Finally the following code will be generated:

if (uint4(...) && convert_uint4(convert_uint4(int4(...)) == convert_uint4(int4(...))))

Thanks for contributing to TVM! Please refer to guideline https://tvm.apache.org/docs/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from Reviewers by @ them in the pull request thread.

@echuraev echuraev force-pushed the echuraev/fix_opencl_type_casting branch from e448d31 to c73f181 Compare April 15, 2022 09:50
Faced situation when generated OpenCL kernel contained the following if
condition:
```
if (uint4(...) && (int4(...) == int4(...)))
```

In this case, got the following error:
"can't convert between vector values of different size ('uint4' and 'int __attribute__((ext_vector_type(4)))')"

Added casts for binary ops. But it was necessary to modify `CastFromTo`
and add new method `CastTo`. Because with `CastFromTo` the following
code was generated:
```
if (uint4(...) && (convert_uint4(int4(...)) == convert_uint4(int4(...))))
```
But the OpenCL compiler still generated the same error.

This is why added new method `CastTo`. In this method we don't check the
current type of op and just add cast to a new type.

Finally the following code will be generated:
```
if (uint4(...) && convert_uint4(convert_uint4(int4(...)) == convert_uint4(int4(...))))
```
@echuraev echuraev force-pushed the echuraev/fix_opencl_type_casting branch from c73f181 to e2cb3e3 Compare April 15, 2022 09:59
@echuraev echuraev closed this Apr 15, 2022
@echuraev echuraev reopened this Apr 15, 2022
@echuraev echuraev closed this Apr 15, 2022
@echuraev echuraev reopened this Apr 15, 2022
@echuraev
Copy link
Contributor Author

Sorry, closed and opened this PR several times, due to on our branch I saw some problems with generated kernels. But all these problems were specific for our branch, because we have modified the codegen. This PR should work on the tvm/main.

@csullivan, @masahi, @comaniac please, review it.

@masahi masahi merged commit 8aafe5b into apache:main Apr 15, 2022
echuraev added a commit to echuraev/tvm that referenced this pull request Apr 18, 2022
echuraev added a commit to echuraev/tvm that referenced this pull request Apr 18, 2022
The previous PR apache#11021 was reverted in apache#11035 due
to it affected performance of generated OpenCL code.

This PR fixed the same issue but doesn't lead to performance
degradation. Tested on Resnet50_v2 network.
echuraev added a commit to echuraev/tvm that referenced this pull request Apr 19, 2022
Lucien0 pushed a commit to Lucien0/tvm that referenced this pull request Apr 19, 2022
Faced situation when generated OpenCL kernel contained the following if
condition:
```
if (uint4(...) && (int4(...) == int4(...)))
```

In this case, got the following error:
"can't convert between vector values of different size ('uint4' and 'int __attribute__((ext_vector_type(4)))')"

Added casts for binary ops. But it was necessary to modify `CastFromTo`
and add new method `CastTo`. Because with `CastFromTo` the following
code was generated:
```
if (uint4(...) && (convert_uint4(int4(...)) == convert_uint4(int4(...))))
```
But the OpenCL compiler still generated the same error.

This is why added new method `CastTo`. In this method we don't check the
current type of op and just add cast to a new type.

Finally the following code will be generated:
```
if (uint4(...) && convert_uint4(convert_uint4(int4(...)) == convert_uint4(int4(...))))
```
masahi pushed a commit that referenced this pull request Apr 19, 2022
echuraev added a commit to echuraev/tvm that referenced this pull request Apr 19, 2022
The previous PR apache#11021 was reverted in apache#11035 due
to it affected performance of generated OpenCL code.

This PR fixed the same issue but doesn't lead to performance
degradation. Tested on Resnet50_v2 network.
masahi pushed a commit that referenced this pull request Apr 19, 2022
* [OpenCL] Fix type casting

The previous PR #11021 was reverted in #11035 due
to it affected performance of generated OpenCL code.

This PR fixed the same issue but doesn't lead to performance
degradation. Tested on Resnet50_v2 network.

* Implement using select built-in
driazati pushed a commit to driazati/tvm that referenced this pull request Apr 19, 2022
* [OpenCL] Fix type casting

The previous PR apache#11021 was reverted in apache#11035 due
to it affected performance of generated OpenCL code.

This PR fixed the same issue but doesn't lead to performance
degradation. Tested on Resnet50_v2 network.

* Implement using select built-in
@echuraev echuraev deleted the echuraev/fix_opencl_type_casting branch April 20, 2022 05:42
altanh pushed a commit to altanh/tvm that referenced this pull request Apr 28, 2022
Faced situation when generated OpenCL kernel contained the following if
condition:
```
if (uint4(...) && (int4(...) == int4(...)))
```

In this case, got the following error:
"can't convert between vector values of different size ('uint4' and 'int __attribute__((ext_vector_type(4)))')"

Added casts for binary ops. But it was necessary to modify `CastFromTo`
and add new method `CastTo`. Because with `CastFromTo` the following
code was generated:
```
if (uint4(...) && (convert_uint4(int4(...)) == convert_uint4(int4(...))))
```
But the OpenCL compiler still generated the same error.

This is why added new method `CastTo`. In this method we don't check the
current type of op and just add cast to a new type.

Finally the following code will be generated:
```
if (uint4(...) && convert_uint4(convert_uint4(int4(...)) == convert_uint4(int4(...))))
```
altanh pushed a commit to altanh/tvm that referenced this pull request Apr 28, 2022
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.

2 participants