Skip to content

Add OpenCL 3.1 (-cl-std=CL3.1) support#752

Merged
wenju-he merged 1 commit into
intel:mainfrom
wenju-he:opencl-3.1
Jul 13, 2026
Merged

Add OpenCL 3.1 (-cl-std=CL3.1) support#752
wenju-he merged 1 commit into
intel:mainfrom
wenju-he:opencl-3.1

Conversation

@wenju-he

@wenju-he wenju-he commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Clang gained OpenCL 3.1 language version support (16d22173dbb1d) and, separately, promotes 6 extensions to OpenCL 3.1 core (f4aa82f80e00): cl_khr_extended_bit_ops, cl_khr_integer_dot_product, cl_khr_subgroup_extended_types, cl_khr_subgroup_rotate, cl_khr_subgroup_shuffle, cl_khr_subgroup_shuffle_relative. Their builtins in opencl-c.h are gated on OPENCL_C_VERSION >= CL_VERSION_3_1, which is only set correctly if the PCM used for CL3.1 was itself built with -cl-std=CL3.1.

Wire -cl-std=CL3.1 through the opencl-clang wrapper with its own set of precompiled headers (opencl-c-31-{spir,spir64}[-fp64].pcm) instead of reusing the CL3.0 PCMs, so the promoted builtins are visible under CL3.1 without requiring users to pass -cl-ext=+ explicitly.

Clang gained OpenCL 3.1 language version support (16d22173dbb1d) and,
separately, promotes 6 extensions to OpenCL 3.1 core (f4aa82f80e00):
cl_khr_extended_bit_ops, cl_khr_integer_dot_product,
cl_khr_subgroup_extended_types, cl_khr_subgroup_rotate,
cl_khr_subgroup_shuffle, cl_khr_subgroup_shuffle_relative. Their
builtins in opencl-c.h are gated on __OPENCL_C_VERSION__ >=
CL_VERSION_3_1, which is only set correctly if the PCM used for CL3.1
was itself built with -cl-std=CL3.1.

Wire -cl-std=CL3.1 through the opencl-clang wrapper with its own set
of precompiled headers (opencl-c-31-{spir,spir64}[-fp64].pcm) instead
of reusing the CL3.0 PCMs, so the promoted builtins are visible under
CL3.1 without requiring users to pass -cl-ext=+<extension> explicitly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread cl_headers/CMakeLists.txt
create_pcm(opencl-c-12-spir.pcm cl12spir opencl-c-base.h "${SPIR_TRIPLE};${CL12};${OPTS}" "${DEPS}")
create_pcm(opencl-c-20-spir.pcm cl20spir opencl-c-base.h "${SPIR_TRIPLE};${CL20};${OPTS}" "${DEPS}")
create_pcm(opencl-c-30-spir.pcm cl30spir opencl-c-base.h "${SPIR_TRIPLE};${CL30};${OPTS};${OPTS30}" "${DEPS}")
create_pcm(opencl-c-31-spir.pcm cl31spir opencl-c-base.h "${SPIR_TRIPLE};${CL31};${OPTS};${OPTS30}" "${DEPS}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we need to add an OPTS31 to include new optional features. Please refer to table in https://registry.khronos.org/OpenCL/specs/unified/html/OpenCL_C.html#features. Section 6.2.1 table 1.

new features are appended in the table after "__opencl_c_work_group_collective_functions"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

should they be added to OPTS30 instead? where is doc link that they are added for OpenCL 3.1?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to table name "Optional features in OpenCL C 3.0 or newer and their predefined macros". I agree that they be added to OPTS30.

The OpenCL C spec is updated incrementally. I believe that when OpenCL 3.0 spec was published several years ago. These new feature macros were not included.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will add to OPTS30 in separate PR, since OpenCL 3.1 doesn't explicit adds them.

wenju-he added a commit to llvm/llvm-project that referenced this pull request Jul 11, 2026
These extension checks apply to 3.1 as well.
This fix kernel build fails when OpenCL 3.1 is enabled in
intel/opencl-clang#752

Assisted-by: Claude
llvm-upstreamsync Bot pushed a commit to qualcomm/cpullvm-toolchain that referenced this pull request Jul 11, 2026
These extension checks apply to 3.1 as well.
This fix kernel build fails when OpenCL 3.1 is enabled in
intel/opencl-clang#752

Assisted-by: Claude
llvm-sync Bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 11, 2026
These extension checks apply to 3.1 as well.
This fix kernel build fails when OpenCL 3.1 is enabled in
intel/opencl-clang#752

Assisted-by: Claude
llvm-upstream-sync Bot pushed a commit to sriyalamar/cpullvm-toolchain that referenced this pull request Jul 11, 2026
These extension checks apply to 3.1 as well.
This fix kernel build fails when OpenCL 3.1 is enabled in
intel/opencl-clang#752

Assisted-by: Claude
@wenju-he wenju-he merged commit 2d56789 into intel:main Jul 13, 2026
4 of 7 checks passed
@wenju-he wenju-he deleted the opencl-3.1 branch July 14, 2026 00:25
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