docs: `libm::expf` on device is libdevice, not the host libm — say so where bit-comparability matters

Aperta Adatta ai principianti
#1,823 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
82/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
documentation

Direzione di ricerca

Trova l'esempio libm_math e il punto in cui è già spiegato che le chiamate a libm::{expf, sinf, ...} vengono intercettate e abbassate a intrinsic di libdevice, oltre al capitolo di matematica del libro che ripete lo stesso materiale. Leggi prima la formulazione esistente, poi aggiungi l'avvertenza richiesta: libm::* lato device è libdevice, non la libm dell'host, e corrisponde entro ulps anziché in modo bit-exact, quindi un'implementazione correttamente arrotondata non sostituisce l'algoritmo dell'host. Fatto significa che la frase compare in entrambi i punti e che i docs/il libro continuano a compilare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

The libm_math example states (correctly) that device libm::{expf, sinf, ...} calls are intercepted and lowered to the matching
libdevice intrinsic (__nv_expf, ...). What is not stated anywhere is that this makes them a different function from the
host's expf
, which matters to anyone whose output has to be bit-identical to the host's.

Measured (downstream, not upstream)

In Craton, comparing a device-computed scale 2 / (1 + exp(-z)) against the host's expf (glibc 2.44) on 320 arguments that
occur in a real model:

device form bit-identical to the host
f32 exp 243 / 320 (max 2 ulp)
f64 intermediate, one rounding 226 / 320 (max 2 ulp)

A more accurate computation matched libm worse, because glibc's expf is not correctly rounded either. Matching it required
transcribing sysdeps/ieee754/flt-32/e_expf.c (32-entry table + a cubic evaluated in f64), which then matched 320 / 320.

Ask

One sentence in the libm_math example (and in the book's math material): libm::* on the device is libdevice, not the host's
libm; do not use it where bit-for-bit agreement with the host is required — and note that a correctly rounded implementation is not
a substitute for matching the host's algorithm.

Environment

348895e4, CUDA toolkit 13.4 (V13.4.92), driver 615.78.08, NVIDIA RTX PRO 4500 Blackwell (compute capability 12.0, sm_120),
host x86_64 Linux with glibc 2.44.

Lingua principale
Rust
Stelle
4.1k
Fork
377
Merge medio
3g 2h
PR unite (30g)
103

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NVIDIA/cuda-rust

Tutte le issue di NVIDIA/cuda-rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.