Packed NVFP4 weight kernels for CPU inference. More...
#include <assert.h>#include <math.h>#include <stddef.h>#include <stdint.h>#include <string.h>#include "ck_threadpool.h"#include "ckernel_quant.h"Go to the source code of this file.
Functions | |
| static int | ck_moe_swiglu_nvfp4_projection (const float *hidden, const void *gate, float gate_scale, const void *up, float up_scale, const void *down, float down_scale, float *result, int hidden_dim, int intermediate_dim, void *workspace) |
| static size_t | ck_nvfp4_align64 (size_t value) |
| static void | ck_nvfp4_gemv_rows (int begin, int end, void *opaque) |
| float | ck_ue4m3_to_fp32 (uint8_t value) |
| static float | ck_ue4m3_to_fp32_inline (uint8_t value) |
| void | dequantize_row_nvfp4 (const void *weights, float *output, int k, float weight_scale) |
| void | gemv_nvfp4_q8_0 (float *output, const void *weights, const float *weight_scales, const void *activations, int rows, int cols) |
| static void | gemv_nvfp4_q8_0_uniform (float *output, const void *weights, float weight_scale, const void *activations, int rows, int cols) |
| int | moe_swiglu_expert_forward_nvfp4_workspace (const float *hidden, const int *indices, const float *routing_weights, const void *expert_gate, const float *expert_gate_scales, const void *expert_up, const float *expert_up_scales, const void *expert_down, const float *expert_down_scales, float *output, int rows, int hidden_dim, int intermediate_dim, int n_experts, int top_k, void *workspace, size_t workspace_bytes) |
| size_t | moe_swiglu_nvfp4_workspace_bytes (int hidden_dim, int intermediate_dim) |
| int | moe_swiglu_shared_forward_nvfp4_workspace (const float *hidden, const float *routed, const void *shared_gate, const float *shared_gate_scale, const void *shared_up, const float *shared_up_scale, const void *shared_down, const float *shared_down_scale, float *output, int rows, int hidden_dim, int intermediate_dim, float combination_scale, void *workspace, size_t workspace_bytes) |
| void | vec_dot_nvfp4_q8_0 (int n, float *output, const void *weights, const void *activations, float weight_scale) |
| void | vec_dot_nvfp4_q8_0_ref (int n, float *output, const void *weights, const void *activations, float weight_scale) |
Variables | |
| static const int8_t | ck_nvfp4_e2m1_x2 [16] |
| static const float | ck_nvfp4_ue4m3 [128] |
Packed NVFP4 weight kernels for CPU inference.
The storage ABI keeps E2M1 weights and E4M3 block scales packed. The checkpoint's reciprocal tensor/expert scale is supplied separately so no weight expansion or scale re-encoding is required during conversion.
Definition in file gemm_kernels_nvfp4.c.
|
static |
Definition at line 289 of file gemm_kernels_nvfp4.c.
References CK_DT_Q8_0, ck_dtype_row_bytes(), ck_nvfp4_align64(), gemv_nvfp4_q8_0_uniform(), and quantize_row_q8_0().
Referenced by moe_swiglu_expert_forward_nvfp4_workspace(), and moe_swiglu_shared_forward_nvfp4_workspace().
|
static |
Definition at line 218 of file gemm_kernels_nvfp4.c.
Referenced by ck_moe_swiglu_nvfp4_projection(), moe_swiglu_expert_forward_nvfp4_workspace(), moe_swiglu_nvfp4_workspace_bytes(), and moe_swiglu_shared_forward_nvfp4_workspace().
|
static |
Definition at line 232 of file gemm_kernels_nvfp4.c.
References end, and vec_dot_nvfp4_q8_0().
Referenced by gemv_nvfp4_q8_0_uniform().
| float ck_ue4m3_to_fp32 | ( | uint8_t | value | ) |
Definition at line 53 of file gemm_kernels_nvfp4.c.
References ck_ue4m3_to_fp32_inline().
|
inlinestatic |
Definition at line 48 of file gemm_kernels_nvfp4.c.
References ck_nvfp4_ue4m3.
Referenced by ck_ue4m3_to_fp32(), dequantize_row_nvfp4(), vec_dot_nvfp4_q8_0(), and vec_dot_nvfp4_q8_0_ref().
| void dequantize_row_nvfp4 | ( | const void * | weights, |
| float * | output, | ||
| int | k, | ||
| float | weight_scale | ||
| ) |
Definition at line 58 of file gemm_kernels_nvfp4.c.
References ck_nvfp4_e2m1_x2, ck_ue4m3_to_fp32_inline(), block_nvfp4::d, QK_NVFP4, QK_NVFP4_SUB, and block_nvfp4::qs.
| void gemv_nvfp4_q8_0 | ( | float * | output, |
| const void * | weights, | ||
| const float * | weight_scales, | ||
| const void * | activations, | ||
| int | rows, | ||
| int | cols | ||
| ) |
Definition at line 203 of file gemm_kernels_nvfp4.c.
References QK_NVFP4, and vec_dot_nvfp4_q8_0().
|
static |
Definition at line 244 of file gemm_kernels_nvfp4.c.
References CK_DT_NVFP4, ck_dtype_row_bytes(), ck_nvfp4_gemv_rows(), ck_threadpool_global(), ck_threadpool_n_threads(), and ck_threadpool_parallel_for_n().
Referenced by ck_moe_swiglu_nvfp4_projection().
| int moe_swiglu_expert_forward_nvfp4_workspace | ( | const float * | hidden, |
| const int * | indices, | ||
| const float * | routing_weights, | ||
| const void * | expert_gate, | ||
| const float * | expert_gate_scales, | ||
| const void * | expert_up, | ||
| const float * | expert_up_scales, | ||
| const void * | expert_down, | ||
| const float * | expert_down_scales, | ||
| float * | output, | ||
| int | rows, | ||
| int | hidden_dim, | ||
| int | intermediate_dim, | ||
| int | n_experts, | ||
| int | top_k, | ||
| void * | workspace, | ||
| size_t | workspace_bytes | ||
| ) |
Definition at line 318 of file gemm_kernels_nvfp4.c.
References CK_DT_NVFP4, CK_DT_Q8_0, ck_dtype_row_bytes(), ck_moe_swiglu_nvfp4_projection(), ck_nvfp4_align64(), and moe_swiglu_nvfp4_workspace_bytes().
| size_t moe_swiglu_nvfp4_workspace_bytes | ( | int | hidden_dim, |
| int | intermediate_dim | ||
| ) |
Definition at line 274 of file gemm_kernels_nvfp4.c.
References CK_DT_Q8_0, ck_dtype_row_bytes(), and ck_nvfp4_align64().
Referenced by moe_swiglu_expert_forward_nvfp4_workspace(), and moe_swiglu_shared_forward_nvfp4_workspace().
| int moe_swiglu_shared_forward_nvfp4_workspace | ( | const float * | hidden, |
| const float * | routed, | ||
| const void * | shared_gate, | ||
| const float * | shared_gate_scale, | ||
| const void * | shared_up, | ||
| const float * | shared_up_scale, | ||
| const void * | shared_down, | ||
| const float * | shared_down_scale, | ||
| float * | output, | ||
| int | rows, | ||
| int | hidden_dim, | ||
| int | intermediate_dim, | ||
| float | combination_scale, | ||
| void * | workspace, | ||
| size_t | workspace_bytes | ||
| ) |
Definition at line 377 of file gemm_kernels_nvfp4.c.
References CK_DT_Q8_0, ck_dtype_row_bytes(), ck_moe_swiglu_nvfp4_projection(), ck_nvfp4_align64(), and moe_swiglu_nvfp4_workspace_bytes().
| void vec_dot_nvfp4_q8_0 | ( | int | n, |
| float * | output, | ||
| const void * | weights, | ||
| const void * | activations, | ||
| float | weight_scale | ||
| ) |
Definition at line 125 of file gemm_kernels_nvfp4.c.
References CK_FP16_TO_FP32, ck_nvfp4_e2m1_x2, ck_ue4m3_to_fp32_inline(), block_nvfp4::d, QK_NVFP4, block_nvfp4::qs, and vec_dot_nvfp4_q8_0_ref().
Referenced by ck_nvfp4_gemv_rows(), and gemv_nvfp4_q8_0().
| void vec_dot_nvfp4_q8_0_ref | ( | int | n, |
| float * | output, | ||
| const void * | weights, | ||
| const void * | activations, | ||
| float | weight_scale | ||
| ) |
Definition at line 81 of file gemm_kernels_nvfp4.c.
References CK_FP16_TO_FP32, ck_nvfp4_e2m1_x2, ck_ue4m3_to_fp32_inline(), QK_NVFP4, QK_NVFP4_SUB, block_q8_0::qs, and block_nvfp4::qs.
Referenced by vec_dot_nvfp4_q8_0().
|
static |
Definition at line 24 of file gemm_kernels_nvfp4.c.
Referenced by dequantize_row_nvfp4(), vec_dot_nvfp4_q8_0(), and vec_dot_nvfp4_q8_0_ref().
|
static |
Definition at line 29 of file gemm_kernels_nvfp4.c.
Referenced by ck_ue4m3_to_fp32_inline().