This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] Remove the need for subgroups extension pragma in enqueue kernel and pipe builtins
ClosedPublic

Authored by Anastasia on Apr 21 2021, 11:38 AM.

Details

Summary

There is no extension pragma requirement in the spec for these functions and all other builtin functions are available without the pragama.

This patch simplifies the parser and makes the language semantics consistent.

Diff Detail

Event Timeline

Anastasia created this revision.Apr 21 2021, 11:38 AM
Anastasia requested review of this revision.Apr 21 2021, 11:38 AM

I wish it could be true... But cl_khr_subgroups still requires pragma in some versions as it wasn't a core feature earlier (https://www.khronos.org/registry/OpenCL/sdk/2.2/docs/man/html/cl_khr_subgroups.html).

I know that we are going around in circles and we discussed this many times... But I see your point and this will definitely lead to overall simplification of OpenCL codebase in clang. Maybe we could add a comment into docs that we are deprecating pragmas?

I wish it could be true... But cl_khr_subgroups still requires pragma in some versions as it wasn't a core feature earlier (https://www.khronos.org/registry/OpenCL/sdk/2.2/docs/man/html/cl_khr_subgroups.html).

Btw I am not suggesting removing the pragma. We will still have to parse it for backward compatibility. I am only dropping the requirement of using it in order to call get_kernel_max_sub_group_size_for_ndrange or get_kernel_sub_group_count_for_ndrange when the extension is supported. Because I don't see why this would be needed especially that all other functions from subgroups can be called without the pragma https://godbolt.org/z/MYavchPT3.

Btw the newer extension specs don't contain the pragma e.g.
https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#_extended_subgroup_functions

I know that we are going around in circles and we discussed this many times... But I see your point and this will definitely lead to overall simplification of OpenCL codebase in clang. Maybe we could add a comment into docs that we are deprecating pragmas?

Right now we have the following in the docs: https://clang.llvm.org/docs/OpenCLSupport.html#implementation-guidelines

Note that some legacy extensions (published prior to OpenCL 3.0) still provide some non-conformant functionality for pragmas e.g. add diagnostics on the use of types or functions. This functionality is not guaranteed to remain in future releases. However, any future changes should not affect backward compatibility.

This is not quite deprecation but it makes it clear that the behavior can change as soon as backward compatibility is preserved.

Would you like us to add or ammend anything?

Btw I am not suggesting removing the pragma. We will still have to parse it for backward compatibility. I am only dropping the requirement of using it in order to call get_kernel_max_sub_group_size_for_ndrange or get_kernel_sub_group_count_for_ndrange when the extension is supported. Because I don't see why this would be needed especially that all other functions from subgroups can be called without the pragma https://godbolt.org/z/MYavchPT3.

Oh! I didn't get that! I see another one https://godbolt.org/z/3GPW31W9c, https://godbolt.org/z/dYasedxjx. This is also fixed with your patch, right?

Btw the newer extension specs don't contain the pragma e.g. https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_Ext.html#_extended_subgroup_functions

Indeed... No wording about pragma even in OpenCL C 2.0...

Right now we have the following in the docs: https://clang.llvm.org/docs/OpenCLSupport.html#implementation-guidelines

Note that some legacy extensions (published prior to OpenCL 3.0) still provide some non-conformant functionality for pragmas e.g. add diagnostics on the use of types or functions. This functionality is not guaranteed to remain in future releases. However, any future changes should not affect backward compatibility.

This is not quite deprecation but it makes it clear that the behavior can change as soon as backward compatibility is preserved.

Would you like us to add or ammend anything?

I think this fine for this change since the patch doesn't change anything but fixes a bug.

Anastasia added a comment.EditedApr 22 2021, 5:10 AM

Btw I am not suggesting removing the pragma. We will still have to parse it for backward compatibility. I am only dropping the requirement of using it in order to call get_kernel_max_sub_group_size_for_ndrange or get_kernel_sub_group_count_for_ndrange when the extension is supported. Because I don't see why this would be needed especially that all other functions from subgroups can be called without the pragma https://godbolt.org/z/MYavchPT3.

Oh! I didn't get that! I see another one https://godbolt.org/z/3GPW31W9c, https://godbolt.org/z/dYasedxjx. This is also fixed with your patch, right?

True, I have forgotten about those. :)

PS the patch fixes those too.

Anastasia retitled this revision from [OpenCL] Remove the need for subgroupd extension pragma in enqueue kernel builtins to [OpenCL] Remove the need for subgroups extension pragma in enqueue kernel builtins.Apr 22 2021, 5:29 AM
This revision is now accepted and ready to land.Apr 23 2021, 2:05 AM
mantognini accepted this revision.Apr 23 2021, 2:17 AM

Thanks, I believe this goes in the right direction.

Anastasia retitled this revision from [OpenCL] Remove the need for subgroups extension pragma in enqueue kernel builtins to [OpenCL] Remove the need for subgroups extension pragma in enqueue kernel and pipe builtins.Apr 23 2021, 3:49 AM
This revision was landed with ongoing or failed builds.May 6 2021, 6:00 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 6 2021, 6:00 AM
Herald added a subscriber: ldrumm. · View Herald Transcript