← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
gelu_rows_tanh_checked.c File Reference
#include "ckernel_normalization_checked.h"
#include "ckernel_engine.h"
#include "checked_float_buffer.h"
#include <string.h>

Go to the source code of this file.

Functions

int gelu_rows_tanh_checked_f32 (const float *input, size_t input_elements, size_t input_stride, float *output, size_t output_elements, size_t output_stride, float *scratch, size_t scratch_elements, size_t rows, size_t channels)
 

Function Documentation

◆ gelu_rows_tanh_checked_f32()

int gelu_rows_tanh_checked_f32 ( const float *  input,
size_t  input_elements,
size_t  input_stride,
float *  output,
size_t  output_elements,
size_t  output_stride,
float *  scratch,
size_t  scratch_elements,
size_t  rows,
size_t  channels 
)

Definition at line 5 of file gelu_rows_tanh_checked.c.

7 {
8 size_t ni, no, ns;
9 if (!ck_checked_span(rows, channels, input_stride, &ni) ||
10 !ck_checked_span(rows, channels, output_stride, &no) ||
11 !ck_checked_span(rows, channels, channels, &ns) ||
12 input_elements < ni || output_elements < no || scratch_elements < ns) return -2;
13 if (!ck_checked_region(input, ni) || !ck_checked_region(output, no) ||
14 !ck_checked_region(scratch, ns) || ck_checked_overlap(input, ni, output, no) ||
15 ck_checked_overlap(input, ni, scratch, ns) ||
16 ck_checked_overlap(output, no, scratch, ns)) return -1;
17 for (size_t r = 0; r < rows; ++r)
18 if (!ck_checked_finite(input + r * input_stride, channels)) return -3;
19 for (size_t r = 0; r < rows; ++r) {
20 memcpy(scratch + r * channels, input + r * input_stride, channels * sizeof(float));
21 /* Historical gelu_exact_inplace implements tanh GELU, matching gelu_new.
22 * This preserves its arithmetic; an erf provider is a different contract. */
23 gelu_exact_inplace(scratch + r * channels, channels);
24 }
25 if (!ck_checked_finite(scratch, ns)) return -4;
26 for (size_t r = 0; r < rows; ++r)
27 memcpy(output + r * output_stride, scratch + r * channels, channels * sizeof(float));
28 return 0;
29}
static int ck_checked_finite(const float *ptr, size_t n)
static int ck_checked_span(size_t rows, size_t width, size_t stride, size_t *span)
static int ck_checked_region(const float *ptr, size_t n)
static int ck_checked_overlap(const float *a, size_t na, const float *b, size_t nb)
void gelu_exact_inplace(float *data, size_t n)

References ck_checked_finite(), ck_checked_overlap(), ck_checked_region(), ck_checked_span(), and gelu_exact_inplace().