Download cpp_engine/include/core/thread_utils.hpp from Ypeng12/quant-ai: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/Ypeng12/quant-ai/resolve/main/cpp_engine/include/core/thread_utils.hpp
- Command line
-
hf download hf://spaces/Ypeng12/quant-ai/cpp_engine/include/core/thread_utils.hpp
-
curl -L -o thread_utils.hpp https://huggingface.co/spaces/Ypeng12/quant-ai/resolve/main/cpp_engine/include/core/thread_utils.hpp
1.17 kB
| namespace quant::core { | |
| class ThreadUtils { | |
| public: | |
| /** | |
| * Pin current thread to a dedicated CPU core. | |
| * Linux: pthread_setaffinity_np | |
| * macOS: thread_policy_set with THREAD_AFFINITY_POLICY | |
| */ | |
| static bool pin_current_thread(int core_id) noexcept; | |
| /** | |
| * Set thread priority (SCHED_FIFO or max nice). | |
| */ | |
| static bool set_realtime_priority(int priority = 80) noexcept; | |
| /** | |
| * Set thread human-readable name for top / htop / perf. | |
| */ | |
| static bool set_thread_name(const char* name) noexcept; | |
| /** | |
| * Lock all current and future process memory into RAM to prevent paging / page-fault jitter. | |
| */ | |
| static bool lock_all_memory() noexcept; | |
| /** | |
| * Low-latency CPU pause (x86 _mm_pause or ARM isb) to avoid pipeline stalls in spinloops. | |
| */ | |
| static inline void cpu_pause() noexcept { | |
| __builtin_ia32_pause(); | |
| asm volatile("isb" : : : "memory"); | |
| std::this_thread::yield(); | |
| } | |
| }; | |
| } // namespace quant::core | |