FlashKDA icon indicating copy to clipboard operation
FlashKDA copied to clipboard

Centralize CHUNK and D constants as single source of truth

Open haix716 opened this issue 4 months ago • 0 comments

Problem

CHUNK=16 and D=128 appear as magic numbers in multiple locations:

  • csrc/flash_kda.cpp — static_assert and workspace size calculation
  • csrc/smxx/fwd_kernel1.cuh — kernel constants
  • csrc/smxx/fwd_kernel2.cuh — kernel constants
  • tests/torch_ref.py — reference implementation
  • tests/test_fwd.py — test parameters
  • docs/20260420-flashkda-v1-deep-dive.md — documentation

There is no single source of truth. If someone wanted to support D=64 or D=256, they'd need to change dozens of locations.

Recommendation

Define CHUNK and D as compile-time constants in one place (e.g., setup.py as compiler defines, or a shared header), and reference them everywhere else. Add a test that verifies the error message when D != 128.

Impact

Extensibility. Makes it possible to support different D values without a multi-file hunt for magic numbers.

haix716 avatar Jul 28 '26 06:07 haix716