sparkle/native/ext/io/bg_reader.h
fiser_jun 4745f264b2
2026-08-04 14:34:00 +08:00

24 lines
1.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 自由后台读线程de-risk脱离 GPU 完成回调、零 GILpread 进调用方 MLX buffer。
// 线程全程只碰 dst 原始指针 / 路径 / 整数,绝不接触 Python 对象 → 无需 GIL。
#pragma once
#include "../common.h"
#include <functional>
void bg_reader_start(int workers, int low_cap = 0);
long bg_reader_submit(const mx::array& dst, const std::vector<int>& experts,
const std::vector<int>& rows, const std::string& path,
int stride, long ticket, int prio = 0);
bool bg_reader_ready(long ticket);
void bg_reader_wait(long ticket);
void bg_reader_stop();
long bg_pread_into_pool(
const std::vector<mx::array>& dst,
const std::vector<long>& seg_off,
const std::vector<long>& seg_nb,
long slot, long expert,
const std::string& path, long stride, long ticket, int prio = 0, bool nocache = true);
// 通用后台任务入口:把任意闭包派到后台线程池(低优队列)。侧区/staging 预取的 GPU 完成回调
// 用它把 pread 派离 Metal 回调线程 → 真正与计算重叠。内部接口,不绑 Python。
void bg_submit_task(std::function<void()> fn);