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

Go to the source code of this file.

Data Structures

struct  ck_audio_conv1d_job
 

Typedefs

typedef void(* ck_audio_conv1d_compute_fn) (const ck_audio_conv1d_job *, void *)
 

Functions

void audio_conv1d_compute_avx2 (const ck_audio_conv1d_job *job, void *unused)
 
int ck_audio_conv1d_checked_execute (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 input_channels, size_t output_channels, size_t input_frames, size_t kernel_size, size_t stride, size_t padding, size_t dilation, size_t output_frames, ck_audio_conv1d_compute_fn compute, void *compute_context)
 

Typedef Documentation

◆ ck_audio_conv1d_compute_fn

typedef void(* ck_audio_conv1d_compute_fn) (const ck_audio_conv1d_job *, void *)

Definition at line 24 of file audio_conv1d_checked_internal.h.

Function Documentation

◆ audio_conv1d_compute_avx2()

void audio_conv1d_compute_avx2 ( const ck_audio_conv1d_job *  job,
void *  unused 
)

◆ ck_audio_conv1d_checked_execute()

int ck_audio_conv1d_checked_execute ( 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  input_channels,
size_t  output_channels,
size_t  input_frames,
size_t  kernel_size,
size_t  stride,
size_t  padding,
size_t  dilation,
size_t  output_frames,
ck_audio_conv1d_compute_fn  compute,
void *  compute_context 
)

Definition at line 142 of file audio_conv1d_checked.c.

151 {
152 size_t input_span, output_span, weight_count, scratch_need;
153 if (!input_channels || !output_channels || !input_frames ||
154 !kernel_size || !stride || !dilation || !output_frames ||
155 input_channels > INT_MAX || output_channels > INT_MAX ||
156 input_frames > INT_MAX || kernel_size > INT_MAX ||
157 stride > INT_MAX || padding > INT_MAX || dilation > INT_MAX ||
158 output_frames > INT_MAX)
160 const int64_t effective_kernel = 1 +
161 ((int64_t)kernel_size - 1) * (int64_t)dilation;
162 const int64_t padded = (int64_t)input_frames +
163 2 * (int64_t)padding - effective_kernel;
164 if (padded < 0 || padded / stride + 1 != output_frames)
166 if (!ck_checked_span((size_t)input_channels, (size_t)input_frames,
167 input_stride, &input_span) ||
168 !ck_checked_span((size_t)output_channels, (size_t)output_frames,
169 output_stride, &output_span) ||
170 audio_conv1d_checked_workspace((size_t)input_channels,
171 (size_t)output_channels, (size_t)input_frames,
172 (size_t)output_frames, &scratch_need))
174 if ((size_t)output_channels > SIZE_MAX / (size_t)input_channels ||
175 (size_t)output_channels * (size_t)input_channels > SIZE_MAX / (size_t)kernel_size)
177 weight_count = (size_t)output_channels * (size_t)input_channels * (size_t)kernel_size;
178 if (weight_count > SIZE_MAX / sizeof(float)) return CK_AUDIO_CONV_CHECKED_OVERFLOW;
179 if (input_elements < input_span || weight_elements < weight_count ||
180 bias_elements < (size_t)output_channels || output_elements < output_span ||
181 scratch_elements < scratch_need)
183 if (!ck_checked_region(input, input_span) ||
184 !ck_checked_region(weight, weight_count) ||
185 !ck_checked_region(bias, (size_t)output_channels) ||
186 !ck_checked_region(output, output_span) ||
187 !ck_checked_region(scratch, scratch_need))
189 if (ck_checked_overlap(output, output_span, input, input_span) ||
190 ck_checked_overlap(output, output_span, weight, weight_count) ||
191 ck_checked_overlap(output, output_span, bias, (size_t)output_channels) ||
192 ck_checked_overlap(output, output_span, scratch, scratch_need) ||
193 ck_checked_overlap(scratch, scratch_need, input, input_span) ||
194 ck_checked_overlap(scratch, scratch_need, weight, weight_count) ||
195 ck_checked_overlap(scratch, scratch_need, bias, (size_t)output_channels))
197 if (!ck_checked_finite(weight, weight_count) ||
198 !ck_checked_finite(bias, (size_t)output_channels))
200 for (size_t channel = 0; channel < input_channels; ++channel)
201 if (!ck_checked_finite(input + (size_t)channel * input_stride,
202 (size_t)input_frames))
204 /* Validation and staged commit remain shared by both providers. */
205 const ck_audio_conv1d_job job = {input, weight, bias, scratch,
206 input_stride, input_channels, output_channels, input_frames,
207 kernel_size, stride, padding, dilation, output_frames, 0,
208 output_channels};
209 compute(&job, compute_context);
210 if (!ck_checked_finite(scratch, (size_t)output_channels * (size_t)output_frames))
212 for (size_t channel = 0; channel < output_channels; ++channel)
213 memcpy(output + (size_t)channel * output_stride,
214 scratch + (size_t)channel * (size_t)output_frames,
215 (size_t)output_frames * sizeof(float));
217}
int audio_conv1d_checked_workspace(size_t input_channels, size_t output_channels, size_t input_frames, size_t output_frames, size_t *scratch_elements)
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)
@ CK_AUDIO_CONV_CHECKED_OVERFLOW
@ CK_AUDIO_CONV_CHECKED_OK
@ CK_AUDIO_CONV_CHECKED_CAPACITY
@ CK_AUDIO_CONV_CHECKED_NONFINITE
@ CK_AUDIO_CONV_CHECKED_INVALID

References audio_conv1d_checked_workspace(), CK_AUDIO_CONV_CHECKED_CAPACITY, CK_AUDIO_CONV_CHECKED_INVALID, CK_AUDIO_CONV_CHECKED_NONFINITE, CK_AUDIO_CONV_CHECKED_OK, CK_AUDIO_CONV_CHECKED_OVERFLOW, ck_checked_finite(), ck_checked_overlap(), ck_checked_region(), and ck_checked_span().

Referenced by audio_conv1d_checked_channel_major_f32(), audio_conv1d_checked_channel_major_f32_avx2_fma(), audio_conv1d_checked_channel_major_f32_hwfma(), audio_conv1d_dilated_checked_channel_major_f32(), audio_conv1d_dilated_checked_channel_major_f32_avx2_fma(), audio_conv1d_dilated_checked_channel_major_f32_hwfma(), and audio_conv1d_parallel_checked_impl().