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

Go to the source code of this file.

Functions

int ck_linear_rows_bias_bf16_avx2_panel_checked (const uint16_t *input, const uint16_t *weight, const uint16_t *bias, uint16_t *output, uint16_t *staged, double *packed, size_t input_elements, size_t weight_elements, size_t bias_elements, size_t output_elements, size_t packed_elements, size_t rows, size_t input_width, size_t output_width)

Function Documentation

◆ ck_linear_rows_bias_bf16_avx2_panel_checked()

int ck_linear_rows_bias_bf16_avx2_panel_checked ( const uint16_t * input,
const uint16_t * weight,
const uint16_t * bias,
uint16_t * output,
uint16_t * staged,
double * packed,
size_t input_elements,
size_t weight_elements,
size_t bias_elements,
size_t output_elements,
size_t packed_elements,
size_t rows,
size_t input_width,
size_t output_width )

Definition at line 91 of file linear_rows_bias_bf16_avx2_panel_checked.c.

96{
97#if defined(__AVX2__) && defined(__FMA__)
98 if (!rows || !input_width || !output_width || output_width > SIZE_MAX-(PANEL-1) ||
99 rows > SIZE_MAX/input_width || rows > SIZE_MAX/output_width ||
100 output_width > SIZE_MAX/input_width)
101 return -2;
102 const size_t padded = (output_width+PANEL-1)/PANEL*PANEL;
103 if (padded > SIZE_MAX/input_width || input_elements != rows*input_width ||
104 weight_elements != output_width*input_width || bias_elements != output_width ||
105 output_elements != rows*output_width || packed_elements != padded*input_width)
106 return -2;
107 const void *ptrs[] = {input,weight,bias,output,staged,packed};
108 const size_t sizes[] = {2,2,2,2,2,8};
109 const size_t counts[] = {input_elements,weight_elements,bias_elements,output_elements,output_elements,packed_elements};
110 for (size_t i = 0; i < 6; ++i) {
111 if (!region(ptrs[i],counts[i],sizes[i])) return -1;
112 if (i >= 3)
113 for (size_t j = 0; j < i; ++j)
114 if (overlaps(ptrs[i],counts[i]*sizes[i],ptrs[j],counts[j]*sizes[j])) return -1;
115 }
116 if (!finite_bf16(input,input_elements) || !finite_bf16(weight,weight_elements) ||
117 !finite_bf16(bias,bias_elements))
118 return -3;
119 struct project_panel projection = {input,weight,bias,staged,packed,rows,input_width,output_width,0};
120 ck_checked_parallel_for(padded/PANEL,2,panel_range,&projection);
121 if (atomic_load_explicit(&projection.failed,memory_order_relaxed)) return -3;
122 memcpy(output,staged,output_elements*sizeof(*output));
123 return 0;
124#else
125 (void)input; (void)weight; (void)bias; (void)output; (void)staged; (void)packed;
126 (void)input_elements; (void)weight_elements; (void)bias_elements; (void)output_elements;
127 (void)packed_elements; (void)rows; (void)input_width; (void)output_width;
128 return -4;
129#endif
130}
static int overlaps(const void *a, size_t an, const void *b, size_t bn)
static void ck_checked_parallel_for(size_t count, int grain, ck_checked_range_fn fn, void *args)
static int region(const void *p, size_t n)
static int finite_bf16(const uint16_t *p, size_t n)

References ck_checked_parallel_for(), finite_bf16(), overlaps(), PANEL, and region().