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

Go to the source code of this file.

Functions

int audio_conv1d_depthwise_channel_major_f32_checked (const float *input, size_t input_elements, size_t input_stride, const float *weight, size_t weight_elements, const float *bias, size_t bias_elements, float *output, size_t output_elements, size_t output_stride, float *scratch, size_t scratch_elements, size_t channels, size_t input_frames, size_t kernel_size, size_t stride, size_t output_frames)

Function Documentation

◆ audio_conv1d_depthwise_channel_major_f32_checked()

int audio_conv1d_depthwise_channel_major_f32_checked ( const float * input,
size_t input_elements,
size_t input_stride,
const float * weight,
size_t weight_elements,
const float * bias,
size_t bias_elements,
float * output,
size_t output_elements,
size_t output_stride,
float * scratch,
size_t scratch_elements,
size_t channels,
size_t input_frames,
size_t kernel_size,
size_t stride,
size_t output_frames )

Definition at line 9 of file audio_conv1d_depthwise_checked.c.

16 {
17 size_t input_span, output_span, weight_count, staged;
18 if (!channels || !input_frames || !kernel_size || !stride || !output_frames ||
19 input_frames < kernel_size ||
20 (input_frames - kernel_size) / stride + 1 != output_frames ||
21 channels > SIZE_MAX / kernel_size ||
22 channels > SIZE_MAX / output_frames)
23 return -2;
24 weight_count = channels * kernel_size;
25 staged = channels * output_frames;
26 if (!ck_checked_span(channels, input_frames, input_stride, &input_span) ||
27 !ck_checked_span(channels, output_frames, output_stride, &output_span) ||
28 weight_count > SIZE_MAX / sizeof(float) ||
29 staged > SIZE_MAX / sizeof(float))
30 return -2;
31 if (input_elements < input_span || weight_elements < weight_count ||
32 bias_elements < channels || output_elements < output_span ||
33 scratch_elements < staged)
34 return -3;
35 if (!ck_checked_region(input, input_span) ||
36 !ck_checked_region(weight, weight_count) ||
37 !ck_checked_region(bias, channels) ||
38 !ck_checked_region(output, output_span) ||
39 !ck_checked_region(scratch, staged) ||
40 ck_checked_overlap(output, output_span, input, input_span) ||
41 ck_checked_overlap(output, output_span, weight, weight_count) ||
42 ck_checked_overlap(output, output_span, bias, channels) ||
43 ck_checked_overlap(output, output_span, scratch, staged) ||
44 ck_checked_overlap(scratch, staged, input, input_span) ||
45 ck_checked_overlap(scratch, staged, weight, weight_count) ||
46 ck_checked_overlap(scratch, staged, bias, channels))
47 return -1;
48 if (!ck_checked_finite(weight, weight_count) ||
49 !ck_checked_finite(bias, channels))
50 return -4;
51 for (size_t c = 0; c < channels; ++c)
52 if (!ck_checked_finite(input + c * input_stride, input_frames))
53 return -4;
54 for (size_t c = 0; c < channels; ++c) {
55 for (size_t t = 0; t < output_frames; ++t) {
56 float sum = bias[c];
57 for (size_t k = 0; k < kernel_size; ++k)
58 sum = fmaf(input[c * input_stride + t * stride + k],
59 weight[c * kernel_size + k], sum);
60 scratch[c * output_frames + t] = sum;
61 }
62 }
63 if (!ck_checked_finite(scratch, staged)) return -4;
64 for (size_t c = 0; c < channels; ++c)
65 memcpy(output + c * output_stride, scratch + c * output_frames,
66 output_frames * sizeof(float));
67 return 0;
68}
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)

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