[libclc] [libclc] Set OpenCL C version for each target (PR #135733)
Wenju He via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 21 19:21:51 PDT 2025
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 <wenju.he at intel.com>
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 <wenju.he at intel.com>
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 <wenju.he at intel.com>
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 OpenCL version.
set( opencl_lang_std "CL2.0" )
set( build_flags )
>From 35cfd64ec9ff6cd10d57783224f62fe381c12cc9 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Wed, 16 Apr 2025 18:45:40 -0700
Subject: [PATCH 4/5] -> DARCH, update nv opencl version link
---
libclc/CMakeLists.txt | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 07da2466f5e42..1285a9d1fa513 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -390,7 +390,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# 1.2 is Clang's default OpenCL C language standard to compile for.
set( opencl_lang_std "CL1.2" )
- if ( ${DARCH} STREQUAL spirv )
+ if ( DARCH STREQUAL spirv )
set( opencl_lang_std "CL3.0" )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
@@ -399,7 +399,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
- elseif( ${DARCH} STREQUAL clspv )
+ 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 )
@@ -408,13 +408,13 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
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.
+ elseif( DARCH STREQUAL nvptx )
+ # Refer to https://developer.nvidia.com/opencl for OpenCL version.
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 )
+ 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" )
set( build_flags )
>From b3653cdcfde00ece9ac929d6c0555c237e87ff86 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Mon, 21 Apr 2025 19:20:28 -0700
Subject: [PATCH 5/5] Build for OpenCL 3.0, enable all extensions and features
---
libclc/CMakeLists.txt | 26 +++++---------------------
1 file changed, 5 insertions(+), 21 deletions(-)
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 1285a9d1fa513..cabb17128f245 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -387,11 +387,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS " device: ${d} ( ${${d}_aliases} )" )
- # 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" )
+ if ( ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
set( build_flags -O0 -finline-hint-functions -DCLC_SPIRV )
set( opt_flags )
set( spvflags --spirv-max-version=1.1 )
@@ -399,27 +395,13 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
if( ARCH STREQUAL spirv64 )
set( MACRO_ARCH SPIRV64 )
endif()
- elseif( DARCH STREQUAL clspv )
- # Refer to https://github.com/google/clspv for OpenCL version.
- set( opencl_lang_std "CL3.0" )
+ elseif( ARCH STREQUAL clspv OR ARCH STREQUAL clspv64 )
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://developer.nvidia.com/opencl for OpenCL version.
- 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" )
- set( build_flags )
- set( opt_flags -O3 )
- set( MACRO_ARCH ${ARCH} )
else()
set( build_flags )
set( opt_flags -O3 )
@@ -429,7 +411,9 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
set( LIBCLC_ARCH_OBJFILE_DIR "${LIBCLC_OBJFILE_DIR}/${arch_suffix}" )
file( MAKE_DIRECTORY ${LIBCLC_ARCH_OBJFILE_DIR} )
- list( APPEND build_flags -cl-std=${opencl_lang_std} )
+ # Build for OpenCL 3.0 and enable all extensions and features independently
+ # of the target or device.
+ list( APPEND build_flags -cl-std=CL3.0 -Xclang -cl-ext=+all )
string( TOUPPER "CLC_${MACRO_ARCH}" CLC_TARGET_DEFINE )
More information about the cfe-commits
mailing list