DeepSeek Metal: DS4_BUSY_ALL experiment (off), progress lines
This commit is contained in:
1 parent
8d3c976166
commit
90359513e3
3 files changed
+20
-2
No files matched your search
+5
-2
@@ -218,6 +218,7 @@ struct Busy {
|
||||
id<MTLComputePipelineState> ps = nil;
|
||||
id<MTLBuffer> flag = nil;
|
||||
id<MTLCommandBuffer> last = nil;
|
||||
bool running = false;
|
||||
};
|
||||
Busy g_busy;
|
||||
} // namespace
|
||||
@@ -250,7 +251,8 @@ kernel void busy_spin(device volatile atomic_uint* flag [[buffer(0)]], constant
|
||||
g_busy.ok = true;
|
||||
}
|
||||
}
|
||||
if (!g_busy.ok) return;
|
||||
if (!g_busy.ok || g_busy.running) return;
|
||||
g_busy.running = true;
|
||||
if (g_busy.last != nil) [g_busy.last waitUntilCompleted]; // (the previous spin has left)
|
||||
*(volatile uint32_t*) [g_busy.flag contents] = 0;
|
||||
uint32_t cap = std::getenv("DS4_BUSY_CAP") ? (uint32_t) std::atoi(std::getenv("DS4_BUSY_CAP")) : 20000u; // ~ tens of ms at most
|
||||
@@ -266,8 +268,9 @@ kernel void busy_spin(device volatile atomic_uint* flag [[buffer(0)]], constant
|
||||
}
|
||||
}
|
||||
extern "C" void ds4_busy_end() {
|
||||
if (!g_busy.ok || g_busy.last == nil) return;
|
||||
if (!g_busy.ok || g_busy.last == nil || !g_busy.running) return;
|
||||
*(volatile uint32_t*) [g_busy.flag contents] = 1;
|
||||
g_busy.running = false;
|
||||
}
|
||||
|
||||
Context::Context() : impl_(new Impl) {
|
||||
|
||||
@@ -991,6 +991,14 @@ int main(int argc, char** argv) {
|
||||
out.push_back(tok);
|
||||
std::printf("%d,", tok);
|
||||
std::fflush(stdout);
|
||||
if (std::getenv("DS4_PROGRESS") && out.size() % 200 == 0) { // (sustained-run time series)
|
||||
static double tp = now_ms();
|
||||
static size_t np = 0;
|
||||
const double tn = now_ms();
|
||||
std::fprintf(stderr, "progress %zu tokens: %.2f tok/s over the last %zu\n", out.size(), 1000.0 * (double) (out.size() - np) / (tn - tp), out.size() - np);
|
||||
tp = tn;
|
||||
np = out.size();
|
||||
}
|
||||
if ((tok == 1 && std::getenv("DS4_NO_EOS") == nullptr) || (int) out.size() >= n) break; // (DS4_NO_EOS: decode n tokens whatever)
|
||||
if (got.empty()) {
|
||||
int off = 0, acc = 0;
|
||||
|
||||
@@ -7584,6 +7584,13 @@ struct Model::Impl {
|
||||
}
|
||||
|
||||
bool forward(const int* tk, int T, int logits_rows, std::string& err, int seed_rows = -1) {
|
||||
#if defined(STRATA_METAL)
|
||||
struct BusyAll { // DS4_BUSY_ALL: the GPU is held busy for the whole step (the host gaps between its bursts too)
|
||||
bool on;
|
||||
BusyAll() : on(std::getenv("DS4_BUSY_ALL") != nullptr) { if (on) ds4_busy_begin(); }
|
||||
~BusyAll() { if (on) ds4_busy_end(); }
|
||||
} busy_all;
|
||||
#endif
|
||||
if (T < 1 || T > kWin) {
|
||||
err = "a window of " + std::to_string(T) + " tokens";
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user