summaryrefslogtreecommitdiff
path: root/poc/web_swarm/worker_native/c++/capability.hpp
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-11-13 14:12:49 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-11-13 14:12:49 +0100
commite821d617802ebbfff756844e4d9720342fc78a4e (patch)
tree1dcf33b84698b5074218e44ea491b77a9c23ee66 /poc/web_swarm/worker_native/c++/capability.hpp
parent0c0087ef9482634273ec1a23d3a915754f94926d (diff)
downloadlibs-lbm-dev.tar.gz
Swarm POCdev
Diffstat (limited to 'poc/web_swarm/worker_native/c++/capability.hpp')
-rw-r--r--poc/web_swarm/worker_native/c++/capability.hpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/poc/web_swarm/worker_native/c++/capability.hpp b/poc/web_swarm/worker_native/c++/capability.hpp
new file mode 100644
index 0000000..d892a8f
--- /dev/null
+++ b/poc/web_swarm/worker_native/c++/capability.hpp
@@ -0,0 +1,63 @@
+#pragma once
+
+#include <kel/lbm/swarm/capability.hpp>
+#include <kel/lbm/abstract/data.hpp>
+
+#include <string>
+#include <thread>
+
+#if defined(__linux__)
+#include <unistd.h>
+#endif
+
+namespace kel {
+namespace lbm {
+namespace swarm {
+
+/**
+ * What a native worker can honestly say about itself.
+ *
+ * Deliberately short. A browser worker has to measure its texture budget
+ * because WebGL will not tell it, but a process can simply ask the OS, and
+ * there is no point inventing numbers beyond that until there is a scheduler
+ * that would use them.
+ */
+inline data<sch::NativeCapability> probe_native_capability(){
+ data<sch::NativeCapability> cap;
+
+ unsigned threads = std::thread::hardware_concurrency();
+ if(threads == 0u){
+ // hardware_concurrency is allowed to give up; one thread is the
+ // honest floor rather than zero, which would read as "no capacity".
+ threads = 1u;
+ }
+ cap.get<"threads">().set(threads);
+
+ uint64_t memory_bytes = 0u;
+#if defined(__linux__)
+ const long pages = ::sysconf(_SC_PHYS_PAGES);
+ const long page_size = ::sysconf(_SC_PAGE_SIZE);
+ if(pages > 0 and page_size > 0){
+ memory_bytes = static_cast<uint64_t>(pages) * static_cast<uint64_t>(page_size);
+ }
+#endif
+ cap.get<"memory_bytes">().set(memory_bytes);
+
+#if defined(__x86_64__)
+ cap.get<"cpu">().set(std::string{"x86_64"});
+#elif defined(__aarch64__)
+ cap.get<"cpu">().set(std::string{"aarch64"});
+#else
+ cap.get<"cpu">().set(std::string{"unknown"});
+#endif
+
+ // Nothing here links SYCL yet. Reported so the orchestrator can start
+ // distinguishing compute capable workers without a protocol change.
+ cap.get<"has_sycl">().set(false);
+
+ return cap;
+}
+
+} // namespace swarm
+} // namespace lbm
+} // namespace kel