c_josie_overlay

dev-util/radiance: fix clang-24 fp16/bf16 vector types

clang 24 makes __bf16/__fp16 distinct storage-only types, so the gfx12
WMMA/fdot2 builtins now demand short/_Float16 vector operands. Re-spell
the fragment typedefs in libr4d/r4d_dt16.h, libr4d/r4d_gdn_wmma.h and
libr4d/r4d_moe.hip (v8bf/mb_v8bf/rg_v8bf -> short; v8hf/v2hf ->
_Float16), keeping a separate __fp16 cvt2hf for cvt_pkrtz's return.

Verified: all 80 libr4d/*.hip compile clean with clang 24 for gfx1200
(-Wall -Wextra, -ffp-contract=off).

b6064458ad377c790a646e0fde5f710b5e55ae2c
cjosie <administrator@josie-c.com> · 2026-10-14T22:23 · browse files at this commit

parents: 3e4e9d3

diff --git a/dev-util/radiance/files/radiance-1.5.0-clang-24-vector-types.patch b/dev-util/radiance/files/radiance-1.5.0-clang-24-vector-types.patch
new file mode 100644
index 0000000..7d0a903
--- /dev/null
+++ b/dev-util/radiance/files/radiance-1.5.0-clang-24-vector-types.patch
@@ -0,0 +1,74 @@
+diff --git a/libr4d/r4d_dt16.h b/libr4d/r4d_dt16.h
+index 4688b73..2fd9c92 100644
+--- a/libr4d/r4d_dt16.h
++++ b/libr4d/r4d_dt16.h
+@@ -9,9 +9,12 @@
+ #pragma once
+ #include "r4d_common.h"
+ 
+-typedef __bf16   v8bf __attribute__((ext_vector_type(8)));
+-typedef __fp16   v8hf __attribute__((ext_vector_type(8)));  // what the f16 WMMA builtin takes
+-typedef __fp16   v2hf __attribute__((ext_vector_type(2)));  // what cvt_pkrtz returns
++// clang 24 treats __bf16/__fp16 as distinct storage-only types, so the vector operands
++// the WMMA/fdot2 builtins take must be spelled short/_Float16 exactly as declared.
++typedef short    v8bf __attribute__((ext_vector_type(8)));  // 8 bf16, as the bf16 WMMA builtin takes them
++typedef _Float16 v8hf __attribute__((ext_vector_type(8)));  // what the f16 WMMA builtin takes
++typedef _Float16 v2hf __attribute__((ext_vector_type(2)));  // what fdot2 takes
++typedef __fp16   cvt2hf __attribute__((ext_vector_type(2))); // what cvt_pkrtz returns
+ 
+ // GROW = how many octaves the running row max may exceed the REFERENCE max before the
+ // accumulator has to be rescaled. p = 2^(s - m_ref) must stay inside the format, so GROW is
+@@ -53,15 +56,15 @@ template<> struct DT16<1> {                       // f16: 3 more mantissa bits,
+         return __builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12(a, b, c);
+     }
+     __device__ __forceinline__ static uint32_t pk(float x, float y) {
+-        union { v2hf h; uint32_t u; } q; q.h = __builtin_amdgcn_cvt_pkrtz(x, y); return q.u;
++        union { cvt2hf h; uint32_t u; } q; q.h = __builtin_amdgcn_cvt_pkrtz(x, y); return q.u;
+     }
+     __device__ __forceinline__ static uint32_t pkv(v2f x) {
+         union { v2f f; float e[2]; } s; s.f = x;
+-        union { v2hf h; uint32_t u; } q; q.h = __builtin_amdgcn_cvt_pkrtz(s.e[0], s.e[1]); return q.u;
++        union { cvt2hf h; uint32_t u; } q; q.h = __builtin_amdgcn_cvt_pkrtz(s.e[0], s.e[1]); return q.u;
+     }
+     // two bf16 in a dword -> two f16 in a dword. bf16->f32 is a shift, so this is 3 VALU.
+     __device__ __forceinline__ static uint32_t from_bf16w(uint32_t w) {
+-        union { v2hf h; uint32_t u; } q;
++        union { cvt2hf h; uint32_t u; } q;
+         q.h = __builtin_amdgcn_cvt_pkrtz(__builtin_bit_cast(float, w << 16),
+                                          __builtin_bit_cast(float, w & 0xffff0000u));
+         return q.u;
+diff --git a/libr4d/r4d_gdn_wmma.h b/libr4d/r4d_gdn_wmma.h
+index 2c4923e..c02266d 100644
+--- a/libr4d/r4d_gdn_wmma.h
++++ b/libr4d/r4d_gdn_wmma.h
+@@ -7,7 +7,7 @@
+ #pragma once
+ #include <hip/hip_runtime.h>
+ 
+-typedef __bf16 v8bf __attribute__((ext_vector_type(8)));
++typedef short  v8bf __attribute__((ext_vector_type(8)));  /* 8 bf16, as the builtin takes them (clang 24) */
+ typedef float  v8f  __attribute__((ext_vector_type(8)));
+ 
+ // gfx1201 has no bf16 convert instruction, so this is software. Round-half-away
+diff --git a/libr4d/r4d_moe.hip b/libr4d/r4d_moe.hip
+index 384c9d1..7fd5275 100644
+--- a/libr4d/r4d_moe.hip
++++ b/libr4d/r4d_moe.hip
+@@ -2226,7 +2226,7 @@ static_assert(MoeDnArgs::count <= RAD_MAX_KPARAMS,
+ constexpr uint32_t kBK16 = 64;            // bf16 K elements staged per pass
+ constexpr uint32_t kP16  = kBK16 + 8;     // the LDS row pitch, in elements
+ 
+-typedef __bf16 mb_v8bf __attribute__((ext_vector_type(8)));
++typedef short  mb_v8bf __attribute__((ext_vector_type(8)));
+ typedef float  mb_v8f  __attribute__((ext_vector_type(8)));
+ 
+ __device__ __forceinline__ mb_v8f mb_mma(mb_v8bf a, mb_v8bf b, mb_v8f c) {
+@@ -3894,7 +3894,7 @@ namespace {
+ 
+ constexpr int kRgKU = 8;                  /* r4d_gemm_bf16_nt_m64's KU: the unroll, not the order */
+ 
+-typedef __bf16 rg_v8bf __attribute__((ext_vector_type(8)));
++typedef short  rg_v8bf __attribute__((ext_vector_type(8)));
+ typedef float  rg_v8f  __attribute__((ext_vector_type(8)));
+ /* Global-address-space pointer for the fragment loads, as r4d_gemm_bf16_nt_m64.hip holds it. */
+ typedef __attribute__((address_space(1))) const unsigned long long* rg_gu2;
diff --git a/dev-util/radiance/radiance-1.5.0.ebuild b/dev-util/radiance/radiance-1.5.0.ebuild
index 1e35b0e..52a378b 100644
--- a/dev-util/radiance/radiance-1.5.0.ebuild
+++ b/dev-util/radiance/radiance-1.5.0.ebuild
@@ -33,6 +33,12 @@ RDEPEND="
 
 DOCS=( README.md )
 
+PATCHES=(
+	# clang 24 makes __bf16/__fp16 distinct storage-only types; the WMMA/fdot2
+	# builtins now demand short/_Float16 vector operands.
+	"${FILESDIR}/${PN}-1.5.0-clang-24-vector-types.patch"
+)
+
 src_configure() {
 	# radiance's CMake locates hipcc itself and drives it as the device compiler.
 	# Do not call rocm_use_hipcc: forcing CC/CXX=hipcc compiles host code for amdgcn.