Download kernels/Quant/020_nvfp4_linear_layer/src/kernel.h from QianQu/CompoundingKernel-Explorer: direct link, hf CLI and curl.
- Browser
- Download file 4.1 kB
-
https://huggingface.co/spaces/QianQu/CompoundingKernel-Explorer/resolve/main/kernels/Quant/020_nvfp4_linear_layer/src/kernel.h
- Command line
-
hf download hf://spaces/QianQu/CompoundingKernel-Explorer/kernels/Quant/020_nvfp4_linear_layer/src/kernel.h
-
curl -L -o kernel.h https://huggingface.co/spaces/QianQu/CompoundingKernel-Explorer/resolve/main/kernels/Quant/020_nvfp4_linear_layer/src/kernel.h
4.1 kB
| // Launcher for the fused NVFP4 quantization pipeline (see kernel.cu). | |
| // sync_ws: >= 1024 floats of ZERO-INITIALISED persistent scratch (grid-barrier epoch counters | |
| // u64 + amax slots, self-maintaining across calls); ab: [alpha, beta] output for the GEMM. | |
| // The launcher picks the kernel variant + grid size from M (register-resident for small M). | |
| // late_pdl: trigger PDL dependents only after alpha is published. | |
| // carve: -1 default per variant, 0 default L1/smem split, 1 max smem carveout instantiation. | |
| // do_wsf=false skips the weight-scale re-layout (custom GEMM reads the raw row-major scales). | |
| static constexpr int kMaxPartials = 4096; | |
| void launch_fused_quant(const void* x, int M, int Mp, int K, const uint8_t* wsf, uint8_t* wsf_blk, | |
| int N, float w_gd, uint8_t* xq, uint8_t* xsf_blk, float* sync_ws, | |
| float* ab, bool do_wsf, bool late_pdl, int carve, cudaStream_t s, | |
| float* avec = nullptr, // N-float alpha vector (unused: nullptr) | |
| int ipt = 0); // 7: IPT 7 variant, 21: IPT 2 x 128 threads, 0: default | |
| int quant_full_grid(); // max co-resident CTAs of the persistent quant kernel | |
| // launch-time flag: the quant kernel's weight-scale re-layout writes the PADDED layout of the | |
| // CUTLASS tile configs: 0 off, 1 = 256x224 tiles, 2 = 256x112 tiles | |
| void set_wsf_pad(int mode); | |
| // persistent quant (al32i bit 65536): demote [p, p+bytes) L2 lines to evict_normal at entry | |
| void set_quant_l2_demote(const void* p, long long bytes); | |
| // Quant kernels: prefetch the first K-prefix of every fp4 weight row at p into L2 after their | |
| // stores (nullptr = off). Read at launch time (captured into graphs). | |
| void set_quant_l2_prefetch(const void* p, long long bytes); | |
| void set_quant_pf_prefix(int bytes); // weight-row prefix bytes of that prefetch (default 1024) | |
| // Swap-AB GEMM: computes out^T tiles = W x^T (weight rows = MMA M = 128, tokens = MMA N = BX). | |
| // Built for BX = 128, KS = 2 only (else returns false). Requires K%512==0, N%128==0, Mp%128==0, | |
| // (K/256)%(2S)==0. red_ws >= Mp*N*S fp32 when S > 1. | |
| // cold-L2 weight prefetch: share (%) of each split's K stages prefetched into L2 before | |
| // griddepcontrol.wait (0 = off). Read at launch time (captured into graphs). | |
| void set_swap_l2_prefetch(int pct); | |
| bool launch_nvfp4_gemm_swap(const void* xq, const void* xsf_blk, const void* wq, | |
| const void* wsf_raw, const float* ab, void* out, float* red_ws, int Mp, | |
| int N, int K, int S, int BX, int KS, cudaStream_t s); | |
| // Persistent-quant pass-1 L2 policy override (read at launch time -> captured into graphs): | |
| // tail MB of x loaded with evict_last (-1 = default), first = the remaining pass-1 loads with | |
| // L2 evict_first instead of evict_normal. | |
| void set_tail_force_mb(int mb); | |
| void set_p1_first(bool on); | |
| // evict_last budget (MB of x) of the persistent quant kernel's amax pass (default 40) | |
| void set_evict_last_mb(int mb); | |
| // chunked large-M pipeline (quant overlapped with the GEMM): amax-only persistent pass (also | |
| // alpha + weight-scale re-layout), then per-chunk row quantization reading the published amax | |
| void launch_quant_amax(const void* x, int M, int Mp, int K, const uint8_t* wsf, uint8_t* wsf_blk, | |
| int N, float w_gd, uint8_t* xq, uint8_t* xsf_blk, float* sync_ws, float* ab, | |
| float* amax_out, cudaStream_t s); | |
| void launch_quant_rows(const void* x, int M, int r0, int r1, int K, const float* amax_p, | |
| uint8_t* xq, uint8_t* xsf_blk, cudaStream_t s, | |
| int cps = 0); // cps > 0: grid = cps CTAs per SM (default 2) | |
| static constexpr int kNoiseCalib2 = 2; | |
| static constexpr int kNoiseCalib3 = 3; | |
| // Weight-stationary small-M GEMM (Mp 128 pin): 56 weight rows per CTA over the full K, no split-K | |
| bool launch_nvfp4_gemm_ws(const void* xq, const void* xsf_blk, const void* wq, const void* wsf_raw, | |
| const float* ab, void* out, int Mp, int N, int K, cudaStream_t s); | |