Skip to content

feat(cuda): report device identity and compiled architecture - #30

Open
NicolasRouquette wants to merge 1 commit into
lean-dojo:mainfrom
NicolasRouquette:cuda-device-identity
Open

feat(cuda): report device identity and compiled architecture#30
NicolasRouquette wants to merge 1 commit into
lean-dojo:mainfrom
NicolasRouquette:cuda-device-identity

Conversation

@NicolasRouquette

Copy link
Copy Markdown
Contributor

Why

A benchmark or a sizing decision that cannot name the device it ran on produces a number that cannot be filed beside another one. Buffer.allocatorStats already answers how much device memory there is; nothing answered which device, and nothing answered which architectures the binary actually holds native code for.

The second gap is the one that bites quietly. Device code is compiled for an architecture, and with no -arch the toolkit applies its own default. A binary built that way still runs on a newer GPU — through forward PTX JIT — so nothing fails and nothing warns. The timings are then of JIT-generated code for an architecture the compiler was never told about, which is a different measurement from the one a reader will assume.

What

  • Buffer.deviceInfo : IO (Option DeviceInfo) over cudaGetDeviceProperties: name, index, compute capability, SM count, core and memory clocks, memory bus width, total memory, driver and runtime versions.
  • DeviceInfo.peakBandwidthGBs, so a row reporting achieved GB/s can be read as a fraction of the roofline without the reader looking the card up.
  • Buffer.compiledArchList — the binary's own __CUDA_ARCH_LIST__ ("860", "750,860") — and DeviceInfo.runsNatively. DeviceInfo.format prints the mismatch as a warning:
NVIDIA RTX A4500 (device 0, sm_86, 56 SMs, 19.5 GiB, ~640 GB/s peak, driver 13.0, runtime 12.6) [WARNING: compiled for 520, NOT sm_86 — running via PTX JIT]

That line is not hypothetical — it is the first thing the check reported on the machine it was written on.

Shape of the change

Properties are queried once under pthread_once and cached; cudaGetDeviceProperties is comparatively expensive and its answer cannot change for a device index.

In the CPU stub, and in a CUDA build on a host where no device answers, the name is empty and every scalar is 0, so deviceInfo returns none. A caller therefore prints one line under either build flavour and reads the absence off the fields rather than off its own build flavour.

Additions only — 4 files, no existing declaration or symbol changed. The stub carries the matching definitions so the parity build keeps linking.

Testing

Built and run both flavours on an RTX A4500 (sm_86, CUDA 12.6, driver 13.0):

  • CPU stub: deviceInfo returns none, the caller's line reads as absence.
  • CUDA, no -arch: reports the device correctly and flags compiled for 520, NOT sm_86.
  • CUDA, TORCHLEAN_CUDA_ARCH=sm_86: warning gone, reads [compiled for 860].

Measured cost of the JIT for the workload in hand: none (24.47 ms against 23.29 ms, within run-to-run scatter). The point is that it was not knowable before.

🤖 Generated with Claude Code

@NicolasRouquette
NicolasRouquette force-pushed the cuda-device-identity branch 3 times, most recently from 4d00f0c to c30b1ef Compare August 26, 2026 23:38
A benchmark or a sizing decision that cannot name the device it ran on
produces a number that cannot be filed beside another one. The allocator
snapshot already answers how much device memory there is; nothing answered
which device, and nothing answered which architectures the binary actually
holds native code for.

Adds `Buffer.deviceInfo : IO (Option DeviceInfo)` over `cudaGetDeviceProperties`
— name, index, compute capability, SM count, core and memory clocks, bus width,
total memory, driver and runtime versions — plus `peakBandwidthGBs`, so a row
reporting achieved GB/s can be read as a fraction of the roofline without the
reader looking the card up.

Adds `Buffer.compiledArchList`, the binary's own `__CUDA_ARCH_LIST__`, and
`DeviceInfo.runsNatively`. A binary compiled for one architecture still runs on
a newer device through PTX JIT, silently turning a benchmark into a measurement
of the fallback; the pair of facts makes that visible, and `DeviceInfo.format`
prints it as a warning when they disagree.

Properties are queried once under `pthread_once` and cached. In the CPU stub,
and in a CUDA build on a host where no device answers, the name is empty and
`deviceInfo` is `none` — so a caller prints one line under either flavour and
reads the absence off the fields rather than off its own build flavour.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant