aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2024-01-18 01:24:15 +0100
committerPřemysl Eric Janouch <p@janouch.name>2024-01-18 18:31:10 +0100
commit819d2d80e0524dbd9bf1616e0db08818100af7a1 (patch)
treeaf7e92ec48567dc698a96421c97dcc8d4a602cf5
parent36f661260321ff97842099b23e4c4999576ace77 (diff)
downloadgallery-819d2d80e0524dbd9bf1616e0db08818100af7a1.tar.gz
gallery-819d2d80e0524dbd9bf1616e0db08818100af7a1.tar.xz
gallery-819d2d80e0524dbd9bf1616e0db08818100af7a1.zip
Limit concurrency to number of hardware threads
-rw-r--r--deeptagger/deeptagger.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/deeptagger/deeptagger.cpp b/deeptagger/deeptagger.cpp
index 103047b..cb28d92 100644
--- a/deeptagger/deeptagger.cpp
+++ b/deeptagger/deeptagger.cpp
@@ -598,7 +598,11 @@ infer(Ort::Env &env, const char *path, const std::vector<std::string> &images)
Thumbnailing ctx;
for (const auto &path : images)
ctx.input.push(path);
- for (auto i = g.batch; i--; )
+
+ auto workers = g.batch;
+ if (auto threads = std::thread::hardware_concurrency())
+ workers = std::min(workers, long(threads));
+ for (auto i = workers; i--; )
std::thread(thumbnail, std::ref(config), *width, *height,
std::ref(ctx)).detach();
@@ -610,7 +614,7 @@ infer(Ort::Env &env, const char *path, const std::vector<std::string> &images)
std::unique_lock<std::mutex> output_lock(ctx.output_mutex);
ctx.output_cv.wait(output_lock,
- [&]{ return ctx.output.size() == g.batch || ctx.done == g.batch; });
+ [&]{ return ctx.output.size() == g.batch || ctx.done == workers; });
// It would be possible to add dummy entries to the batch,
// so that the model doesn't need to be rebuilt.
@@ -618,7 +622,7 @@ infer(Ort::Env &env, const char *path, const std::vector<std::string> &images)
run(ctx.output, config, session, shape);
ctx.output.clear();
}
- if (ctx.done == g.batch)
+ if (ctx.done == workers)
break;
}
}