MCPcopy Create free account
hub / github.com/Niko1221/Strata / ensure_ctx_batch

Method ensure_ctx_batch

engine/src/core/dflash2.cpp:98–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98bool Dflash2Drafter::ensure_ctx_batch(std::string& err) {
99 if (ctx_batch_) return true;
100 auto* cb = new CtxBatch();
101 constexpr int B = CtxBatch::kB;
102 auto dev = [&](auto** p, size_t n) {
103 using T = std::remove_pointer_t<std::remove_reference_t<decltype(*p)>>;
104 return cudaMalloc((void**) p, n * sizeof(T)) == cudaSuccess;
105 };
106 const size_t tap_n = std::max<size_t>(taps_.size(), 1) * (size_t) N_;
107 bool ok = dev(&cb->pos, B) && dev(&cb->rt, (size_t) B * 128) &&
108 dev(&cb->xqc, (size_t) B * tap_n + 4096) && dev(&cb->xdc, (size_t) B * (tap_n / 32) + 64) &&
109 dev(&cb->fcy, (size_t) B * N_) && dev(&cb->kc, (size_t) B * NKV_ * HD_) &&
110 dev(&cb->vc, (size_t) B * NKV_ * HD_);
111 for (int i = 0; ok && i < 2; ++i) {
112 ok = cudaEventCreateWithFlags(&cb->ev[i], cudaEventDisableTiming) == cudaSuccess;
113 if (ok && log_on_) {
114 ok = cudaHostAlloc((void**) &cb->h_logq[i], (size_t) B * N_, cudaHostAllocDefault) == cudaSuccess &&
115 cudaHostAlloc((void**) &cb->h_logd[i], (size_t) B * (N_ / 32) * sizeof(float), cudaHostAllocDefault) == cudaSuccess;
116 }
117 }
118 if (!ok) {
119 (void) cudaGetLastError();
120 ctx_batch_ = cb;
121 free_ctx_batch();
122 (void) err;
123 return false;
124 }
125 ctx_batch_ = cb;
126 return true;
127}
128
129// STRATA_DF2_PROFILE=1 (measurement only): the round runs without its graph and an event follows every stage; the per-stage averages print at exit
130struct Dflash2Drafter::Prof {

Callers

nothing calls this directly

Calls 6

devFunction · 0.70
cudaMallocFunction · 0.50
cudaEventCreateWithFlagsFunction · 0.50
cudaHostAllocFunction · 0.50
cudaGetLastErrorFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected