Skip to content

Comments

Integer dot product translation#1174

Merged
svenvh merged 5 commits intoKhronosGroup:mainfrom
Quetzonarch:integer_dot_product_translation_fix
Jul 22, 2022
Merged

Integer dot product translation#1174
svenvh merged 5 commits intoKhronosGroup:mainfrom
Quetzonarch:integer_dot_product_translation_fix

Conversation

@Quetzonarch
Copy link
Contributor

@Quetzonarch Quetzonarch commented Aug 24, 2021

This proposed change is a fix for translation of IR from OCL-like source when dot function is called with integer arguments (ints or vectors of chars or shorts) to properly support cl_khr_integer_dot_product extension. Previously dot would always be translated to its version with floating point arguments. With this fix the call to dot function should be translated into a proper OpCode, based on the arguments used.

@CLAassistant
Copy link

CLAassistant commented Aug 24, 2021

CLA assistant check
All committers have signed the CLA.

@MrSidims
Copy link
Contributor

Approved for testing. @Quetzonarch could you please rebase your PR to exclude "Fix support of SPV_INTEL_vector_compute extension" from it as it was merged?

@Quetzonarch Quetzonarch force-pushed the integer_dot_product_translation_fix branch from f3c123f to 3e5ffbd Compare August 27, 2021 12:54
@StuartDBrady
Copy link
Contributor

StuartDBrady commented Oct 5, 2021

In my view, this optimization is beyond the scope of the SPIR-V/LLVM Translator, and should instead be implemented in spirv-opt (in SPIR-V Tools) and/or as part of a standalone optimizer for LLVM IR making use of OpenCL builtins. Such an optimizer could make use of the SPIR-V/LLVM Translator library interface, if needed, but it does not belong in this repository. It certainly shouldn't be enabled by default, given that 1) this is an optimization beyond the scope of the translator and 2) the translator needs to support consumers of SPIR-V that do not support the IDP extension.

@StuartDBrady
Copy link
Contributor

At first glance, the description led me to believe this was an optimization which was using pattern matching to detect cases where a floating point dot product has been used with floating point vectors that have been converted from integer vectors, i.e. optimizing OpDot(OpConvertStoF(some_int)) → OpSDot(some_int).

I now see that this is not what was intended, but that this is a correctness fix for translation of IR produced from source using the cl_khr_integer_dot_product extension. I haven't looked very closely at the tests, but the code looks fine as far as I can see. However, I'd request that the commit message and description be updated to make it clearer that this is adding support for cl_khr_integer_dot_product, rather than adding an optimization.

Copy link
Member

@svenvh svenvh left a comment

Choose a reason for hiding this comment

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

Like @StuartDBrady I initially also got misled by the description. As I understand now, this is not an optimization but actually fixing a bug in the translator: it currently translates calls such as dot(uchar4, uchar4) into OpDot %i8, which is wrong because OpDot only operates on floating point types. Clarifying in the description that the current behaviour is wrong would be great, as Stuart mentioned.

I think we should work towards accepting this PR and am keen to help; we've left this for too long!

@Quetzonarch I guess first you should try to rebase onto latest main and then you'll probably hit some issues. I have left some comments that should help you solve some problems that I expect will appear after rebasing, plus some other improvements.

@Quetzonarch
Copy link
Contributor Author

Thank you for the comments and suggestions regarding the change. Yes, the point of this is to fix incorrect translations of IR produced from source using the cl_khr_integer_dot_product extension, sorry for the misleading description. I've begun implementing suggested changes. I'll try to push the update as soon as possible.

@Quetzonarch Quetzonarch force-pushed the integer_dot_product_translation_fix branch from 96b0670 to 3e5ffbd Compare July 13, 2022 13:42
Added additional translation when dot function is called in OpenCL with
integer arguments (packed int or vectors of 4 chars or 2 shorts) so
that it's translated into proper OpCodes from
SPV_KHR_integer_dot_product extension and not OpDot, which works on
floats.
Added additional translation when dot function is called in OpenCL with
integer arguments (packed int or vectors of 4 chars or 2 shorts) so
that it's translated into proper OpCodes from
SPV_KHR_integer_dot_product extension and not OpDot, which works on
floats.
Fixed translation of IR from source when dot function is called
with integer arguments (ints, vectors of chars or shorts)
to properly support cl_khr_integer_dot_product extension.
Previously dot would always be translated to its version with floating
point arguments. Additionally updated with suggested changes.
@Quetzonarch Quetzonarch force-pushed the integer_dot_product_translation_fix branch from 3e5ffbd to e2c96a4 Compare July 14, 2022 15:48
@Quetzonarch
Copy link
Contributor Author

I've rebased the branch onto the latest main and applied suggested changes. Everything seemed to work alright, but some parts might need some additional checking (for example my use of mutateCallInstSPIRV function, as I wasn't too familiar with that one).

Copy link
Member

@svenvh svenvh left a comment

Choose a reason for hiding this comment

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

Thanks for the update @Quetzonarch! I've left a few more comments and the CI has found some issues; other than that it looks good to me.

Fixed some small mistakes in comments; added extension in tests and
changed one variable name to resolve CI issues. Additionally refactored
argument swapping as per suggestion.
@Quetzonarch Quetzonarch force-pushed the integer_dot_product_translation_fix branch from defcc8d to 08ac086 Compare July 21, 2022 13:37
@Quetzonarch
Copy link
Contributor Author

I've seen that CI had found some issues, so I've applied small changes to the last commit (slight code formatting in OCLToSPIRV and missing spir_func words in tests).

@svenvh svenvh merged commit c8cd2f6 into KhronosGroup:main Jul 22, 2022
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this pull request Jul 22, 2022
Fix translation of IR from source when dot function is called
with integer arguments (ints, vectors of chars or shorts)
to properly support cl_khr_integer_dot_product extension.
Previously it translated calls such as dot(uchar4, uchar4) into
OpDot %i8, which is wrong because OpDot only operates on
floating point types.

(cherry picked from commit c8cd2f6)
svenvh pushed a commit to svenvh/SPIRV-LLVM-Translator that referenced this pull request Jul 22, 2022
Fix translation of IR from source when dot function is called
with integer arguments (ints, vectors of chars or shorts)
to properly support cl_khr_integer_dot_product extension.
Previously it translated calls such as dot(uchar4, uchar4) into
OpDot %i8, which is wrong because OpDot only operates on
floating point types.

(cherry picked from commit c8cd2f6)
svenvh pushed a commit that referenced this pull request Jul 22, 2022
Fix translation of IR from source when dot function is called
with integer arguments (ints, vectors of chars or shorts)
to properly support cl_khr_integer_dot_product extension.
Previously it translated calls such as dot(uchar4, uchar4) into
OpDot %i8, which is wrong because OpDot only operates on
floating point types.

(cherry picked from commit c8cd2f6)
svenvh pushed a commit that referenced this pull request Nov 6, 2024
#1174 implements translating integer dot product OCL builtins to SPIR-V builtins. This pull request is to do the reverse translation.
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.

5 participants