/** * @Description : * @Author : chenht2022 * @Date : 2024-07-22 02:03:05 * @Version : 1.0.0 * @LastEditors : chenht2022 * @LastEditTime : 2024-07-25 10:33:38 * @Copyright (c) 2024 by KVCache.AI, All Rights Reserved. **/ #ifndef CPUINFER_BACKEND_H #define CPUINFER_BACKEND_H #include #include #include #include #include #include #include enum ThreadStatus { WORKING, WAITING, EXIT, }; struct ThreadState { std::unique_ptr> status; std::unique_ptr> curr; int end; }; class Backend { public: Backend(int); ~Backend(); int get_thread_num(); void do_work_stealing_job(int, std::function, std::function, std::function); #ifdef USE_NUMA static thread_local int numa_node; #endif static thread_local int thread_local_id; private: int thread_num_; int max_thread_num_; std::vector thread_state_; // [thread_num] std::function init_func_; std::function compute_func_; std::function finalize_func_; std::vector workers_; void process_tasks(int); void worker_thread(int); }; #endif