From e821d617802ebbfff756844e4d9720342fc78a4e Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 13 Nov 2026 14:12:49 +0100 Subject: Swarm POC --- poc/web_swarm/worker_native/c++/capability.hpp | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 poc/web_swarm/worker_native/c++/capability.hpp (limited to 'poc/web_swarm/worker_native/c++/capability.hpp') 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 +#include + +#include +#include + +#if defined(__linux__) +#include +#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 probe_native_capability(){ + data 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(pages) * static_cast(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 -- cgit v1.3.1