okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-sycl-prs e106b4c86 into the batch 16 candidate (SYCL pull requests 4185 and 3153)a8a51b280

main
1.6 KiB38 linesraw
1#pragma once
2#include <chrono>
3#include <cstdlib>
4// Only the pipeline owner thread calls these chain methods. The state belongs
5// to its current MtpDrafter and is reset before every chain and request. No
6// class definition or layout differs from the normal engine's archives.
7namespace strata::private_demand {
8struct State {
9    const void* owner = nullptr;
10    bool enabled = false, final = false;
11    int submitted = 0, target = 0, limit = 0;
12    long long chains = 0, requested = 0, actual = 0, continuations = 0, dead = 0;
13    bool metrics = false;
14    long long last_ready_ns = 0, reaction_ns = 0, submit_ns = 0, max_reaction_ns = 0;
15    int ordinal = 0, T = 0, a = 0, n_force = 0;
16    long long p = 0;
17    int tokens[8] = {}, force[8] = {};
18};
19inline long long now_ns() {
20    return std::chrono::duration_cast<std::chrono::nanoseconds>(
21        std::chrono::steady_clock::now().time_since_epoch()).count();
22}
23inline State& state() { static thread_local State s; return s; }
24inline State* get(const void* p) {
25    auto& s = state(); return s.enabled && s.owner == p ? &s : nullptr;
26}
27inline void begin(const void* p, bool on) {
28    auto& s = state(); const int ordinal = s.ordinal + int(on); s = State{};
29    s.owner = p; s.enabled = on; s.ordinal = ordinal;
30    s.metrics = std::getenv("STRATA_PRIVATE_MTP_DEMAND_LOG") || std::getenv("STRATA_PRIVATE_MTP_DEMAND_MICRO");
31}
32inline bool can_enqueue_s1(const void* p) {
33    auto* s = get(p); return !s || s->submitted == 0 || s->final;
34}
35inline void drain(const void* p) {
36    if (auto* s = get(p)) { s->target = s->limit; s->final = true; }
37}
38} // namespace strata::private_demand