← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
ckernel_linear_checked.h File Reference
#include <stddef.h>

Go to the source code of this file.

Functions

int linear_rows_checked_f32 (const float *input, size_t input_elements, size_t input_stride, const float *weight, size_t weight_elements, size_t weight_stride, const float *bias, size_t bias_elements, float *output, size_t output_elements, size_t output_stride, size_t rows, size_t input_channels, size_t output_channels)
 

Function Documentation

◆ linear_rows_checked_f32()

int linear_rows_checked_f32 ( const float *  input,
size_t  input_elements,
size_t  input_stride,
const float *  weight,
size_t  weight_elements,
size_t  weight_stride,
const float *  bias,
size_t  bias_elements,
float *  output,
size_t  output_elements,
size_t  output_stride,
size_t  rows,
size_t  input_channels,
size_t  output_channels 
)

Definition at line 25 of file linear_rows_checked.c.

31{
32 if (!input || !weight || !bias || !output ||
33 !span_fits(rows, input_stride, input_channels, input_elements) ||
34 !span_fits(output_channels, weight_stride, input_channels, weight_elements) ||
35 !span_fits(rows, output_stride, output_channels, output_elements) ||
36 bias_elements < output_channels)
37 return -1;
38
39 /* Validate every accessed value and every result before the first write. */
40 for (size_t r = 0; r < rows; ++r)
41 for (size_t c = 0; c < input_channels; ++c)
42 if (!isfinite(input[r * input_stride + c])) return -1;
43 for (size_t o = 0; o < output_channels; ++o) {
44 if (!isfinite(bias[o])) return -1;
45 for (size_t c = 0; c < input_channels; ++c)
46 if (!isfinite(weight[o * weight_stride + c])) return -1;
47 }
48 for (size_t r = 0; r < rows; ++r)
49 for (size_t o = 0; o < output_channels; ++o) {
50 const double result = dot_bias(input + r * input_stride,
51 weight + o * weight_stride,
52 input_channels, bias[o]);
53 if (!isfinite(result) || fabs(result) > FLT_MAX) return -1;
54 }
55 for (size_t r = 0; r < rows; ++r)
56 for (size_t o = 0; o < output_channels; ++o)
57 output[r * output_stride + o] = (float)dot_bias(
58 input + r * input_stride, weight + o * weight_stride,
59 input_channels, bias[o]);
60 return 0;
61}
static int span_fits(size_t rows, size_t stride, size_t width, size_t elements)
static double dot_bias(const float *input, const float *weight, size_t width, float bias)

References dot_bias(), and span_fits().