Potential sync optimizations for single-threaded schedulers
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia riproducendo l’esempio Godbolt e leggendo le implementazioni di sync_wait, async_scope e inline_scheduler menzionate nell’issue. Traccia dove vengono introdotti i mutex e le variabili di condizione e se in quel punto sono disponibili informazioni sul tipo di scheduler. Il lavoro è completo quando viene stabilito se la sincronizzazione a thread singolo può essere rimossa in sicurezza e viene documentata una direzione concreta per l’implementazione, oppure il motivo per cui il design lo impedisce.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I've been playing around with stdexec and had a thought about sync_wait and async_scope that I wanted to run by the community. I might be missing something obvious here, so please let me know if this doesn't make sense!
I noticed that when using sync_wait with inline_scheduler, we still use mutexes and condition variables internally, even though we know the work will run on the calling thread. Same thing seems to happen with async_scope when all tasks run on a single thread.
I was wondering:
- Is there a way (or maybe there already is?) to optimize away this synchronization overhead when we know at compile-time that everything will run on the same thread?
- Does the sender type system provide enough information to detect these cases?
Quick example of what made me think about this (godbolt):
#include <stdexec/execution.hpp>
#include <exec/inline_scheduler.hpp>
int main(int argc, char* argv[]) {
auto sdr = stdexec::schedule(exec::inline_scheduler{})
| stdexec::then([argc] { return argc; })
| stdexec::then([](auto n) { return 2 * n; });
auto [res] = stdexec::sync_wait(std::move(sdr)).value();
return res;
}
I expected the generated assembly to be equivalent, or extremely close, to simply writing:
int main(int argc, char* argv[]) {
auto then_f = [](auto n) { return 2 * n; };
auto [res] = std::optional{std::tuple{std::move(then_f)(argc)}}.value();
return res;
}
However, the generated code uses mutexes and condition variables.
I was thinking: could sync_wait potentially use type traits from the active scheduler to determine if it needs to be thread-safe? That way, it could avoid mutexes and condition variables in single-threaded cases.
The same could apply to async_scopes that run in single-threaded environments.
If my understanding of sync_wait and inline_scheduler is incorrect, please let me know!
Otherwise, it would be interesting to know whether such overhead is avoidable in single-threaded cases or if it's inherently tied to the design.
Thanks for any insights!
- Lingua principale
- C++
- Stelle
- 2.4k
- Fork
- 270
- Merge medio
- 2g 17h
- PR unite (30g)
- 37
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NVIDIA/stdexec
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 66/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 74/100
Tutte le issue di NVIDIA/stdexec
Issue simili
-
ai_reviewed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
ydb-platform/ydb#53869 · 3 commenti ·
-
bug cert blocker needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
project-chip/connectedhomeip#74373 ·
-
[request] tracy/0.14.1 Apertaupstream update
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
conan-io/conan-center-index#31035 ·
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
vllm-project/vllm-ascend#17329 ·