mirror of
https://github.com/kvcache-ai/ktransformers.git
synced 2026-04-28 03:39:48 +00:00
add kt-kernel
This commit is contained in:
parent
a064cc8525
commit
4c5fcf9774
188 changed files with 59126 additions and 1 deletions
47
kt-kernel/cpu_backend/task_queue.h
Normal file
47
kt-kernel/cpu_backend/task_queue.h
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* @Description :
|
||||
* @Author : chenht2022
|
||||
* @Date : 2024-07-16 10:43:18
|
||||
* @Version : 1.0.0
|
||||
* @LastEditors : chenht
|
||||
* @LastEditTime : 2024-10-09 11:08:07
|
||||
* @Copyright (c) 2024 by KVCache.AI, All Rights Reserved.
|
||||
**/
|
||||
#ifndef CPUINFER_TASKQUEUE_H
|
||||
#define CPUINFER_TASKQUEUE_H
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
class TaskQueue {
|
||||
public:
|
||||
TaskQueue();
|
||||
~TaskQueue();
|
||||
|
||||
void enqueue(std::function<void()>);
|
||||
|
||||
void sync(size_t n);
|
||||
|
||||
private:
|
||||
struct Node {
|
||||
std::function<void()> task;
|
||||
std::atomic<Node*> next;
|
||||
Node() : task(nullptr), next(nullptr) {}
|
||||
Node(const std::function<void()>& t) : task(t), next(nullptr) {}
|
||||
};
|
||||
|
||||
std::atomic<Node*> head;
|
||||
std::atomic<Node*> tail;
|
||||
std::atomic<bool> done;
|
||||
std::atomic<size_t> pending;
|
||||
std::thread workerThread;
|
||||
|
||||
void worker();
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue