From e889b28ea4c223944c23fe8439bf4d75e9329777 Mon Sep 17 00:00:00 2001 From: Wenju He Date: Fri, 21 Nov 2025 05:38:48 +0100 Subject: [PATCH 1/6] Add clang patch to enable BFloat16 for SPIR/SPIR-V --- ...lang-Enable-BFloat16-for-SPIR-SPIR-V.patch | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 patches/clang/0001-Clang-Enable-BFloat16-for-SPIR-SPIR-V.patch diff --git a/patches/clang/0001-Clang-Enable-BFloat16-for-SPIR-SPIR-V.patch b/patches/clang/0001-Clang-Enable-BFloat16-for-SPIR-SPIR-V.patch new file mode 100644 index 00000000..f5dfa224 --- /dev/null +++ b/patches/clang/0001-Clang-Enable-BFloat16-for-SPIR-SPIR-V.patch @@ -0,0 +1,36 @@ +From 6e240c1b150b4623d126539320b00375f6ee4ed6 Mon Sep 17 00:00:00 2001 +From: Wenju He +Date: Fri, 21 Nov 2025 05:37:58 +0100 +Subject: [PATCH] [Clang] Enable BFloat16 for SPIR/SPIR-V + +--- + clang/lib/Basic/Targets/SPIR.h | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h +index 37cf9d7921ba..f593971bb3a0 100644 +--- a/clang/lib/Basic/Targets/SPIR.h ++++ b/clang/lib/Basic/Targets/SPIR.h +@@ -101,6 +101,9 @@ protected: + UseAddrSpaceMapMangling = true; + HasLegalHalfType = true; + HasFloat16 = true; ++ HasBFloat16 = true; ++ BFloat16Width = BFloat16Align = 16; ++ BFloat16Format = &llvm::APFloat::BFloat(); + // Define available target features + // These must be defined in sorted order! + NoAsmVariants = true; +@@ -384,9 +387,6 @@ public: + resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-" + "v96:128-v192:256-v256:256-v512:512-v1024:1024-G1-P4-A0"); + +- BFloat16Width = BFloat16Align = 16; +- BFloat16Format = &llvm::APFloat::BFloat(); +- + HasLegalHalfType = true; + HasFloat16 = true; + HalfArgsAndReturns = true; +-- +2.39.1 + From b97e79c9bf791909715b78d04ac1002d64b4e6d5 Mon Sep 17 00:00:00 2001 From: Wenju He Date: Fri, 21 Nov 2025 05:51:32 +0100 Subject: [PATCH 2/6] fix cmake typo --- cmake/modules/CMakeFunctions.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/CMakeFunctions.cmake b/cmake/modules/CMakeFunctions.cmake index 13a013c6..c13f2600 100644 --- a/cmake/modules/CMakeFunctions.cmake +++ b/cmake/modules/CMakeFunctions.cmake @@ -141,7 +141,7 @@ function(apply_patches repo_dir patches_dir base_revision target_branch) message(STATUS "[OPENCL-CLANG] Not present - ${patching_log}") endif() endforeach(patch) - elsef(patches_needed EQUAL 0) # The target branch already exists + elseif(patches_needed EQUAL 0) # The target branch already exists execute_process( # Check it out COMMAND ${GIT_EXECUTABLE} checkout ${target_branch} WORKING_DIRECTORY ${repo_dir} From e2bb5de0d5cb9b751c31e03dddc0fcf68e57bdd6 Mon Sep 17 00:00:00 2001 From: Wenju He Date: Sat, 22 Nov 2025 02:09:19 -0800 Subject: [PATCH 3/6] test --- ...r_fp64-guard-for-atomic_double-doubl.patch | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 patches/clang/0002-OpenCL-Add-cl_khr_fp64-guard-for-atomic_double-doubl.patch diff --git a/patches/clang/0002-OpenCL-Add-cl_khr_fp64-guard-for-atomic_double-doubl.patch b/patches/clang/0002-OpenCL-Add-cl_khr_fp64-guard-for-atomic_double-doubl.patch new file mode 100644 index 00000000..17e3c968 --- /dev/null +++ b/patches/clang/0002-OpenCL-Add-cl_khr_fp64-guard-for-atomic_double-doubl.patch @@ -0,0 +1,52 @@ +From 781b00ae47ac0ea57b62164e57ff426f8121aa1d Mon Sep 17 00:00:00 2001 +From: Wenju He +Date: Sat, 22 Nov 2025 01:58:02 -0800 +Subject: [PATCH] [OpenCL] Add cl_khr_fp64 guard for atomic_double/double in + cl_ext_float_atomics functions + +Fix downstream compile errors: +error: unknown type name 'atomic_double' +error: use of type 'double' requires cl_khr_fp64 support +--- + clang/lib/Headers/opencl-c.h | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h +index f65b4b314cff..39f91c139496 100644 +--- a/clang/lib/Headers/opencl-c.h ++++ b/clang/lib/Headers/opencl-c.h +@@ -13781,6 +13781,7 @@ float __ovld atomic_fetch_max_explicit(volatile atomic_float *, + defined(__opencl_c_ext_fp32_local_atomic_min_max) + + #if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics) ++#ifdef cl_khr_fp64 + #if defined(__opencl_c_ext_fp64_global_atomic_min_max) + double __ovld atomic_fetch_min(volatile __global atomic_double *, double); + double __ovld atomic_fetch_max(volatile __global atomic_double *, double); +@@ -13821,6 +13822,7 @@ double __ovld atomic_fetch_max_explicit(volatile atomic_double *, + double, memory_order, memory_scope); + #endif // defined(__opencl_c_ext_fp64_global_atomic_min_max) && \ + defined(__opencl_c_ext_fp64_local_atomic_min_max) ++#endif // cl_khr_fp64 + #endif // defined(cl_khr_int64_base_atomics) && \ + defined(cl_khr_int64_extended_atomics) + +@@ -13907,6 +13909,7 @@ float __ovld atomic_fetch_sub_explicit(volatile atomic_float *, + defined(__opencl_c_ext_fp32_local_atomic_add) + + #if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics) ++#ifdef cl_khr_fp64 + #if defined(__opencl_c_ext_fp64_global_atomic_add) + double __ovld atomic_fetch_add(volatile __global atomic_double *, double); + double __ovld atomic_fetch_sub(volatile __global atomic_double *, double); +@@ -13947,6 +13950,7 @@ double __ovld atomic_fetch_sub_explicit(volatile atomic_double *, + double, memory_order, memory_scope); + #endif // defined(__opencl_c_ext_fp64_global_atomic_add) && \ + defined(__opencl_c_ext_fp64_local_atomic_add) ++#endif // cl_khr_fp64 + #endif // defined(cl_khr_int64_base_atomics) && \ + defined(cl_khr_int64_extended_atomics) + +-- +2.39.1 + From 1fd5681a4cfd41f60a358874e5cc72a6b058a1f4 Mon Sep 17 00:00:00 2001 From: Wenju He Date: Sat, 22 Nov 2025 04:07:05 -0800 Subject: [PATCH 4/6] Revert "test" This reverts commit e2bb5de0d5cb9b751c31e03dddc0fcf68e57bdd6. --- ...r_fp64-guard-for-atomic_double-doubl.patch | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 patches/clang/0002-OpenCL-Add-cl_khr_fp64-guard-for-atomic_double-doubl.patch diff --git a/patches/clang/0002-OpenCL-Add-cl_khr_fp64-guard-for-atomic_double-doubl.patch b/patches/clang/0002-OpenCL-Add-cl_khr_fp64-guard-for-atomic_double-doubl.patch deleted file mode 100644 index 17e3c968..00000000 --- a/patches/clang/0002-OpenCL-Add-cl_khr_fp64-guard-for-atomic_double-doubl.patch +++ /dev/null @@ -1,52 +0,0 @@ -From 781b00ae47ac0ea57b62164e57ff426f8121aa1d Mon Sep 17 00:00:00 2001 -From: Wenju He -Date: Sat, 22 Nov 2025 01:58:02 -0800 -Subject: [PATCH] [OpenCL] Add cl_khr_fp64 guard for atomic_double/double in - cl_ext_float_atomics functions - -Fix downstream compile errors: -error: unknown type name 'atomic_double' -error: use of type 'double' requires cl_khr_fp64 support ---- - clang/lib/Headers/opencl-c.h | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h -index f65b4b314cff..39f91c139496 100644 ---- a/clang/lib/Headers/opencl-c.h -+++ b/clang/lib/Headers/opencl-c.h -@@ -13781,6 +13781,7 @@ float __ovld atomic_fetch_max_explicit(volatile atomic_float *, - defined(__opencl_c_ext_fp32_local_atomic_min_max) - - #if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics) -+#ifdef cl_khr_fp64 - #if defined(__opencl_c_ext_fp64_global_atomic_min_max) - double __ovld atomic_fetch_min(volatile __global atomic_double *, double); - double __ovld atomic_fetch_max(volatile __global atomic_double *, double); -@@ -13821,6 +13822,7 @@ double __ovld atomic_fetch_max_explicit(volatile atomic_double *, - double, memory_order, memory_scope); - #endif // defined(__opencl_c_ext_fp64_global_atomic_min_max) && \ - defined(__opencl_c_ext_fp64_local_atomic_min_max) -+#endif // cl_khr_fp64 - #endif // defined(cl_khr_int64_base_atomics) && \ - defined(cl_khr_int64_extended_atomics) - -@@ -13907,6 +13909,7 @@ float __ovld atomic_fetch_sub_explicit(volatile atomic_float *, - defined(__opencl_c_ext_fp32_local_atomic_add) - - #if defined(cl_khr_int64_base_atomics) && defined(cl_khr_int64_extended_atomics) -+#ifdef cl_khr_fp64 - #if defined(__opencl_c_ext_fp64_global_atomic_add) - double __ovld atomic_fetch_add(volatile __global atomic_double *, double); - double __ovld atomic_fetch_sub(volatile __global atomic_double *, double); -@@ -13947,6 +13950,7 @@ double __ovld atomic_fetch_sub_explicit(volatile atomic_double *, - double, memory_order, memory_scope); - #endif // defined(__opencl_c_ext_fp64_global_atomic_add) && \ - defined(__opencl_c_ext_fp64_local_atomic_add) -+#endif // cl_khr_fp64 - #endif // defined(cl_khr_int64_base_atomics) && \ - defined(cl_khr_int64_extended_atomics) - --- -2.39.1 - From 9856f3b200977a80b797e41f57081ee1a198a7af Mon Sep 17 00:00:00 2001 From: Wenju He Date: Sat, 22 Nov 2025 04:09:33 -0800 Subject: [PATCH 5/6] fix llvm version --- .github/workflows/on-push-verification-in-tree.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/on-push-verification-in-tree.yml b/.github/workflows/on-push-verification-in-tree.yml index 99bafd9c..a3fdc514 100644 --- a/.github/workflows/on-push-verification-in-tree.yml +++ b/.github/workflows/on-push-verification-in-tree.yml @@ -35,9 +35,19 @@ jobs: - name: Checkout opencl-clang sources for action files uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + # This step will fail when the branch naming scheme 'ocl-open-XXX' changes! + - name: Parse LLVM version from branch name + id: check-llvm-version + run: | + BRANCH="${{ github.base_ref }}" # on: pull_request, otherwise null + BRANCH=${BRANCH:-${{ github.ref_name }}} # on: push + LLVM_VERSION_LONG=$(echo $BRANCH | grep -oP '\d+') # Eg. 190 for LLVM 19 + LLVM_VERSION_SHORT=${LLVM_VERSION_LONG::-1} # Eg. 19 for LLVM 19 + echo "llvm_version=$LLVM_VERSION_SHORT" >> $GITHUB_OUTPUT + - name: Run build-opencl-clang action uses: ./.github/actions/build-opencl-clang with: - ref_llvm: main - ref_translator: main + ref_llvm: release/${{ steps.check-llvm-version.outputs.llvm_version }}.x + ref_translator: llvm_release_${{ steps.check-llvm-version.outputs.llvm_version }}0 ref_opencl-clang: ${{ github.ref }} From 881059e9db0e1e2ad54600ad7fc4c7a24a504f56 Mon Sep 17 00:00:00 2001 From: Wenju He Date: Mon, 24 Nov 2025 03:09:24 +0100 Subject: [PATCH 6/6] Revert "fix llvm version" This reverts commit 9856f3b200977a80b797e41f57081ee1a198a7af. --- .github/workflows/on-push-verification-in-tree.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/on-push-verification-in-tree.yml b/.github/workflows/on-push-verification-in-tree.yml index a3fdc514..99bafd9c 100644 --- a/.github/workflows/on-push-verification-in-tree.yml +++ b/.github/workflows/on-push-verification-in-tree.yml @@ -35,19 +35,9 @@ jobs: - name: Checkout opencl-clang sources for action files uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - # This step will fail when the branch naming scheme 'ocl-open-XXX' changes! - - name: Parse LLVM version from branch name - id: check-llvm-version - run: | - BRANCH="${{ github.base_ref }}" # on: pull_request, otherwise null - BRANCH=${BRANCH:-${{ github.ref_name }}} # on: push - LLVM_VERSION_LONG=$(echo $BRANCH | grep -oP '\d+') # Eg. 190 for LLVM 19 - LLVM_VERSION_SHORT=${LLVM_VERSION_LONG::-1} # Eg. 19 for LLVM 19 - echo "llvm_version=$LLVM_VERSION_SHORT" >> $GITHUB_OUTPUT - - name: Run build-opencl-clang action uses: ./.github/actions/build-opencl-clang with: - ref_llvm: release/${{ steps.check-llvm-version.outputs.llvm_version }}.x - ref_translator: llvm_release_${{ steps.check-llvm-version.outputs.llvm_version }}0 + ref_llvm: main + ref_translator: main ref_opencl-clang: ${{ github.ref }}