fix(cuda): preserve runtime theta lowering for QSA parity
This commit is contained in:
@@ -30,6 +30,15 @@
|
||||
#include <cuda_fp16.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
// Native theta is a runtime kernel parameter. Preserve its hardware approximate
|
||||
// LG2 lowering: a literal operand is constant-folded to a different float word.
|
||||
// Private module storage has no product write path or caller-selectable value.
|
||||
namespace {
|
||||
__device__ volatile uint32_t qsa_theta_word = 0x3f1ab32bu;
|
||||
__device__ __forceinline__ float runtime_theta_scale(){
|
||||
return __uint_as_float(qsa_theta_word);
|
||||
}
|
||||
}
|
||||
__device__ __forceinline__ float failure(){return __uint_as_float(0x7fc00000u);}
|
||||
__device__ __forceinline__ float warp_sum(float x){
|
||||
#pragma unroll
|
||||
@@ -60,7 +69,7 @@ template<int W> __device__ void rope_row(const float*x,uint32_t position,float*y
|
||||
int row=blockIdx.y,pair=threadIdx.x;if(pair>=W/2)return;size_t start=size_t(row)*W;
|
||||
if(pair>=32){y[start+2*pair]=x[start+2*pair];y[start+2*pair+1]=x[start+2*pair+1];return;}
|
||||
// Original host powf(1e7f,-2.f/64): exact word independently checked in build receipt.
|
||||
const float theta_scale=__uint_as_float(0x3f1ab32bu);
|
||||
const float theta_scale=runtime_theta_scale();
|
||||
float theta=float(position)*powf(theta_scale,float(pair));float c=cosf(theta),s=sinf(theta);
|
||||
float a=x[start+pair],b=x[start+pair+32];float lo=a*c-b*s,hi=a*s+b*c;
|
||||
y[start+pair]=isfinite(lo)?lo:failure();y[start+pair+32]=isfinite(hi)?hi:failure();
|
||||
@@ -95,7 +104,7 @@ extern "C" __global__ void leleka_qsa_index_append(const float*raw,const float*g
|
||||
if(d<128){values[d]=scale*mean*gamma[d];if(!isfinite(values[d]))atomicOr(&bad,1);}
|
||||
__syncthreads();if(d>=128)return;
|
||||
float y=values[d];if(d<64){int pair=d%32;uint32_t rope_pos=pos==0?0:4*(pos/4);
|
||||
float theta=float(rope_pos)*powf(__uint_as_float(0x3f1ab32bu),float(pair));float c=cosf(theta),s=sinf(theta);
|
||||
float theta=float(rope_pos)*powf(runtime_theta_scale(),float(pair));float c=cosf(theta),s=sinf(theta);
|
||||
float a=values[pair],z=values[pair+32];y=d<32?a*c-z*s:a*s+z*c;}
|
||||
y=bad||!isfinite(y)?failure():y;
|
||||
next[512+d]=y;if(pos==0)next[384+d]=y;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
// Generated candidate from matching owned CU; source/compiler receipts retained.
|
||||
// Fixed private volatile theta load preserves original runtime approximate LG2.
|
||||
// No device qualification or asset admission is implied.
|
||||
//
|
||||
// Generated by NVIDIA NVVM Compiler
|
||||
@@ -45,6 +46,7 @@
|
||||
.shared .align 4 .u32 _ZZ8norm_rowILi256EEvPKfS1_PfE3bad;
|
||||
// _ZZ8norm_rowILi128EEvPKfS1_PfE4sums has been demoted
|
||||
// _ZZ8norm_rowILi128EEvPKfS1_PfE3bad has been demoted
|
||||
.global .align 4 .u32 _ZN49_INTERNAL_6fd67985_18_qwen_qsa_native_cu_b8d66bf451_GLOBAL__N__6fd67985_18_qwen_qsa_native_cu_b8d66bf414qsa_theta_wordE = 1058714411;
|
||||
|
||||
.visible .entry leleka_qsa_split_q_gate(
|
||||
.param .u64 leleka_qsa_split_q_gate_param_0,
|
||||
@@ -562,13 +564,13 @@ $L__BB3_16:
|
||||
st.global.f32 [%rd10+4], %f22;
|
||||
bra.uni $L__BB4_4;
|
||||
$L__BB4_3:
|
||||
cvt.rn.f32.u32 %f1, %r3;
|
||||
cvt.rn.f32.u32 %f2, %r1;
|
||||
mov.f32 %f3, 0f3F1AB32B;
|
||||
lg2.approx.ftz.f32 %f4, %f3;
|
||||
mul.ftz.f32 %f5, %f4, %f2;
|
||||
ld.volatile.global.f32 %f1, [_ZN49_INTERNAL_6fd67985_18_qwen_qsa_native_cu_b8d66bf451_GLOBAL__N__6fd67985_18_qwen_qsa_native_cu_b8d66bf414qsa_theta_wordE];
|
||||
cvt.rn.f32.u32 %f2, %r3;
|
||||
cvt.rn.f32.u32 %f3, %r1;
|
||||
lg2.approx.ftz.f32 %f4, %f1;
|
||||
mul.ftz.f32 %f5, %f4, %f3;
|
||||
ex2.approx.ftz.f32 %f6, %f5;
|
||||
mul.ftz.f32 %f7, %f6, %f1;
|
||||
mul.ftz.f32 %f7, %f6, %f2;
|
||||
cos.approx.ftz.f32 %f8, %f7;
|
||||
sin.approx.ftz.f32 %f9, %f7;
|
||||
add.s32 %r5, %r2, %r1;
|
||||
@@ -629,13 +631,13 @@ $L__BB4_4:
|
||||
st.global.f32 [%rd10+4], %f22;
|
||||
bra.uni $L__BB5_4;
|
||||
$L__BB5_3:
|
||||
cvt.rn.f32.u32 %f1, %r3;
|
||||
cvt.rn.f32.u32 %f2, %r1;
|
||||
mov.f32 %f3, 0f3F1AB32B;
|
||||
lg2.approx.ftz.f32 %f4, %f3;
|
||||
mul.ftz.f32 %f5, %f4, %f2;
|
||||
ld.volatile.global.f32 %f1, [_ZN49_INTERNAL_6fd67985_18_qwen_qsa_native_cu_b8d66bf451_GLOBAL__N__6fd67985_18_qwen_qsa_native_cu_b8d66bf414qsa_theta_wordE];
|
||||
cvt.rn.f32.u32 %f2, %r3;
|
||||
cvt.rn.f32.u32 %f3, %r1;
|
||||
lg2.approx.ftz.f32 %f4, %f1;
|
||||
mul.ftz.f32 %f5, %f4, %f3;
|
||||
ex2.approx.ftz.f32 %f6, %f5;
|
||||
mul.ftz.f32 %f7, %f6, %f1;
|
||||
mul.ftz.f32 %f7, %f6, %f2;
|
||||
cos.approx.ftz.f32 %f8, %f7;
|
||||
sin.approx.ftz.f32 %f9, %f7;
|
||||
add.s32 %r5, %r2, %r1;
|
||||
@@ -696,13 +698,13 @@ $L__BB5_4:
|
||||
st.global.f32 [%rd10+4], %f22;
|
||||
bra.uni $L__BB6_4;
|
||||
$L__BB6_3:
|
||||
cvt.rn.f32.u32 %f1, %r3;
|
||||
cvt.rn.f32.u32 %f2, %r1;
|
||||
mov.f32 %f3, 0f3F1AB32B;
|
||||
lg2.approx.ftz.f32 %f4, %f3;
|
||||
mul.ftz.f32 %f5, %f4, %f2;
|
||||
ld.volatile.global.f32 %f1, [_ZN49_INTERNAL_6fd67985_18_qwen_qsa_native_cu_b8d66bf451_GLOBAL__N__6fd67985_18_qwen_qsa_native_cu_b8d66bf414qsa_theta_wordE];
|
||||
cvt.rn.f32.u32 %f2, %r3;
|
||||
cvt.rn.f32.u32 %f3, %r1;
|
||||
lg2.approx.ftz.f32 %f4, %f1;
|
||||
mul.ftz.f32 %f5, %f4, %f3;
|
||||
ex2.approx.ftz.f32 %f6, %f5;
|
||||
mul.ftz.f32 %f7, %f6, %f1;
|
||||
mul.ftz.f32 %f7, %f6, %f2;
|
||||
cos.approx.ftz.f32 %f8, %f7;
|
||||
sin.approx.ftz.f32 %f9, %f7;
|
||||
add.s32 %r5, %r2, %r1;
|
||||
@@ -1002,10 +1004,10 @@ $L__BB8_28:
|
||||
@%p42 bra $L__BB8_33;
|
||||
and.b32 %r44, %r7, -4;
|
||||
cvt.rn.f32.u32 %f77, %r44;
|
||||
cvt.rn.f32.u32 %f78, %r5;
|
||||
mov.f32 %f79, 0f3F1AB32B;
|
||||
lg2.approx.ftz.f32 %f80, %f79;
|
||||
mul.ftz.f32 %f81, %f80, %f78;
|
||||
ld.volatile.global.f32 %f78, [_ZN49_INTERNAL_6fd67985_18_qwen_qsa_native_cu_b8d66bf451_GLOBAL__N__6fd67985_18_qwen_qsa_native_cu_b8d66bf414qsa_theta_wordE];
|
||||
cvt.rn.f32.u32 %f79, %r5;
|
||||
lg2.approx.ftz.f32 %f80, %f78;
|
||||
mul.ftz.f32 %f81, %f80, %f79;
|
||||
ex2.approx.ftz.f32 %f82, %f81;
|
||||
mul.ftz.f32 %f83, %f82, %f77;
|
||||
cos.approx.ftz.f32 %f15, %f83;
|
||||
|
||||
Reference in New Issue
Block a user