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)
167 input_stride, &input_span) ||
169 output_stride, &output_span) ||
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;
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)
200 for (size_t channel = 0; channel < input_channels; ++channel)
202 (size_t)input_frames))
204
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