Merge perf-PR group batch (f-145-pp-batch)
This commit is contained in:
commit
e8b1edbcb7
25 files changed
+2105
-130
No files matched your search
@@ -721,7 +721,7 @@ public:
|
||||
|
||||
/// Blobs touched, for the driver to report. With `h = 0` this is `48 * k` per token and the number is only
|
||||
/// interesting once Phase 3 makes it not so.
|
||||
int64_t reads() const override { return reads_; }
|
||||
int64_t reads() const override { return reads_.load(std::memory_order_relaxed); }
|
||||
|
||||
// ---- the Linux I/O path of the mapped file tier (STRATA_IO_PREFETCH=1, opt in; no effect on Windows)
|
||||
//
|
||||
@@ -735,6 +735,9 @@ public:
|
||||
// The bytes are the same bytes, so the output is the same. `threads` = I/O threads (0: default 4).
|
||||
void set_io_prefetch(bool on, int threads);
|
||||
bool io_prefetch() const { return io_pf_; }
|
||||
/// blob() hands out stage buffers it recycles (the GGUF in place, an unbuffered source, the I/O read-ahead): one
|
||||
/// thread at a time (STRATA_PIPED_CONCURRENT is off with such a source)
|
||||
bool stages_blobs() const { return staged(); }
|
||||
/// Counts the cached / uncached bytes of every blob read from the files (mincore, page-granular). Free with
|
||||
/// io_prefetch; otherwise opt in with STRATA_IO_STATS=1 (the check costs a few microseconds per blob).
|
||||
void set_io_stats(bool on) { io_stats_ = on || io_pf_; }
|
||||
@@ -891,7 +894,7 @@ private:
|
||||
uint64_t xstage_blob_ = 0;
|
||||
int64_t exchanges_ = 0;
|
||||
std::atomic<int64_t> file_reads_{0};
|
||||
int64_t reads_ = 0;
|
||||
std::atomic<int64_t> reads_{0}; ///< (a counter only; two threads can read blobs at once)
|
||||
#if defined(_WIN32)
|
||||
void* file_ = nullptr;
|
||||
void* mapping_ = nullptr;
|
||||
@@ -939,9 +942,9 @@ public:
|
||||
int64_t blobs() const { return blobs_; }
|
||||
const uint8_t* blob(int64_t layer, int64_t expert) override;
|
||||
/// `blob` without the read counter: a pure pointer into the arena, safe from another thread (the async adaptive
|
||||
/// tier's job thread, which must not touch the non-atomic `reads_`)
|
||||
/// tier's job thread)
|
||||
const uint8_t* blob_at(int64_t layer, int64_t expert) const;
|
||||
int64_t reads() const { return reads_; }
|
||||
int64_t reads() const { return reads_.load(std::memory_order_relaxed); }
|
||||
bool pinned(int64_t layer, int64_t expert) const override;
|
||||
const uint8_t* device_alias(int64_t layer, int64_t expert) const override;
|
||||
/// Prefix pinning: the old rule (device_alias(layer, 0)); pin by need: at least one pinned range in the layer.
|
||||
@@ -985,7 +988,7 @@ private:
|
||||
const uint8_t* base_ = nullptr;
|
||||
int64_t blobs_ = 0;
|
||||
int64_t n_expert_ = 0;
|
||||
int64_t reads_ = 0;
|
||||
std::atomic<int64_t> reads_{0}; ///< (a counter only; two threads can read blobs at once)
|
||||
std::string note_;
|
||||
std::string ram_warning_;
|
||||
double gib_per_s_ = 0.0;
|
||||
|
||||
@@ -92,6 +92,10 @@ public:
|
||||
/// --pipeline-windows: capture the prefill graphs and size its input records for windows of up to max_t rows now,
|
||||
/// so a later prefill(sync = false) of a window neither captures nor allocates (both wait for the device).
|
||||
bool prepare_prefill(std::string& err);
|
||||
/// A prompt read beside running batch windows (STRATA_PIPED_CONCURRENT): the prompt pass's graphs captured and its
|
||||
/// input records sized for chunks of up to n rows now, with nothing in flight. On the read's thread a capture or
|
||||
/// a free waits for the device, whose windows wait for the main thread's doorbell service (#31).
|
||||
bool reserve_prefill(int64_t n, std::string& err);
|
||||
cudaStream_t stream() const { return cs_; }
|
||||
|
||||
/// One round: catch-up over T cells from `p` (rows = the window's final residuals, `tokens` = the window's
|
||||
|
||||
@@ -113,6 +113,41 @@ public:
|
||||
return e;
|
||||
}
|
||||
|
||||
// Every slot holds at least `bytes` from here on: grown now, by a caller that must not allocate later (a pinned
|
||||
// allocation or free takes the driver's lock and can wait for the device: STRATA_PIPED_CONCURRENT grows the rings
|
||||
// before a read whose windows run beside it). On the device that is current, as acquire(). False: a slot could
|
||||
// not be had (its uploads then grow it, or go up from the caller's memory, as before).
|
||||
bool reserve(size_t bytes) {
|
||||
if (bytes == 0 || pageable_forced()) return true;
|
||||
int cur = -1;
|
||||
if (cudaGetDevice(&cur) != cudaSuccess) { cudaGetLastError(); return false; }
|
||||
if (dev_ < 0) dev_ = cur;
|
||||
if (cur != dev_) return false;
|
||||
for (Slot& sl : slots_) {
|
||||
if (sl.cap >= bytes && sl.ev != nullptr) continue;
|
||||
if (sl.pending) {
|
||||
sl.pending = false;
|
||||
if (cudaEventSynchronize(sl.ev) != cudaSuccess) { cudaGetLastError(); return false; }
|
||||
}
|
||||
if (sl.cap < bytes) {
|
||||
if (sl.p) { cudaFreeHost(sl.p); sl.p = nullptr; sl.cap = 0; }
|
||||
const size_t cap = bytes < kMinCap ? kMinCap : bytes;
|
||||
if (cudaHostAlloc(&sl.p, cap, cudaHostAllocPortable) != cudaSuccess) {
|
||||
cudaGetLastError();
|
||||
sl.p = nullptr;
|
||||
return false;
|
||||
}
|
||||
sl.cap = cap;
|
||||
}
|
||||
if (sl.ev == nullptr && cudaEventCreateWithFlags(&sl.ev, cudaEventDisableTiming) != cudaSuccess) {
|
||||
cudaGetLastError();
|
||||
sl.ev = nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void release() {
|
||||
for (Slot& sl : slots_) {
|
||||
if (sl.pending && sl.ev) cudaEventSynchronize(sl.ev);
|
||||
|
||||
@@ -178,6 +178,14 @@ public:
|
||||
/// Is the zero-doorbell graph the one a batch window would run now (every expert of the stage in VRAM by the host
|
||||
/// table)? Looks at the table, as each window does. (STRATA_ADMIT_MERGE_FIRST's gate.)
|
||||
bool ar_live() { refresh_ar(); return ar_on(); }
|
||||
/// STRATA_SPLIT_OVERLAP=1 (opt-in; stages on DIFFERENT devices only): the hand-off carries a ready flag (one
|
||||
/// mapped word per hand-off buffer: host and device addresses). The writing stage raises it from the GPU when
|
||||
/// its hand-off is out (handoff_publish); the reading stage's window graph waits on it (wait_flag_ge) - so the
|
||||
/// next stage's graph is launched while this stage is still running, and the host no longer syncs between the
|
||||
/// stages. Null (the default): the old order - sync, then launch the next stage. Set before `init`.
|
||||
void set_handoff_flags(uint32_t* in_host, uint32_t* in_dev, uint32_t* out_host, uint32_t* out_dev) {
|
||||
hflag_in_h_ = in_host; hflag_in_d_ = in_dev; hflag_out_h_ = out_host; hflag_out_d_ = out_dev;
|
||||
}
|
||||
/// The next stage: `run` and `commit` continue into it (its pool calls get `next_user`); sampling settings
|
||||
/// and `final_R` are the last stage's.
|
||||
void set_next(Verifier* next, void* next_user) { next_ = next; next_user_ = next_user; }
|
||||
@@ -225,7 +233,14 @@ public:
|
||||
/// 1 = this stage's window and commit are done (the last stage's picks are in batch_out), 0 = still running,
|
||||
/// -1 = an error (err). Serves every layer that has rung so far.
|
||||
int batch_poll(PoolMultiFn pool, void* user, std::string& err);
|
||||
bool batch_busy() const { return b_running_; }
|
||||
bool batch_busy() const { return b_running_.load(std::memory_order_acquire); }
|
||||
/// Serves the layers of this stage's window that have rung (the CPU pool and the flags), with no CUDA call: 1 once
|
||||
/// every layer is served (or the window raises no host doorbells), 0 while one is still to ring. batch_poll
|
||||
/// calls it, unless set_external_serve(true) moved it to a thread of its own (STRATA_PIPED_CONCURRENT: a CUDA
|
||||
/// call can wait for the driver's lock while another thread holds it waiting for the GPU, whose window waits
|
||||
/// for its doorbell, #31); batch_poll then makes no CUDA call before every layer is served.
|
||||
int batch_serve(PoolMultiFn pool, void* user);
|
||||
void set_external_serve(bool on) { ext_serve_.store(on, std::memory_order_release); }
|
||||
/// A slot's sampling (temperature / top_p / top_k / min_p / seed; penalties are not applied in batch windows):
|
||||
/// its row is drawn again on the last stage with Philox(seed, position), as a solo window draws it. Greedy by
|
||||
/// default. Set on the first stage, it reaches the last.
|
||||
@@ -349,10 +364,22 @@ private:
|
||||
for (int t = 0; t < S; ++t) k.push_back(rows[t]);
|
||||
return k;
|
||||
}
|
||||
// batch_launch / batch_poll
|
||||
bool b_running_ = false;
|
||||
int64_t b_k_ = 0, b_steps_ = 0;
|
||||
std::chrono::steady_clock::time_point b_last_;
|
||||
// batch_launch / batch_poll (with external serving, batch_serve runs on another thread: running and the served
|
||||
// layer count are atomics, set by batch_launch before running)
|
||||
std::atomic<bool> b_running_{false};
|
||||
std::atomic<int64_t> b_k_{0};
|
||||
int64_t b_steps_ = 0;
|
||||
std::atomic<bool> ext_serve_{false};
|
||||
// when a layer was last served (steady clock ticks): the serving thread writes it, batch_poll's checks read it
|
||||
std::atomic<int64_t> b_last_{0};
|
||||
void ring_now() {
|
||||
b_last_.store((int64_t) std::chrono::steady_clock::now().time_since_epoch().count(), std::memory_order_release);
|
||||
}
|
||||
std::chrono::steady_clock::time_point last_ring() const {
|
||||
return std::chrono::steady_clock::time_point(
|
||||
std::chrono::steady_clock::duration(b_last_.load(std::memory_order_acquire)));
|
||||
}
|
||||
std::chrono::steady_clock::time_point ext_checked_{}; ///< batch_poll's last check with external serving
|
||||
int32_t b_out_[8] = {};
|
||||
std::vector<strata::kernels::SamplerParams> slot_sp_;
|
||||
bool sample_rows(int S, std::string& err); ///< the sampled slots' rows of the last batch window
|
||||
@@ -423,6 +450,21 @@ private:
|
||||
int handoff_rows_ = 0; ///< set_handoff_rows (0: kVerifyMaxT)
|
||||
const float* hand_in_ = nullptr;
|
||||
float* hand_out_ = nullptr;
|
||||
uint32_t* hflag_in_h_ = nullptr; ///< set_handoff_flags: the incoming hand-off's ready word (host / device)
|
||||
uint32_t* hflag_in_d_ = nullptr;
|
||||
uint32_t* hflag_out_h_ = nullptr; ///< ... and the outgoing one's
|
||||
uint32_t* hflag_out_d_ = nullptr;
|
||||
uint32_t* hcount_d_ = nullptr; ///< handoff_publish's block counter (device memory)
|
||||
uint32_t* herr_h_ = nullptr; ///< the bounded hand-off wait gave up (mapped; the reading stage's)
|
||||
uint32_t* herr_d_ = nullptr;
|
||||
uint32_t* hdrop_h_ = nullptr; ///< STRATA_TEST_HANDOFF_DROP: the writing stage withholds its flag (mapped)
|
||||
uint32_t* hdrop_d_ = nullptr;
|
||||
bool handoff_failed(std::string& err) const; ///< the bounded hand-off wait timed out in the last window
|
||||
int prelaunched_ = 0; ///< prelaunch ran for a window of this size: run skips staging + launch
|
||||
/// The overlapped split: stage this window's inputs and launch its graph now (the graph waits on the hand-off
|
||||
/// flag); `run` then only serves the host side. Called on a helper thread while the previous stage runs.
|
||||
bool prelaunch(int T, const int32_t* tokens, int64_t pos0, std::string& err);
|
||||
bool chain_overlap() const; ///< this stage hands off through a flag to a next stage that waits on it
|
||||
Verifier* next_ = nullptr;
|
||||
void* next_user_ = nullptr;
|
||||
bool ple_stage() const { return lb_ <= 1 && 1 < le_; } ///< holds layer 1, where the PLE block runs
|
||||
|
||||
@@ -32,6 +32,13 @@ struct QsaAttnPools {
|
||||
const int32_t* page_table = nullptr;
|
||||
};
|
||||
|
||||
/// Batch windows: every query's own K/V pools - query z reads p[z] (z < n). n = 0: the call's one `pools`.
|
||||
inline constexpr int kAttnRowsMax = 8;
|
||||
struct QsaAttnPoolsRows {
|
||||
QsaAttnPools p[kAttnRowsMax];
|
||||
int n = 0;
|
||||
};
|
||||
|
||||
/// Scratch floats for `cap` selected cells: partial accumulators, maxima and sums.
|
||||
uint64_t qsa_decode_attn_scratch_floats(int64_t cap, const QsaShapes& s);
|
||||
|
||||
@@ -68,5 +75,9 @@ void qsa_decode_attn_chunks_only(const float* q, const QsaAttnPools& pools, cons
|
||||
void* stream);
|
||||
void qsa_decode_attn_merge_only(const int32_t* steps, int64_t cap, const QsaShapes& s, const float* scratch,
|
||||
float* attn, int64_t n_q, int v2, void* stream);
|
||||
/// qsa_decode_attn_batch for up to kAttnRowsMax queries of DIFFERENT sequences (batch slots), query z attending
|
||||
/// over rows.p[z] - one launch instead of one per query, the same per-query arithmetic (bit-identical outputs).
|
||||
void qsa_decode_attn_batch_rows(const float* q, const QsaAttnPoolsRows& rows, const int32_t* ids, const int32_t* steps,
|
||||
int64_t cap, const QsaShapes& s, float* scratch, float* attn, int64_t n_q, void* stream);
|
||||
|
||||
} // namespace strata::kernels
|
||||
@@ -24,6 +24,16 @@
|
||||
namespace strata::kernels {
|
||||
|
||||
/// scores [nq, max_blocks]; q_idx [nq, idx_n_head, idx_dim] (normed and rotated); steps [nq, kStepCount].
|
||||
/// Batch windows: query q's own indexer keys - pooled[q], dead[q] (q < n <= 8).
|
||||
struct QsaScoreRows {
|
||||
const float* pooled[8] = {};
|
||||
const float* dead[8] = {};
|
||||
int n = 0;
|
||||
};
|
||||
/// qsa_block_scores for up to 8 queries of DIFFERENT sequences in one launch (the multi kernel, per query its own
|
||||
/// keys; the same arithmetic in the same order: bit-identical scores).
|
||||
void qsa_block_scores_rows(const QsaScoreRows& rows, const float* q_idx, const int32_t* steps, int64_t nq,
|
||||
int64_t max_blocks, const QsaShapes& s, float* scores, void* stream);
|
||||
void qsa_block_scores(const float* pooled, const float* dead, const float* q_idx, const int32_t* steps, int64_t nq,
|
||||
int64_t max_blocks, const QsaShapes& s, float* scores, void* stream,
|
||||
int64_t active_blocks = -1); ///< perf-review C-1: > 0 launches only this many blocks (the
|
||||
|
||||
@@ -38,6 +38,20 @@ void gdn_ab_multi(const float* x, const uint16_t* w_alpha, const uint16_t* w_bet
|
||||
/// The recurrence + output norm for T tokens (h = (T, conv_channels) as q|k|v, gate/beta (T, h_v), z/y
|
||||
/// (T, value_dim)). With `n_keep == nullptr` the state is read and NOT written (verify); otherwise the first
|
||||
/// *n_keep tokens are run and the state is written (commit; `y` may be scratch). Bitwise `fused_gdn_step_norm`.
|
||||
/// Batch windows: up to 8 slot groups in one launch - group i is rows [first[i], first[i] + ntok[i]) of the
|
||||
/// window's buffers, recurring over its own slot's state[i] (and committing keep[i] tokens when keep is given).
|
||||
struct GdnGroups {
|
||||
float* state[8] = {};
|
||||
const int32_t* keep[8] = {};
|
||||
int first[8] = {};
|
||||
int ntok[8] = {};
|
||||
int n = 0;
|
||||
};
|
||||
/// gdn_step_norm_multi over several slots' groups at once (the generic kernel, grid.y = group; per group the
|
||||
/// same arithmetic as one call each: bit-identical). `commit`: every group keeps *keep[i] tokens, no outputs used.
|
||||
void gdn_step_norm_groups(const GdnGroups& groups, const float* h, int conv_channels, const float* gate, const float* beta,
|
||||
const float* z, const float* gamma, float eps, float* y, int h_k, int h_v, bool commit,
|
||||
void* stream);
|
||||
void gdn_step_norm_multi(float* state, const float* h, int conv_channels, const float* gate, const float* beta,
|
||||
const float* z, const float* gamma, float eps, float* y, int h_k, int h_v, int n_tok,
|
||||
const int32_t* n_keep, void* stream, int t_out_begin = 0, void* xq_out = nullptr);
|
||||
@@ -60,6 +74,17 @@ void wait_flag_ge(const uint32_t* flag, uint32_t value, void* stream);
|
||||
/// kernel costs ~2.4 us on a gfx1201 graph whatever it does. n <= 128 * k for any k (a strided loop).
|
||||
void wait_copy_i32_from_mapped(const uint32_t* flag, uint32_t value, int32_t* dst, const int32_t* src, int64_t n,
|
||||
void* stream);
|
||||
|
||||
/// Layer split, overlapped hand-off (STRATA_SPLIT_OVERLAP): dst (mapped) = [a (na) | b (nb) | c (nc)] with volatile
|
||||
/// stores, then the LAST block to finish raises *flag = 1 (mapped) after a system fence, so the next stage's GPU can
|
||||
/// start (wait_flag_ge(flag, 1)) without the host syncing this stage first. `counter` is one device word, 0 between
|
||||
/// calls (the last block resets it). Volatile because on RDNA a plain store to mapped memory can sit in the L2.
|
||||
/// `drop` (mapped, may be null): a test hook - nonzero leaves the flag down, as if the publish were lost.
|
||||
void handoff_publish(float* dst, const float* a, int64_t na, const float* b, int64_t nb, const float* c, int64_t nc,
|
||||
uint32_t* counter, uint32_t* flag, void* stream, const uint32_t* drop = nullptr);
|
||||
/// The reading stage's hand-off wait, bounded: spin until *flag >= value, or after timeout_ns (0: no bound) set
|
||||
/// *err = 1 (mapped) and return, so the window's graph completes and the host fails the window cleanly.
|
||||
void wait_handoff(const uint32_t* flag, uint32_t value, uint32_t* err, unsigned long long timeout_ns, void* stream);
|
||||
/// the GPU's %globaltimer (ns) into buf[i] (a one-thread kernel: the verify window's stage profiler). Inside a PDL
|
||||
/// stretch (pdl.hpp) the stamp passes the early launch on, so a profiled window keeps the chain it measures.
|
||||
void gpu_stamp(unsigned long long* buf, int i, void* stream);
|
||||
|
||||
@@ -159,6 +159,7 @@ struct State {
|
||||
std::vector<int> allowed; ///< the process's CPUs, snapshotted before any thread is pinned
|
||||
std::vector<int> plan; ///< the aux CPUs (empty: nothing to do)
|
||||
std::vector<int> workers; ///< the pool's CPUs: their threads are never touched
|
||||
int host_cpu = -1; ///< the CPU the host thread is pinned to (-1: unknown)
|
||||
cpu_set_t target;
|
||||
std::set<int> owned; ///< tids of pool workers and host threads
|
||||
std::map<int, cpu_set_t> original; ///< tid -> the mask it had before this module moved it
|
||||
@@ -286,6 +287,66 @@ inline void set_enabled(bool on) {
|
||||
|
||||
inline bool enabled() { return detail::state().enabled.load(std::memory_order_acquire); }
|
||||
|
||||
namespace detail {
|
||||
/// The CPUs a thread that must not share the host's core runs on: every CPU the process may use but the host's and
|
||||
/// the pool workers' (on an SMT machine with the default pool, the idle sibling threads); without such CPUs, every CPU
|
||||
/// but the host's; failing that, every CPU. Caller holds `mu`. False when `configure` saw no CPUs.
|
||||
inline bool off_host_target_locked(const State& s, cpu_set_t& out) {
|
||||
if (s.allowed.empty()) return false;
|
||||
auto build = [&](bool skip_workers) {
|
||||
CPU_ZERO(&out);
|
||||
int n = 0;
|
||||
for (int c : s.allowed) {
|
||||
if (c == s.host_cpu) continue;
|
||||
if (skip_workers && std::find(s.workers.begin(), s.workers.end(), c) != s.workers.end()) continue;
|
||||
CPU_SET(c, &out);
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
};
|
||||
if (build(true) > 0 || build(false) > 0) return true;
|
||||
CPU_ZERO(&out);
|
||||
for (int c : s.allowed) CPU_SET(c, &out);
|
||||
return true;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
/// Puts the calling thread off the host's core and off the pool workers' CPUs (see off_host_target_locked). A thread
|
||||
/// the host creates inherits the host's single CPU; one that must not share that core (the concurrent prompt read's
|
||||
/// thread and its doorbell thread, STRATA_PIPED_CONCURRENT) calls this first. False when nothing changed.
|
||||
inline bool place_off_host() {
|
||||
detail::State& s = detail::state();
|
||||
std::lock_guard<std::mutex> lk(s.mu);
|
||||
cpu_set_t to;
|
||||
if (!detail::off_host_target_locked(s, to)) return false;
|
||||
return sched_setaffinity(0, sizeof to, &to) == 0;
|
||||
}
|
||||
|
||||
/// Called on the host thread: every other thread that runs on exactly the host's CPUs (it inherited them: the prefill
|
||||
/// copy threads started by the first prompt, a helper the host started) goes where place_off_host puts a thread. The
|
||||
/// pool's workers and the host threads are never moved. Returns how many moved.
|
||||
inline int release_host_inheritors() {
|
||||
detail::State& s = detail::state();
|
||||
std::lock_guard<std::mutex> lk(s.mu);
|
||||
cpu_set_t host, all, to;
|
||||
CPU_ZERO(&host);
|
||||
CPU_ZERO(&all);
|
||||
if (!detail::off_host_target_locked(s, to) || sched_getaffinity(0, sizeof host, &host) != 0) return 0;
|
||||
for (int c : s.allowed) CPU_SET(c, &all);
|
||||
if (detail::same_mask(host, all)) return 0; // the host is not pinned: nothing inherited a single core
|
||||
detail::purge_locked(s);
|
||||
const int self = detail::self_tid();
|
||||
int n = 0;
|
||||
for (int tid : detail::task_ids()) {
|
||||
if (tid == self || s.owned.find(tid) != s.owned.end()) continue;
|
||||
cpu_set_t m;
|
||||
CPU_ZERO(&m);
|
||||
if (sched_getaffinity(tid, sizeof m, &m) != 0 || !detail::same_mask(m, host)) continue;
|
||||
if (sched_setaffinity(tid, sizeof to, &to) == 0) ++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/// The aux CPUs of the plan ({} when there is none).
|
||||
inline std::vector<int> plan() {
|
||||
detail::State& s = detail::state();
|
||||
@@ -324,6 +385,7 @@ inline std::string set_topology(int host_cpu, const std::vector<int>& worker_cpu
|
||||
: derive(allowed, host_cpu, worker_cpus);
|
||||
s.plan = plan;
|
||||
s.workers = worker_cpus;
|
||||
s.host_cpu = host_cpu;
|
||||
CPU_ZERO(&s.target);
|
||||
for (int c : plan) CPU_SET(c, &s.target);
|
||||
s.have_plan.store(!plan.empty(), std::memory_order_release);
|
||||
@@ -353,6 +415,8 @@ inline void pin_current_thread() {}
|
||||
inline int restore() { return 0; }
|
||||
inline void set_enabled(bool) {}
|
||||
inline bool enabled() { return false; }
|
||||
inline bool place_off_host() { return false; } // (a new thread does not inherit the host's CPU set here)
|
||||
inline int release_host_inheritors() { return 0; }
|
||||
inline std::vector<int> plan() { return {}; }
|
||||
inline std::string set_topology(int, const std::vector<int>&) { return "strata aux cpus: not available on this system"; }
|
||||
|
||||
|
||||
@@ -154,6 +154,17 @@ public:
|
||||
|
||||
/// Checked before every chunk: true stops the prompt early (`run` returns false with err "cancelled").
|
||||
std::function<bool()> should_stop;
|
||||
/// The first stage only, checked before every chunk but the first: true ends the run there as if the prompt
|
||||
/// ended there. `run` returns true once every stage has read the tokens before that chunk, and `stopped_at()`
|
||||
/// says how many of the run's tokens that is (-1 when the run read them all). A read beside the batch slots
|
||||
/// (STRATA_PIPED_CONCURRENT) gives way to a waiting shorter request there.
|
||||
std::function<bool()> stop_at_chunk;
|
||||
int64_t stopped_at() const { return stopped_at_; }
|
||||
/// Grows this stage's (and the later stages') pinned upload slots to what a text chunk of `T` tokens uploads, so
|
||||
/// a run of such chunks allocates no pinned memory (STRATA_PIPED_CONCURRENT: an allocation or free on the read's
|
||||
/// thread takes the driver's lock). Before the run, with nothing of this path in flight. False: a slot could
|
||||
/// not be had (it then grows at first use, as before).
|
||||
bool reserve_uploads(int64_t T);
|
||||
|
||||
/// The vision path: HOST rows (n_embd floats) indexed by absolute position, read in place of the token
|
||||
/// embedding where non-null (an image's <|image_pad|> cells). Null (default): every position embeds its token.
|
||||
@@ -206,6 +217,7 @@ private:
|
||||
Prefill* next_ = nullptr;
|
||||
Prefill* helper_ = nullptr; ///< set_stage_helper
|
||||
bool single_chunk_ = false; ///< a later stage: the prompt is one chunk (set by the stage before)
|
||||
int64_t stopped_at_ = -1; ///< stop_at_chunk ended the last run after this many tokens (-1: it read all)
|
||||
bool bind_stage_helper(int64_t T); // binds the helper's buffers for a one-chunk prompt of T tokens
|
||||
const float* hand_in_ = nullptr; ///< the previous stage's rows of the chunk being read (host, pinned)
|
||||
/// STRATA_HANDOFF_PIPE: the previous stage's per-piece "landed in hand_in_" events (cudaEvent_t[hand_pieces_],
|
||||
|
||||
@@ -27,4 +27,61 @@ inline int64_t batch_read_piece(bool batch, bool piped, bool layer_split, bool b
|
||||
return chunks_per_piece > 0 ? chunk * chunks_per_piece : 0;
|
||||
}
|
||||
|
||||
/// What a configuration has that keeps the concurrent read (STRATA_PIPED_CONCURRENT=1) off.
|
||||
struct ConcurrentReadSetup {
|
||||
bool prefill_help = false; ///< STRATA_PREFILL_HELP: the idle stage's help allocates on the read's thread
|
||||
bool split_mtp_batch = false; ///< STRATA_SPLIT_MTP_BATCH: the batched draft K/V frees there (a free waits)
|
||||
bool fs_slots = false; ///< STRATA_FS_SLOTS (Foresight swap space): serving a doorbell makes a CUDA call
|
||||
bool pcie_dma = false; ///< --pcie-mode dma: the same (its copies)
|
||||
bool helper_caches = false; ///< --expert-cache-device1..3 (and --remote-expert-opt on them), a prompt source of
|
||||
///< its own; --remote-expert-opt alone is inert on a plain layer split
|
||||
bool staged_source = false; ///< the GGUF source stages its blobs (in place, unbuffered, STRATA_IO_PREFETCH):
|
||||
///< it recycles the buffers it hands out, one thread at a time
|
||||
bool other_source = false; ///< an expert source that is neither the GGUF source nor the arena
|
||||
};
|
||||
|
||||
/// Why the concurrent read stays off with `s` (the first reason, for the log line), or nullptr when it can run.
|
||||
inline const char* concurrent_read_off(const ConcurrentReadSetup& s) {
|
||||
if (s.prefill_help) return "STRATA_PREFILL_HELP";
|
||||
if (s.split_mtp_batch) return "STRATA_SPLIT_MTP_BATCH";
|
||||
if (s.fs_slots) return "STRATA_FS_SLOTS";
|
||||
if (s.pcie_dma) return "--pcie-mode dma";
|
||||
if (s.helper_caches) return "the helper caches (--expert-cache-device1..3)";
|
||||
if (s.staged_source)
|
||||
return "an expert source that stages its blobs (the GGUF in place, unbuffered, STRATA_IO_PREFETCH)";
|
||||
if (s.other_source) return "this expert source";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// Tokens of the next piece of a prompt read on the pipelined slot groups (--batch-groups > 1 on a layer split, #1906),
|
||||
/// or 0 for "the whole rest in one run" (the opt-in is off).
|
||||
/// piece_tokens: STRATA_PIPED_READ_PIECE, rounded down to whole chunks (at least one, at most kPipedMaxChunks)
|
||||
/// A piece is one pipelined run over its chunks, so the stages stay overlapped inside it and only its end drains the
|
||||
/// pipeline. At a piece's end the decoding slots decode, and a waiting shorter request can take over (BYIELD), as
|
||||
/// between the pieces of a read off the pipeline.
|
||||
inline constexpr int64_t kPipedMaxChunks = 32;
|
||||
inline int64_t piped_read_piece(int64_t piece_tokens, int64_t chunk) {
|
||||
if (piece_tokens <= 0) return 0;
|
||||
chunk = std::max<int64_t>(chunk, 1);
|
||||
return std::clamp<int64_t>(piece_tokens / chunk, 1, kPipedMaxChunks) * chunk;
|
||||
}
|
||||
|
||||
/// The slots' decode time between two pieces: share x the piece's time (STRATA_BATCH_DECODE_SHARE, the rule the
|
||||
/// one-GPU path uses between chunks), at most cap_ms (STRATA_PIPED_DECODE_MAX_MS; <= 0: no cap), at least floor_ms
|
||||
/// (STRATA_PIPED_DECODE_MIN_MS).
|
||||
inline double piped_decode_budget_ms(double piece_ms, double share, double cap_ms, double floor_ms) {
|
||||
double b = std::max(0.0, share) * std::max(0.0, piece_ms);
|
||||
if (cap_ms > 0.0) b = std::min(b, cap_ms);
|
||||
return std::max(b, std::max(0.0, floor_ms));
|
||||
}
|
||||
|
||||
/// Prompts arriving back to back: a piecewise read that starts within kPipedLeadInWindowMs + budget_ms of the
|
||||
/// previous piecewise read's end first gives the slots one decode budget (otherwise they stop for both reads).
|
||||
/// ms_since_prev_end: < 0 when there was no piecewise read yet
|
||||
inline constexpr double kPipedLeadInWindowMs = 1000.0;
|
||||
inline bool piped_read_lead_in(bool enabled, bool beside_slots, double ms_since_prev_end, double budget_ms) {
|
||||
return enabled && beside_slots && ms_since_prev_end >= 0.0 &&
|
||||
ms_since_prev_end <= kPipedLeadInWindowMs + std::max(0.0, budget_ms);
|
||||
}
|
||||
|
||||
} // namespace strata::program
|
||||
Reference in new issue
Block a user