[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
wenju-he wrote: > > LGTM. That means we compile for the last OpenCL version, which is 3.0, and > > enable all OpenCL extensions/features, right? > > Yes. Otherwise you have to still write the code to work with the lowest > common denominator. done in commit https://github.com/llvm/llvm-project/pull/135733/commits/b3653cdcfde00ece9ac929d6c0555c237e87ff86 https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
wenju-he wrote: > An OpenCL 1.2 module could still call a builtin that makes internal use of > CLC `ctz`, for example. Yes, you're right. https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
https://github.com/wenju-he updated
https://github.com/llvm/llvm-project/pull/135733
>From 64d7bfdceb5a0a6fbf34bb15cd7d6cbeb9214881 Mon Sep 17 00:00:00 2001
From: Wenju He
Date: Mon, 14 Apr 2025 19:20:25 -0700
Subject: [PATCH 1/5] [libclc] Set OpenCL version to 3.0
This PR is cherry-pick of https://github.com/intel/llvm/commit/cba338e5fb1c
This allows adding OpenCL 2.0 built-ins, e.g. ctz, and OpenCL 3.0
extension built-ins, including generic address space variants.
llvm-diff shows this PR has no change in amdgcn--amdhsa.bc.
---
libclc/CMakeLists.txt | 10 ++
1 file changed, 10 insertions(+)
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index dbbc29261d3b5..278ae5d777a84 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -411,6 +411,16 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR}/${arch_suffix}" )
file( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
+# OpenCL 3.0 extensions
+string(CONCAT CL_3_0_EXTENSIONS
+ "-cl-ext="
+ "+cl_khr_fp64,"
+ "+cl_khr_fp16,"
+ "+__opencl_c_3d_image_writes,"
+ "+__opencl_c_images,"
+ "+cl_khr_3d_image_writes")
+list( APPEND build_flags -cl-std=CL3.0 "-Xclang" ${CL_3_0_EXTENSIONS} )
+
string( TOUPPER "CLC_${MACRO_ARCH}" CLC_TARGET_DEFINE )
list( APPEND build_flags
>From 4facfec781e39a247aba639ea8e080aa79153a12 Mon Sep 17 00:00:00 2001
From: Wenju He
Date: Tue, 15 Apr 2025 20:56:40 -0700
Subject: [PATCH 2/5] set opencl_c_version per target, remove CL_3_0_EXTENSIONS
---
libclc/CMakeLists.txt | 32 +---
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 278ae5d777a84..e3093af57e728 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -387,7 +387,11 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
+ set( opencl_lang_std "CL3.0" )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
set( spvflags --spirv-max-version=1.1 )
@@ -395,13 +399,27 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
-elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
+elseif( ${DARCH} STREQUAL clspv )
+ # Refer to https://github.com/google/clspv for OpenCL version.
+ set( opencl_lang_std "CL3.0" )
set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
set( opt_flags -O3 )
set( MACRO_ARCH CLSPV32 )
if( ARCH STREQUAL clspv64 )
set( MACRO_ARCH CLSPV64 )
endif()
+elseif( ${DARCH} STREQUAL nvptx )
+ # Refer to https://www.khronos.org/opencl/ for OpenCL version in NV
implementation.
+ set( opencl_lang_std "CL3.0" )
+ set( build_flags )
+ set( opt_flags -O3 )
+ set( MACRO_ARCH ${ARCH} )
+elseif( ${DARCH} STREQUAL amdgcn OR ${DARCH} STREQUAL amdgcn-amdhsa OR
${DARCH} STREQUAL r600 )
+ # Refer to https://github.com/ROCm/clr/tree/develop/opencl for OpenCL
version.
+ set( opencl_lang_std "CL2.0" )
+ set( build_flags )
+ set( opt_flags -O3 )
+ set( MACRO_ARCH ${ARCH} )
else()
set( build_flags )
set( opt_flags -O3 )
@@ -411,15 +429,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR}/${arch_suffix}" )
file( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
-# OpenCL 3.0 extensions
-string(CONCAT CL_3_0_EXTENSIONS
- "-cl-ext="
- "+cl_khr_fp64,"
- "+cl_khr_fp16,"
- "+__opencl_c_3d_image_writes,"
- "+__opencl_c_images,"
- "+cl_khr_3d_image_writes")
-list( APPEND build_flags -cl-std=CL3.0 "-Xclang" ${CL_3_0_EXTENSIONS} )
+list( APPEND build_flags -cl-std=${opencl_lang_std} )
string( TOUPPER "CLC_${MACRO_ARCH}" CLC_TARGET_DEFINE )
>From 31604df0f2c7337d476878bc3245f452fe2c941b Mon Sep 17 00:00:00 2001
From: Wenju He
Date: Tue, 15 Apr 2025 21:05:57 -0700
Subject: [PATCH 3/5] use default OpenCL C version for r600
---
libclc/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index e3093af57e728..07da2466f5e42 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -414,7 +414,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( build_flags )
set( opt_flags -O3 )
set( MACRO_ARCH ${ARCH} )
-elseif( ${DARCH} STREQUAL amdgcn OR ${DARCH} STREQUAL amdgcn-amdhsa OR
${DARCH} STREQUAL r600 )
+elseif( ${DARCH} STREQUAL amdgcn OR ${DARCH} STREQUAL amdgcn-amdhsa )
# Refer to https://github.com/ROCm/clr/tree/develop/opencl for O
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
frasercrmck wrote: > LGTM. That means we compile for the last OpenCL version, which is 3.0, and > enable all OpenCL extensions/features, right? libclc is implemented using > functions supported by clang, so it is unlikely a target has libclc build > error in generic libclc files that are shared for all targets. When libclc is > linked to application module, libclc built-ins implementation of unsupported > extensions/features won't be linked in because these built-ins won't exist in > the user module. If the application code uses an unsupported extension, > frontend would report error already. There could be problem if application > modules links in a supported libclc built-in function which calls another > libclc built-in that belongs to unsupported special extension/feature, but I > think this scenario is unlikely and the supported built-in should be fixed to > not using unsupported feature. @frasercrmck What do you think? Sounds good to me. I hope that by having the internal CLC library we can largely avoid the last scenario, as CLC should be less dependent on the OpenCL C version. An OpenCL 1.2 module could still call a builtin that makes internal use of CLC `ctz`, for example. Anyway, sorry for complicating the PR with my suggestion. I was being unnecessarily conservative. https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
@@ -387,21 +387,39 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
+ set( opencl_lang_std "CL3.0" )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
set( spvflags --spirv-max-version=1.1 )
set( MACRO_ARCH SPIRV32 )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
-elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
+elseif( ${DARCH} STREQUAL clspv )
+ # Refer to https://github.com/google/clspv for OpenCL version.
+ set( opencl_lang_std "CL3.0" )
set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
set( opt_flags -O3 )
set( MACRO_ARCH CLSPV32 )
if( ARCH STREQUAL clspv64 )
set( MACRO_ARCH CLSPV64 )
endif()
+elseif( ${DARCH} STREQUAL nvptx )
+ # Refer to https://www.khronos.org/opencl/ for OpenCL version in NV
implementation.
+ set( opencl_lang_std "CL3.0" )
+ set( build_flags )
+ set( opt_flags -O3 )
+ set( MACRO_ARCH ${ARCH} )
+elseif( ${DARCH} STREQUAL amdgcn OR ${DARCH} STREQUAL amdgcn-amdhsa )
+ # Refer to https://github.com/ROCm/clr/tree/develop/opencl for OpenCL
version.
+ set( opencl_lang_std "CL2.0" )
wenju-he wrote:
> I thought we already picked out device compatible default versions in clang?
OpenCL C version is 1.2 for all targets by default in clang if the version
isn't specified in command line:
https://github.com/llvm/llvm-project/blob/b07c88563febdb62b82daad0480d7b6131bc54d4/clang/lib/Basic/LangStandards.cpp#L99
There is TargetInfo api setSupportedOpenCLOpts for target to define its
supported extensions and features.
https://github.com/llvm/llvm-project/pull/135733
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
arsenm wrote: > LGTM. That means we compile for the last OpenCL version, which is 3.0, and > enable all OpenCL extensions/features, right? Yes. Otherwise you have to still write the code to work with the lowest common denominator. https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
wenju-he wrote: > I'd expect the libclc build (or any other runtime support library) to > consistently use the same language version independent of the target. If the > target doesn't support that version (which IIRC isn't actually a hard error > anywhere) and fails to compile on some feature, those should be carved out > into separate version dependent build (as in, this isn't a compile target > property but a specific build target property) LGTM. That means we compile for the last OpenCL version, which is 3.0, and enable all OpenCL extensions/features, right? libclc is implemented using functions supported by clang, so it is unlikely a target has libclc build error in generic libclc files that are shared for all targets. When libclc is linked to application module, libclc built-ins implementation of unsupported extensions/features won't be linked in because these built-ins won't exist in the user module. If the application code uses an unsupported extension, frontend would report error already. There could be problem if application modules links in a supported libclc built-in function which calls another libclc built-in that belongs to unsupported special extension/feature, but I think this scenario is unlikely. @frasercrmck What do you think? https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
https://github.com/arsenm commented: I'd expect the libclc build (or any other runtime support library) to consistently use the same language version independent of the target. If the target doesn't support that version (which IIRC isn't actually a hard error anywhere) and fails to compile on some feature, those should be carved out into separate version dependent build (as in, this isn't a compile target property but a specific build target property) https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
@@ -387,21 +387,39 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
+ set( opencl_lang_std "CL3.0" )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
set( spvflags --spirv-max-version=1.1 )
set( MACRO_ARCH SPIRV32 )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
-elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
+elseif( ${DARCH} STREQUAL clspv )
+ # Refer to https://github.com/google/clspv for OpenCL version.
+ set( opencl_lang_std "CL3.0" )
set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
set( opt_flags -O3 )
set( MACRO_ARCH CLSPV32 )
if( ARCH STREQUAL clspv64 )
set( MACRO_ARCH CLSPV64 )
endif()
+elseif( ${DARCH} STREQUAL nvptx )
+ # Refer to https://www.khronos.org/opencl/ for OpenCL version in NV
implementation.
+ set( opencl_lang_std "CL3.0" )
+ set( build_flags )
+ set( opt_flags -O3 )
+ set( MACRO_ARCH ${ARCH} )
+elseif( ${DARCH} STREQUAL amdgcn OR ${DARCH} STREQUAL amdgcn-amdhsa )
+ # Refer to https://github.com/ROCm/clr/tree/develop/opencl for OpenCL
version.
+ set( opencl_lang_std "CL2.0" )
arsenm wrote:
I thought we already picked out device compatible default versions in clang?
https://github.com/llvm/llvm-project/pull/135733
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
wenju-he wrote: > Another question would be whether or not we should be advertising a 2.X or > 3.X library if we don't have all the builtins? Is this a degradation? That > might depend on downstream toolchains and if/how they react to versioning > info in the LLVM IR. We can incrementally add missing builtins. If we don't set the version, the newer builtins in libclc are not built at all and effectively dead code. https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
wenju-he wrote: > Yes I think on reflection it's probably okay to compile for the highest > supported OpenCL C version. Yeah I think libclc should compile for the version that target claims supporting. > I believe they're supersets of one another, so a 3.0 builtins library would > still contain all of the 1.2 builtins? I might be missing some of the nitty > gritty here though. 3.0 is backward compatible with 1.2,1.1,1.0. For other versions, it depends on whether target include the versions in [CL_DEVICE_OPENCL_C_ALL_VERSIONS](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#CL_DEVICE_OPENCL_C_ALL_VERSIONS) query. https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
@@ -387,21 +387,39 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
+ set( opencl_lang_std "CL3.0" )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
set( spvflags --spirv-max-version=1.1 )
set( MACRO_ARCH SPIRV32 )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
-elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
+elseif( ${DARCH} STREQUAL clspv )
+ # Refer to https://github.com/google/clspv for OpenCL version.
+ set( opencl_lang_std "CL3.0" )
set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
set( opt_flags -O3 )
set( MACRO_ARCH CLSPV32 )
if( ARCH STREQUAL clspv64 )
set( MACRO_ARCH CLSPV64 )
endif()
+elseif( ${DARCH} STREQUAL nvptx )
+ # Refer to https://www.khronos.org/opencl/ for OpenCL version in NV
implementation.
wenju-he wrote:
updated link to https://developer.nvidia.com/opencl
https://github.com/llvm/llvm-project/pull/135733
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
@@ -387,21 +387,39 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
wenju-he wrote:
done
https://github.com/llvm/llvm-project/pull/135733
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
https://github.com/wenju-he updated
https://github.com/llvm/llvm-project/pull/135733
>From 64d7bfdceb5a0a6fbf34bb15cd7d6cbeb9214881 Mon Sep 17 00:00:00 2001
From: Wenju He
Date: Mon, 14 Apr 2025 19:20:25 -0700
Subject: [PATCH 1/4] [libclc] Set OpenCL version to 3.0
This PR is cherry-pick of https://github.com/intel/llvm/commit/cba338e5fb1c
This allows adding OpenCL 2.0 built-ins, e.g. ctz, and OpenCL 3.0
extension built-ins, including generic address space variants.
llvm-diff shows this PR has no change in amdgcn--amdhsa.bc.
---
libclc/CMakeLists.txt | 10 ++
1 file changed, 10 insertions(+)
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index dbbc29261d3b5..278ae5d777a84 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -411,6 +411,16 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR}/${arch_suffix}" )
file( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
+# OpenCL 3.0 extensions
+string(CONCAT CL_3_0_EXTENSIONS
+ "-cl-ext="
+ "+cl_khr_fp64,"
+ "+cl_khr_fp16,"
+ "+__opencl_c_3d_image_writes,"
+ "+__opencl_c_images,"
+ "+cl_khr_3d_image_writes")
+list( APPEND build_flags -cl-std=CL3.0 "-Xclang" ${CL_3_0_EXTENSIONS} )
+
string( TOUPPER "CLC_${MACRO_ARCH}" CLC_TARGET_DEFINE )
list( APPEND build_flags
>From 4facfec781e39a247aba639ea8e080aa79153a12 Mon Sep 17 00:00:00 2001
From: Wenju He
Date: Tue, 15 Apr 2025 20:56:40 -0700
Subject: [PATCH 2/4] set opencl_c_version per target, remove CL_3_0_EXTENSIONS
---
libclc/CMakeLists.txt | 32 +---
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 278ae5d777a84..e3093af57e728 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -387,7 +387,11 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
+ set( opencl_lang_std "CL3.0" )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
set( spvflags --spirv-max-version=1.1 )
@@ -395,13 +399,27 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
-elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
+elseif( ${DARCH} STREQUAL clspv )
+ # Refer to https://github.com/google/clspv for OpenCL version.
+ set( opencl_lang_std "CL3.0" )
set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
set( opt_flags -O3 )
set( MACRO_ARCH CLSPV32 )
if( ARCH STREQUAL clspv64 )
set( MACRO_ARCH CLSPV64 )
endif()
+elseif( ${DARCH} STREQUAL nvptx )
+ # Refer to https://www.khronos.org/opencl/ for OpenCL version in NV
implementation.
+ set( opencl_lang_std "CL3.0" )
+ set( build_flags )
+ set( opt_flags -O3 )
+ set( MACRO_ARCH ${ARCH} )
+elseif( ${DARCH} STREQUAL amdgcn OR ${DARCH} STREQUAL amdgcn-amdhsa OR
${DARCH} STREQUAL r600 )
+ # Refer to https://github.com/ROCm/clr/tree/develop/opencl for OpenCL
version.
+ set( opencl_lang_std "CL2.0" )
+ set( build_flags )
+ set( opt_flags -O3 )
+ set( MACRO_ARCH ${ARCH} )
else()
set( build_flags )
set( opt_flags -O3 )
@@ -411,15 +429,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR}/${arch_suffix}" )
file( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
-# OpenCL 3.0 extensions
-string(CONCAT CL_3_0_EXTENSIONS
- "-cl-ext="
- "+cl_khr_fp64,"
- "+cl_khr_fp16,"
- "+__opencl_c_3d_image_writes,"
- "+__opencl_c_images,"
- "+cl_khr_3d_image_writes")
-list( APPEND build_flags -cl-std=CL3.0 "-Xclang" ${CL_3_0_EXTENSIONS} )
+list( APPEND build_flags -cl-std=${opencl_lang_std} )
string( TOUPPER "CLC_${MACRO_ARCH}" CLC_TARGET_DEFINE )
>From 31604df0f2c7337d476878bc3245f452fe2c941b Mon Sep 17 00:00:00 2001
From: Wenju He
Date: Tue, 15 Apr 2025 21:05:57 -0700
Subject: [PATCH 3/4] use default OpenCL C version for r600
---
libclc/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index e3093af57e728..07da2466f5e42 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -414,7 +414,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( build_flags )
set( opt_flags -O3 )
set( MACRO_ARCH ${ARCH} )
-elseif( ${DARCH} STREQUAL amdgcn OR ${DARCH} STREQUAL amdgcn-amdhsa OR
${DARCH} STREQUAL r600 )
+elseif( ${DARCH} STREQUAL amdgcn OR ${DARCH} STREQUAL amdgcn-amdhsa )
# Refer to https://github.com/ROCm/clr/tree/develop/opencl for O
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
@@ -387,21 +387,39 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
+ set( opencl_lang_std "CL3.0" )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
set( spvflags --spirv-max-version=1.1 )
set( MACRO_ARCH SPIRV32 )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
-elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
+elseif( ${DARCH} STREQUAL clspv )
+ # Refer to https://github.com/google/clspv for OpenCL version.
+ set( opencl_lang_std "CL3.0" )
set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
set( opt_flags -O3 )
set( MACRO_ARCH CLSPV32 )
if( ARCH STREQUAL clspv64 )
set( MACRO_ARCH CLSPV64 )
endif()
+elseif( ${DARCH} STREQUAL nvptx )
+ # Refer to https://www.khronos.org/opencl/ for OpenCL version in NV
implementation.
frasercrmck wrote:
I'm not sure who could verify this, or who even uses libclc built for nvptx.
https://github.com/llvm/llvm-project/pull/135733
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
@@ -387,21 +387,39 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
+ set( opencl_lang_std "CL3.0" )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
set( spvflags --spirv-max-version=1.1 )
set( MACRO_ARCH SPIRV32 )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
-elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
+elseif( ${DARCH} STREQUAL clspv )
+ # Refer to https://github.com/google/clspv for OpenCL version.
+ set( opencl_lang_std "CL3.0" )
set( build_flags "-Wno-unknown-assumption" -DCLC_CLSPV )
set( opt_flags -O3 )
set( MACRO_ARCH CLSPV32 )
if( ARCH STREQUAL clspv64 )
set( MACRO_ARCH CLSPV64 )
endif()
+elseif( ${DARCH} STREQUAL nvptx )
+ # Refer to https://www.khronos.org/opencl/ for OpenCL version in NV
implementation.
+ set( opencl_lang_std "CL3.0" )
+ set( build_flags )
+ set( opt_flags -O3 )
+ set( MACRO_ARCH ${ARCH} )
+elseif( ${DARCH} STREQUAL amdgcn OR ${DARCH} STREQUAL amdgcn-amdhsa )
+ # Refer to https://github.com/ROCm/clr/tree/develop/opencl for OpenCL
version.
+ set( opencl_lang_std "CL2.0" )
frasercrmck wrote:
CC @arsenm
https://github.com/llvm/llvm-project/pull/135733
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
@@ -387,21 +387,39 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
+ set( opencl_lang_std "CL3.0" )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
set( spvflags --spirv-max-version=1.1 )
set( MACRO_ARCH SPIRV32 )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
-elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
+elseif( ${DARCH} STREQUAL clspv )
+ # Refer to https://github.com/google/clspv for OpenCL version.
+ set( opencl_lang_std "CL3.0" )
frasercrmck wrote:
Does this look okay, @rjodinchr?
https://github.com/llvm/llvm-project/pull/135733
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
@@ -387,21 +387,39 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
frasercrmck wrote:
I'd prefer `if( DARCH STREQUAL spirv )` which better fits the current style.
https://github.com/llvm/llvm-project/pull/135733
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
@@ -387,21 +387,39 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
-if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
+# 1.2 is Clang's default OpenCL C language standard to compile for.
+set( opencl_lang_std "CL1.2" )
+
+if ( ${DARCH} STREQUAL spirv )
+ set( opencl_lang_std "CL3.0" )
frasercrmck wrote:
Does this look okay to you, @airlied?
https://github.com/llvm/llvm-project/pull/135733
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
https://github.com/frasercrmck commented: Yes I think on reflection it's probably okay to compile for the highest supported OpenCL C version. I believe they're supersets of one another, so a 3.0 builtins library would still contain all of the 1.2 builtins? I might be missing some of the nitty gritty here though. Another question would be whether or not we should be advertising a 2.X or 3.X library if we don't have all the builtins? Is this a degradation? That might depend on downstream toolchains and if/how they react to versioning info in the LLVM IR. https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
https://github.com/frasercrmck edited https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
wenju-he wrote: > Targets may even want to compile libclc for multiple different versions? That > might introduce extra complexity (we'd need "an extra loop", more compilation > time, new naming/versioning schemes for the build artifacts). An application may compile using different -cl-std version, but IIUC such usage is incompatible with a target which supports a specific OpenCL version. So compiling for the target's supported OpenCL version might be enough. https://github.com/llvm/llvm-project/pull/135733 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
