Potential sync optimizations for single-threaded schedulers
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện ví dụ Godbolt và đọc các triển khai của sync_wait, async_scope và inline_scheduler được đề cập trong issue. Truy vết nơi các mutex và condition variable được đưa vào, cũng như liệu thông tin về kiểu scheduler có sẵn ở đó hay không. Hoàn thành nghĩa là xác định liệu có thể loại bỏ đồng bộ hóa trong trường hợp một luồng một cách an toàn hay không, đồng thời ghi lại một hướng triển khai cụ thể hoặc lý do thiết kế ngăn cản điều đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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!
- Ngôn ngữ chính
- C++
- Star
- 2.4k
- Fork
- 270
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 43
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NVIDIA/stdexec
-
inline_scheduler's namespace-scope static_assert fails under nvcc (private nested __sender access) Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 65/100
Tất cả issue của NVIDIA/stdexec
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
duckdb/duckdb-wasm#2258 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
objectionary/eo-graphs#75 ·
-
Coarray integration tests carry no LABELS, so run_tests.py silently skips them under every backend Đang mởcoarray
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
FISCO-BCOS/FISCO-BCOS#5642 ·