okami.mom/strata

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

Niko1221Merge f-142b-serve into f-1426e1085c1d

main
3.1 KiB60 linesraw
1diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp
2index 4e03dc8..48f5cf8 100644
3--- a/src/prefill/prefill.cpp
4+++ b/src/prefill/prefill.cpp
5@@ -1969,6 +1969,19 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
6     const core::ModelGeometry& g = *m.g;
7     core::SessionState& ss = *m.ss;
8     const auto t_start = Clock::now();
9+    const bool roofline = std::getenv("STRATA_PREFILL_ROOFLINE") != nullptr;
10+    uint64_t roof_bytes = 0, roof_unique_bytes = 0, roof_copies = 0, roof_unique = 0;
11+    std::vector<uint32_t> roof_counts(roofline ? (size_t) (g.n_layers * g.n_expert) : 0);
12+    // The serial issuer or the joined issuer thread owns this counter; peer copies are excluded.
13+    auto roof_copy = [&](int64_t l, int64_t e, size_t bytes) {
14+        if (!roofline) return;
15+        roof_bytes += bytes;
16+        ++roof_copies;
17+        if (roof_counts[(size_t) (l * g.n_expert + e)]++ == 0) {
18+            roof_unique_bytes += bytes;
19+            ++roof_unique;
20+        }
21+    };
22     const int64_t LB = stage_lb_, LE = stage_le_;
23     // The direct successor's future lives on the Prefill object. Intermediate
24     // stages therefore do not drain the complete remaining GPU chain here.
25@@ -2306,6 +2319,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
26                 m.stage_live[sl] = true;
27                 stats_.ms_experts_host += ms_since(th);
28                 ++stats_.experts_streamed;
29+                roof_copy(en.l, en.e, bytes);
30                 ++issued;
31             }
32         };
33@@ -2353,6 +2367,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
34                     m.stage_live[sl] = true;
35                     iss_ms += ms_since(th);
36                     ++iss_streamed;
37+                    roof_copy(en.l, en.e, bytes);
38                     a_issued.store(idx + 1, std::memory_order_release);
39                 }
40             });
41@@ -3580,6 +3595,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
42                             stage_of[j] = sl;
43                             stats_.ms_experts_host += ms_since(th);
44                             ++stats_.experts_streamed;
45+                            roof_copy(l, e, (size_t) lay.blob_bytes(l));
46                             return true;
47                         };
48                         // In the streamed walk an MMQ group is gathered in ONE launch, after ONE wait on its last
49@@ -4001,6 +4017,11 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
50                      (long long) kv_prefetches);
51     }
52     stats_.ms_total += ms_since(t_start);
53+    if (roofline) {
54+        std::fprintf(stderr, "strata prefill roofline: tokens %lld H2D_bytes %llu copies %llu unique_bytes %llu unique_experts %llu\n",
55+                     (long long) n, (unsigned long long) roof_bytes, (unsigned long long) roof_copies,
56+                     (unsigned long long) roof_unique_bytes, (unsigned long long) roof_unique);
57+    }
58     if (pt.on) {
59         pt.fold();
60         double total = 0.0;