StaticThreadPipeline
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <latch>
|
||||
#include <nanobench.h>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
{
|
||||
@@ -25,18 +24,15 @@ int main() {
|
||||
}
|
||||
});
|
||||
|
||||
std::vector<int> threads_per_stage = {1};
|
||||
ThreadPipeline<std::latch *> pipeline(LOG_PIPELINE_SIZE, threads_per_stage);
|
||||
StaticThreadPipeline<std::latch *, WaitStrategy::WaitIfStageEmpty, 1>
|
||||
pipeline(LOG_PIPELINE_SIZE);
|
||||
|
||||
std::latch done{0};
|
||||
|
||||
// Stage 0 consumer thread
|
||||
std::thread stage0_thread([&pipeline, &done]() {
|
||||
const int stage = 0;
|
||||
const int thread_id = 0;
|
||||
|
||||
for (;;) {
|
||||
auto guard = pipeline.acquire(stage, thread_id);
|
||||
auto guard = pipeline.acquire<0, 0>();
|
||||
|
||||
for (auto &item : guard.batch) {
|
||||
for (volatile int i = 0; i < BUSY_ITERS; i = i + 1) {
|
||||
@@ -94,19 +90,15 @@ int main() {
|
||||
.warmup(100);
|
||||
|
||||
for (int batch_size : {1, 4, 16, 64, 256}) {
|
||||
std::vector<int> threads_per_stage = {1};
|
||||
ThreadPipeline<std::latch *> pipeline(LOG_PIPELINE_SIZE,
|
||||
threads_per_stage);
|
||||
StaticThreadPipeline<std::latch *, WaitStrategy::WaitIfStageEmpty, 1>
|
||||
pipeline(LOG_PIPELINE_SIZE);
|
||||
|
||||
std::latch done{0};
|
||||
|
||||
// Stage 0 consumer thread
|
||||
std::thread stage0_thread([&pipeline, &done]() {
|
||||
const int stage = 0;
|
||||
const int thread_id = 0;
|
||||
|
||||
for (;;) {
|
||||
auto guard = pipeline.acquire(stage, thread_id);
|
||||
auto guard = pipeline.acquire<0, 0>();
|
||||
|
||||
for (auto &item : guard.batch) {
|
||||
for (volatile int i = 0; i < BUSY_ITERS; i = i + 1) {
|
||||
@@ -162,18 +154,15 @@ int main() {
|
||||
constexpr int BUSY_ITERS =
|
||||
10; // Light work to emphasize coordination overhead
|
||||
|
||||
std::vector<int> threads_per_stage = {1, 1}; // Two stages
|
||||
ThreadPipeline<std::latch *, strategy> pipeline(LOG_PIPELINE_SIZE,
|
||||
threads_per_stage);
|
||||
StaticThreadPipeline<std::latch *, strategy, 1, 1> pipeline(
|
||||
LOG_PIPELINE_SIZE);
|
||||
|
||||
std::latch done{0};
|
||||
|
||||
// Stage 0 worker
|
||||
std::thread stage0_thread([&pipeline, &done]() {
|
||||
const int stage = 0;
|
||||
const int thread_id = 0;
|
||||
for (;;) {
|
||||
auto guard = pipeline.acquire(stage, thread_id);
|
||||
auto guard = pipeline.template acquire<0, 0>();
|
||||
for (auto &item : guard.batch) {
|
||||
for (volatile int i = 0; i < BUSY_ITERS; i = i + 1) {
|
||||
}
|
||||
@@ -185,10 +174,8 @@ int main() {
|
||||
|
||||
// Stage 1 worker (final stage - always calls futex wake)
|
||||
std::thread stage1_thread([&pipeline, &done]() {
|
||||
const int stage = 1;
|
||||
const int thread_id = 0;
|
||||
for (;;) {
|
||||
auto guard = pipeline.acquire(stage, thread_id);
|
||||
auto guard = pipeline.template acquire<1, 0>();
|
||||
for (auto &item : guard.batch) {
|
||||
for (volatile int i = 0; i < BUSY_ITERS; i = i + 1) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user