[libcu++] `cuda::std::addressof()` produces worse code compared to `__builtin_addressof`

Aperta
#12,830 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
performance

Direzione di ricerca

The issue compares cuda::std::addressof with __builtin_addressof in a memcpy call, so start with the libcu++ addressof definition and the reproducer's WRAP and non-WRAP variants. Compile both for SM80, SM86 and SM90 and compare register counts, since the reported gap is 8 to 19 registers per thread. Done when the library path matches the builtin's register usage, or the cause is documented.

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

Descrizione

bug

How the compiler works for these cases will always be a mistery for me.

Considering the following example

#if WRAP
  memcpy(cuda::std::addressof(word), cuda::std::addressof(swapped), sizeof(word));
#else
  memcpy(__builtin_addressof(word), __builtin_addressof(swapped), sizeof(word));
#endif

even when __builtin_addressof is fully available in addressof, the two paths could generate very different code.
Here the full example https://godbolt.org/z/GaM93dM4W
The difference in register usage is huge!

SM __builtin_addressof cuda::std::addressof Extra registers per thread
SM80 29 48 +19
SM86 32 40 +8
SM90 29 40 +11

luckly this doesn't not affect SM100+ (nvvm-latest).

The workaround would be replacing addressof with __builtin_addressof, but this is not possible for several reasons, including for the namespace.
I don't have a solution @miscco, @davebayer, @Jacobfaib please let me know if you have an idea on how to fix this issue

Lingua principale
C++
Stelle
2.6k
Fork
555
Merge medio
3g 3h
PR unite (30g)
314

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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/cccl

Tutte le issue di NVIDIA/cccl

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.