[HIP] DSpark brick 4b: recurrent Markov head GRU + corr/combine kernels + parity
- k_dspark_markov_gru: proj[3*rank]+bias -> gate=sigmoid, cand=tanh, state[r]=cand+gate*(state[r]-cand), latent[r]=tanh (GRU-style recurrent head). - k_dspark_corr_combine: combined = cur_step + corr_raw + hidden_out_bias. - Host wrappers + parity: GRU 7.6e-7 over a 3-step recurrence (state carries), corr_combine bit-exact. hip 43/43; CPU -D warnings green.
This commit is contained in:
1 parent
1b10258e6e
commit
142580e9ca
2 files changed
+132
No files matched your search
@@ -362,6 +362,57 @@ extern "C" int vetta_dspark_swiglu(const float* g, const float* u, float* out,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// DSpark recurrent Markov head GRU-style update. proj[3*rank] (already GEMV'd,
|
||||
// bias added here): gate=sigmoid(proj[r]), cand=tanh(proj[rank+r]),
|
||||
// state[r]=cand+gate*(state[r]-cand), latent[r]=tanh(proj[2*rank+r]).
|
||||
__global__ void k_dspark_markov_gru(const float* __restrict__ proj,
|
||||
const float* __restrict__ bias,
|
||||
float* __restrict__ state,
|
||||
float* __restrict__ latent, int rank) {
|
||||
const int r = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (r >= rank) return;
|
||||
const float p0 = proj[r] + bias[r];
|
||||
const float p1 = proj[rank + r] + bias[rank + r];
|
||||
const float p2 = proj[2 * rank + r] + bias[2 * rank + r];
|
||||
const float g = 1.f / (1.f + expf(-p0));
|
||||
const float cand = tanhf(p1);
|
||||
state[r] = cand + g * (state[r] - cand);
|
||||
latent[r] = tanhf(p2);
|
||||
}
|
||||
|
||||
extern "C" int vetta_dspark_markov_gru(const float* proj, const float* bias,
|
||||
float* state, float* latent, int rank,
|
||||
vetta_stream_t stream) {
|
||||
if (rank <= 0) return 1;
|
||||
const int t = 256;
|
||||
const int b = (rank + t - 1) / t;
|
||||
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
|
||||
k_dspark_markov_gru<<<b, t, 0, s>>>(proj, bias, state, latent, rank);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// combined[d] = cur_step[d] + corr_raw[d] + hidden_out_bias[d] (corr = how@latent).
|
||||
__global__ void k_dspark_corr_combine(const float* __restrict__ cur,
|
||||
const float* __restrict__ corr,
|
||||
const float* __restrict__ bias,
|
||||
float* __restrict__ out, int D) {
|
||||
const int d = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (d < D) out[d] = cur[d] + corr[d] + bias[d];
|
||||
}
|
||||
|
||||
extern "C" int vetta_dspark_corr_combine(const float* cur, const float* corr,
|
||||
const float* bias, float* out, int D,
|
||||
vetta_stream_t stream) {
|
||||
if (D <= 0) return 1;
|
||||
const int t = 256;
|
||||
const int b = (D + t - 1) / t;
|
||||
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
|
||||
k_dspark_corr_combine<<<b, t, 0, s>>>(cur, corr, bias, out, D);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- BF16 helpers ----------------------------------------------------------
|
||||
|
||||
__device__ __forceinline__ float bf16_to_f32(uint16_t h) {
|
||||
|
||||
Reference in new issue
Block a user