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

24 lines
1.3 KiB
C++
Raw 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.

// GPU 完成回调预取:算完 inds 后在回调里读 id、pread 预热 page cache 或写 per-layer staging。
#pragma once
#include "../common.h"
// 挂 GPU 完成回调:算完 inds 后在回调里读 id 预热 page cache返回 dummy。
// (无 staging 的轻量预取模式:仅把预测专家字节读进 page cache不落池。
mx::array prefetch_on_complete(
const mx::array& expert_ids, const std::string& path, int stride,
bool do_read, mx::StreamOrDevice s);
// miss→hit方案Bexpert_ids 为预测宽集合(降序),回调按 resident 过滤、取前 cap 个缺口
// pread 进 per-layer staging buffer(cap=buffer 行数),并原子记录 (gen,[expert,row])。
mx::array prefetch_into_staging(
const mx::array& staging, const mx::array& expert_ids, int layer, long gen,
const std::string& path, int stride, const std::vector<int>& resident, int cap,
bool parallel, mx::StreamOrDevice s);
// 取走某层就绪记录:[gen, e0,r0,e1,r1,...];空表示无就绪。
std::vector<long> prefetch_staging_take(int layer);
// handler 触发时刻探针(诊断用)enable 开关并清零now 取同时钟当前秒get 取 (gen,layer,t) 日志。
void staging_hprof_enable(bool on);
double staging_hprof_now();
std::vector<double> staging_hprof_get(); // 扁平 [gen,layer,t, ...]