multi-GPU: time the helper GPU's staging/launch and wait per request

This commit is contained in:
Niko1221 committed 2026-09-28 22:47:06 +02:00
1 parent 7dbe2bf85b
commit 4cd2461849
3 files changed
+14 -2

No files matched your search

+4
View File
@@ -43,6 +43,9 @@ public:
double gib() const { return cache_.gib(); }
uint64_t returned_bytes() const { return returned_bytes_; }
uint64_t full_row_bytes() const { return full_row_bytes_; }
/// host time spent in begin() (staging + launches) and in finish() (waiting for this GPU), cumulative
double ms_begin() const { return ms_begin_; }
double ms_wait() const { return ms_wait_; }
private:
int device_ = -1;
@@ -52,6 +55,7 @@ private:
int64_t launched_layers_ = 0;
uint64_t returned_bytes_ = 0;
uint64_t full_row_bytes_ = 0;
double ms_begin_ = 0, ms_wait_ = 0;
ExpertCache cache_;
cudaStream_t stream_ = nullptr;
float* h_x_ = nullptr;
+6
View File
@@ -6,6 +6,7 @@
#include "strata/kernels/s2_expert_grouped.hpp"
#include <algorithm>
#include <chrono>
#include <cstring>
namespace strata::core {
@@ -214,6 +215,9 @@ bool RemoteExperts::open(int device, int slots, int64_t layers, int64_t experts,
bool RemoteExperts::begin(int64_t layer, const float* x, const int32_t* ids, int64_t n_tok,
int64_t k, const int32_t* kind, const int32_t* primary_res,
std::string& err) {
// cumulative host time in here (staging and launches), reported per request by the driver
struct Timer { double& acc; std::chrono::steady_clock::time_point t0 = std::chrono::steady_clock::now();
~Timer() { acc += std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count(); } } timer{ms_begin_};
const int64_t n = n_tok * k;
if (n <= 0 || n > CAP || n_tok > strata::kernels::cpu::MAXT || k != 10 || layer < 0 ||
(size_t) layer >= layers_present_.size() || device_ < 0) {
@@ -296,7 +300,9 @@ bool RemoteExperts::finish(float* out, std::string& err) {
if (group_id_.empty()) return true;
DeviceScope scope(device_);
if (!scope.ok) { err = scope.error(device_); return false; }
const auto w0 = std::chrono::steady_clock::now();
if (!check(cudaStreamSynchronize(stream_), "finish", err, device_)) return false;
ms_wait_ += std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - w0).count();
for (size_t i = 0; i < original_row_.size(); ++i)
std::memcpy(out + (size_t) original_row_[i] * H, h_out_ + i * H, (size_t) H * sizeof(float));
return true;
+4 -2
View File
@@ -3520,11 +3520,13 @@ int main(int argc, char** argv) {
(long long) sfx_windows, (long long) sfx_ok, (long long) sfx_drafts);
for (int r = 0; r < 3; ++r) if (o.expert_cache_remote[(size_t) r] > 0)
std::fprintf(stderr, "strata serve: CUDA%d: %lld expert entries, %lld active layer launches, %.1f MiB returned "
"(%.1f MiB with full rows) in this request\n", r + 1,
"(%.1f MiB with full rows) in this request; host %.0f ms staging+launching, %.0f ms "
"waiting for it (since start)\n", r + 1,
(long long) (remote_experts[(size_t) r].computed() - remote_before[(size_t) r]),
(long long) (remote_experts[(size_t) r].launched_layers() - launches_before[(size_t) r]),
(double) (remote_experts[(size_t) r].returned_bytes() - compact_before[(size_t) r]) / 1048576.0,
(double) (remote_experts[(size_t) r].full_row_bytes() - full_before[(size_t) r]) / 1048576.0);
(double) (remote_experts[(size_t) r].full_row_bytes() - full_before[(size_t) r]) / 1048576.0,
remote_experts[(size_t) r].ms_begin(), remote_experts[(size_t) r].ms_wait());
}
return 0;
}