| 5591 | } |
| 5592 | |
| 5593 | bool Verifier::capture_deferred(const int* rows, int S, int hbase, std::string& err) { |
| 5594 | using namespace strata::kernels; |
| 5595 | const auto key = bkey(rows, S, hbase); |
| 5596 | cudaGraphExec_t& sex = save_bm_[key]; |
| 5597 | cudaGraphExec_t& cex = dcommit_bm_[key]; |
| 5598 | if (sex != nullptr && cex != nullptr) return true; |
| 5599 | const ModelGeometry& g = *g_; |
| 5600 | const QsaShapes s = shapes_of(g); |
| 5601 | const int64_t C = g.ssm_conv_channels, HV = g.ssm_v_heads, ZV = g.ssm_value_dim, ID = g.idx_key_dim, MT = max_t_; |
| 5602 | const int64_t R = dc_rows_, CB = 2 + MT, nQ = g.n_qsa_layers(); |
| 5603 | const uint64_t gdn_floats = (uint64_t) g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size + |
| 5604 | (uint64_t) g.ssm_conv_channels * (g.ssm_d_conv - 1); |
| 5605 | const int64_t TS = (s.idx_block - 1) * ID; |
| 5606 | const int64_t HS = (int64_t) NG_HIST * NG_HC_DIM; |
| 5607 | const bool ple = ss_->ple.ready() && ple_stage(); |
| 5608 | auto layer_index = [&](int64_t& qsa_index, int64_t& gdn_index) { |
| 5609 | qsa_index = gdn_index = 0; |
| 5610 | for (int64_t l = 0; l < lb_; ++l) (is_qsa_layer(g, l) ? qsa_index : gdn_index) += 1; |
| 5611 | }; |
| 5612 | auto finish = [&](cudaGraphExec_t& ex, bool ok, const char* what) { |
| 5613 | cudaGraph_t graph = nullptr; |
| 5614 | const cudaError_t ce = cudaStreamEndCapture(cs_, &graph); |
| 5615 | if (!ok || ce != cudaSuccess) { |
| 5616 | if (graph) cudaGraphDestroy(graph); |
| 5617 | if (ok) err = std::string(what) + cudaGetErrorString(ce); |
| 5618 | return false; |
| 5619 | } |
| 5620 | const bool made = instantiate_evicting(ex, graph, key, what, err); |
| 5621 | cudaGraphDestroy(graph); |
| 5622 | return made; |
| 5623 | }; |
| 5624 | // the save: the window's rows [0, S) of the scratch the commit replays -> the group's saved rows [hbase, +S) |
| 5625 | if (sex == nullptr) { |
| 5626 | if (cudaStreamBeginCapture(cs_, cudaStreamCaptureModeThreadLocal) != cudaSuccess) { |
| 5627 | err = "verify: begin save capture failed"; |
| 5628 | return false; |
| 5629 | } |
| 5630 | bool ok = true; |
| 5631 | int64_t qsa_index = 0, gdn_index = 0; |
| 5632 | layer_index(qsa_index, gdn_index); |
| 5633 | auto copy = [&](float* dst, const float* src, int64_t n) { |
| 5634 | ok = ok && cudaMemcpyAsync(dst, src, (size_t) n * sizeof(float), cudaMemcpyDeviceToDevice, cs_) == cudaSuccess; |
| 5635 | }; |
| 5636 | for (int64_t l = lb_; l < le_; ++l) { |
| 5637 | if (!is_qsa_layer(g, l)) { |
| 5638 | copy(dc_qkv_ + (size_t) (gdn_index * R + hbase) * C, qkv_L_ + (size_t) gdn_index * MT * C, S * C); |
| 5639 | copy(dc_h_ + (size_t) (gdn_index * R + hbase) * C, h_L_ + (size_t) gdn_index * MT * C, S * C); |
| 5640 | copy(dc_gate_ + (size_t) (gdn_index * R + hbase) * HV, gate_L_ + (size_t) gdn_index * MT * HV, S * HV); |
| 5641 | copy(dc_beta_ + (size_t) (gdn_index * R + hbase) * HV, beta_L_ + (size_t) gdn_index * MT * HV, S * HV); |
| 5642 | ++gdn_index; |
| 5643 | } else { |
| 5644 | copy(dc_idx_ + (size_t) (qsa_index * R + hbase) * ID, idx_raw_L_ + (size_t) qsa_index * MT * ID, S * ID); |
| 5645 | ++qsa_index; |
| 5646 | } |
| 5647 | } |
| 5648 | if (ple) copy(dc_hist_ + (size_t) hbase * HS, hist_snap_, S * HS); |
| 5649 | if (!finish(sex, ok, "verify: save capture: ")) { |
| 5650 | if (ok && err.empty()) err = "verify: save capture failed"; |
nothing calls this directly
no test coverage detected