mirror of
https://github.com/kvcache-ai/ktransformers.git
synced 2025-09-14 09:09:42 +00:00
Initial commit
This commit is contained in:
commit
18c42e67df
247 changed files with 53775 additions and 0 deletions
50
ktransformers/ktransformers_ext/cpu_backend/backend.h
Normal file
50
ktransformers/ktransformers_ext/cpu_backend/backend.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* @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 <atomic>
|
||||
#include <condition_variable>
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
enum ThreadStatus {
|
||||
WORKING,
|
||||
WAITING,
|
||||
EXIT,
|
||||
};
|
||||
|
||||
struct ThreadState {
|
||||
std::unique_ptr<std::atomic<ThreadStatus>> status;
|
||||
std::unique_ptr<std::atomic<int>> curr;
|
||||
int end;
|
||||
};
|
||||
|
||||
class Backend {
|
||||
public:
|
||||
Backend(int);
|
||||
~Backend();
|
||||
int get_thread_num();
|
||||
void do_work_stealing_job(int, std::function<void(int)>);
|
||||
|
||||
private:
|
||||
int thread_num_;
|
||||
std::vector<ThreadState> thread_state_; // [thread_num]
|
||||
std::function<void(int)> func_;
|
||||
std::vector<std::thread> workers_;
|
||||
|
||||
void process_tasks(int);
|
||||
void worker_thread(int);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue