mirror of
https://github.com/karpathy/llm.c.git
synced 2026-07-27 20:25:09 -04:00
fixed numerics for online kernel, and an existing race condition in kernel 2
This commit is contained in:
parent
8fb966bc31
commit
c73fa8842a
1 changed files with 2 additions and 2 deletions
|
|
@ -143,8 +143,8 @@ __global__ void softmax_forward_kernel2(float* out, const float* inp, int N, int
|
|||
shared[tid] = fmaxf(shared[tid], shared[tid + stride]);
|
||||
}
|
||||
}
|
||||
float offset = shared[0];
|
||||
__syncthreads();
|
||||
float offset = shared[0];
|
||||
// compute expf and write the result to global memory
|
||||
for (int i = tid; i < C; i += block_size) {
|
||||
out[idx * C + i] = expf(x[i] - offset);
|
||||
|
|
@ -327,7 +327,7 @@ __global__ void softmax_forward_online_kernel1(float* out, const float* inp, int
|
|||
float* out_row = out + i * C;
|
||||
|
||||
float maxval = -INFINITY;
|
||||
float sum = 0.0f;
|
||||
double sum = 0.0f;
|
||||
for (int j = 0; j < C; j++) {
|
||||
float maxval_prev = maxval;
|
||||
if (inp_row[j] > maxval) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue