mirror of
https://github.com/kvcache-ai/ktransformers.git
synced 2026-10-18 14:43:29 +08:00
e80614fc2d
* feat(sft): support distributed activation reuse policies * feat(sft): add frozen-base INT8 LoRA training * fix(sft): make INT8 expert LoRA rank-zero authoritative * fix(sft): preserve DeepSeek router LoRA routing * feat(sft): enable persistent INT8 LoRA training * perf(sft): accelerate INT8 VNNI with oneDNN BRGEMM * perf(int8): fuse oneDNN compensation into backward repack * [feat]: support BF16 expert LoRA training * [fix]: honor forwarded activation policy in SFT workers * feat(sft): add native block-FP8 routed expert LoRA * feat(sft): expose explicit expert placeholder ownership * fix(sft): publish fused adapter artifacts atomically * feat(sft): own artifact and adapter lifecycle contracts * fix(sft): harden artifact and rank-local contracts * fix(sft): auto-adapt owner before adapter restore * style(sft): keep lifecycle comments concise * fix(sft): require fused adapter manifests * test(sft): use spawn for distributed workers * fix(sft): preserve runtime checkpoint metadata * fix(sft): validate wrapped runtime configuration * fix(sft): preserve expert format provenance * fix(sft): own routed experts during device dispatch * test(sft): lock explicit quantization conflict * fix(cpu): make shared memory buffers lifetime-safe * release: prepare v0.7.0
67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
/**
|
|
* @Description :
|
|
* @Author : chenht2022
|
|
* @Date : 2024-08-05 04:49:08
|
|
* @Version : 1.0.0
|
|
* @LastEditors : chenht2022
|
|
* @LastEditTime : 2024-08-05 06:36:41
|
|
* @Copyright (c) 2024 by KVCache.AI, All Rights Reserved.
|
|
**/
|
|
|
|
#ifndef CPUINFER_SHAREDMEMBUFFER_H
|
|
#define CPUINFER_SHAREDMEMBUFFER_H
|
|
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <functional>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <variant>
|
|
#include <vector>
|
|
|
|
struct MemoryRequest {
|
|
std::vector<std::function<void(void*)>> funcs;
|
|
std::vector<size_t> sizes;
|
|
|
|
size_t total_size();
|
|
void update_base_ptr(void* base);
|
|
|
|
template <typename T>
|
|
void append_pointer(T** ptr, size_t size) {
|
|
append_function([ptr](void* base) { *ptr = reinterpret_cast<T*>(base); }, size);
|
|
}
|
|
void append_function(std::function<void(void*)> func, size_t size);
|
|
};
|
|
|
|
class SharedMemBuffer {
|
|
public:
|
|
SharedMemBuffer();
|
|
~SharedMemBuffer();
|
|
|
|
void alloc(void* object, MemoryRequest requests);
|
|
void dealloc(void* object);
|
|
|
|
private:
|
|
void* buffer;
|
|
uint64_t size;
|
|
std::map<void*, std::vector<MemoryRequest>> object_requests;
|
|
std::mutex lock;
|
|
};
|
|
|
|
static SharedMemBuffer shared_mem_buffer;
|
|
static SharedMemBuffer shared_mem_buffer_for_decoder_layer;
|
|
|
|
class SharedMemBufferNuma {
|
|
std::mutex lock;
|
|
std::map<size_t, std::unique_ptr<SharedMemBuffer>> numa_mem;
|
|
|
|
public:
|
|
void alloc(int numa, void* object, MemoryRequest requests);
|
|
void dealloc(int numa, void* object);
|
|
};
|
|
|
|
static SharedMemBufferNuma shared_mem_buffer_numa;
|
|
|
|
#endif
|