8 size_t width, channels, weight_stride, packed_stride;
13 const struct nvfp4_projection *p = opaque;
15 const size_t row = begin / p->channels;
16 const size_t channel = begin % p->channels;
17 const size_t count =
end - begin < p->channels - channel ?
end - begin : p->channels - channel;
18 gemv_nvfp4_q8_0(p->staged + begin, p->weights + channel * p->weight_stride, NULL,
19 p->packed + row * p->packed_stride, (
int)
count, (
int)p->width);
25 const float *input,
size_t input_elements,
const void *weight,
size_t weight_bytes,
26 float *output,
size_t output_elements,
size_t rows,
size_t width,
size_t channels,
27 float *work,
size_t work_elements)
30 if (!width || width %
QK_NVFP4 || width > INT_MAX || channels > INT_MAX ||
33 input_elements < in || output_elements < out)
return -2;
36 if (channels > SIZE_MAX / weight_stride || weight_bytes != channels * weight_stride ||
37 rows > (SIZE_MAX - 3) / packed_stride)
return -2;
38 const size_t packed_elements = (rows * packed_stride + 3) / 4;
39 if (packed_elements > work_elements || out > work_elements - packed_elements)
return -2;
40 const size_t needed = packed_elements + out;
41 if (!weight || (uintptr_t)weight > UINTPTR_MAX - weight_bytes || !
ck_checked_region(input, in) ||
45 const uintptr_t src = (uintptr_t)weight, dst = (uintptr_t)output, tmp = (uintptr_t)work;
46 if ((dst < src + weight_bytes && src < dst + out *
sizeof(
float)) ||
47 (tmp < src + weight_bytes && src < tmp + needed *
sizeof(
float)))
return -1;
49 unsigned char *packed = (
unsigned char *)work;
50 for (
size_t row = 0; row < rows; ++row)
53 struct nvfp4_projection task = {
54 .weights = weight, .packed = packed, .staged = work + packed_elements, .width = width,
55 .channels = channels, .weight_stride = weight_stride, .packed_stride = packed_stride,
59 memcpy(output, task.staged, out *
sizeof(
float));
void gemv_nvfp4_q8_0(float *output, const void *weights, const float *weight_scales, const void *activations, int rows, int cols)
int linear_rows_nvfp4_q8_0_checked_f32(const float *input, size_t input_elements, const void *weight, size_t weight_bytes, float *output, size_t output_elements, size_t rows, size_t width, size_t channels, float *work, size_t work_elements)