| 96 | } |
| 97 | |
| 98 | bool 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 |
| 130 | struct Dflash2Drafter::Prof { |
nothing calls this directly
no test coverage detected