Skip to content

[Fix] Validate num_sms before communication context initialization - #10

Open
morluto wants to merge 1 commit into
MoonshotAI:masterfrom
morluto:codex/validate-num-sms
Open

[Fix] Validate num_sms before communication context initialization#10
morluto wants to merge 1 commit into
MoonshotAI:masterfrom
morluto:codex/validate-num-sms

Conversation

@morluto

@morluto morluto commented Jul 28, 2026

Copy link
Copy Markdown

Fixes #7.

Summary

Validate num_sms before allocating the communication context or compiling
communication kernels.

Explicit values must be positive integers no greater than the current CUDA
device's physical SM count. When omitted, num_sms now resolves to
min(32, device_sm_count).

num_sms is None ----------------> min(32, device SM count)

explicit num_sms
      |
      +--> positive integer? ---- no --> TypeError / ValueError
      |
      +--> <= device SM count? -- no --> ValueError
      |
      `-------------------------- yes -> create context

Problem

MoonEP exposes num_sms as the number of SMs assigned to communication, but
previously accepted any positive integer. Oversized values reached context
allocation and kernel compilation before producing a configuration-dependent
CUDA failure.

The previous fixed default of 32 could also be unsuitable for devices with
fewer than 32 physical SMs.

This change establishes a conservative MoonEP API bound. It does not attempt
to calculate each compiled kernel's occupancy-dependent cooperative launch
limit.

Change

  • Reject booleans and non-integer values with TypeError.
  • Reject zero and negative values with ValueError.
  • Reject explicit values greater than the current device's SM count.
  • Resolve None to the smaller of 32 and the device SM count.
  • Document the resolved default and upper bound.

Validation

  • python3 -m pytest -q tests/test_api_validation.py — 7 passed.
  • python3 -m py_compile moonep/api.py tests/test_api_validation.py — passed.
  • Coverage includes malformed values, oversized values, the exact device
    limit, and default resolution on a smaller device.

@morluto morluto changed the title Validate communication SM count before buffer allocation [Fix] Validate num_sms before communication context initialization Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] num_sms is not validated against the current CUDA device

1 participant