Skip to content

Centralize CHUNK and D constants as single source of truth #20

Description

@haix716

Problem

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

  • csrc/flash_kda.cppstatic_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions