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

Method draft_launch

engine/src/core/dflash2.cpp:1174–1216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1172}
1173
1174bool Dflash2Drafter::draft_launch(const float* taps, int n_new, int64_t pos0, int32_t anchor, std::string& err) {
1175 if (!bound_) { err = "dflash2: not bound"; return false; }
1176 if (!context_wait(err)) return false;
1177 if (n_new < 1 || n_new > kRows) { err = "dflash2: draft rows out of range"; return false; }
1178 const OnDevice on_device(device_);
1179 const Clock::time_point t0 = Clock::now();
1180 if (graph_taps_ != nullptr && graph_taps_ != taps) { err = "dflash2: the taps buffer moved after capture"; return false; }
1181 if (!prof_ && !exec_[n_new]) {
1182 // the staging must hold valid positions while the capture runs the (empty) kernels' parameter checks
1183 for (int i = 0; i < 8; ++i) h_meta_[i] = (int32_t) (pos0 + i);
1184 if (!capture(n_new, taps, err)) return false;
1185 graph_taps_ = taps;
1186 }
1187 const int64_t s = pos0 + n_new;
1188 for (int i = 0; i < 8; ++i) { h_meta_[i] = (int32_t) (pos0 + std::min(i, n_new - 1)); h_meta_[8 + i] = (int32_t) (s + i); }
1189 h_meta_[16] = anchor;
1190 h_meta_[18] = epoch_;
1191 h_meta_[17] = (int32_t) s;
1192 h_meta_[24] = anchor;
1193 for (int i = 1; i < 8; ++i) h_meta_[24 + i] = mask_token_;
1194 for (int i = 0; i < kDrafts; ++i) { ((volatile int32_t*) h_out_)[i] = -1; }
1195 std::atomic_thread_fence(std::memory_order_seq_cst);
1196 log_stage(pos0, n_new);
1197 if (timing_) cudaEventRecord(ev_a_, cs_);
1198 if (prof_) { // the same round without its graph, an event after every stage
1199 cudaStreamSynchronize(cs_);
1200 for (cudaEvent_t e : prof_->ev) cudaEventDestroy(e); // the stamps of context() calls are not a round
1201 prof_->ev.clear();
1202 prof_->name.clear();
1203 kernels::copy_i32_from_mapped(d_meta_, m_meta_, 32, cs_);
1204 stamp("start");
1205 if (!record_context(taps, n_new, cs_, err) || !record_block(cs_, err)) return false;
1206 prof_collect();
1207 } else
1208 if (cudaGraphLaunch(exec_[n_new], cs_) != cudaSuccess) { err = std::string("dflash2 draft: ") + cudaGetErrorString(cudaGetLastError()); return false; }
1209 if (timing_) cudaEventRecord(ev_b_, cs_);
1210 (void) cudaStreamQuery(cs_);
1211 launch_t0_ = t0;
1212 launch_n_ = n_new;
1213 launch_pos0_ = pos0;
1214 launched_ = true;
1215 return true;
1216}
1217
1218bool Dflash2Drafter::draft_finish(int32_t* drafts, float* probs, std::string& err) {
1219 if (!launched_) { err = "dflash2: draft_finish without draft_launch"; return false; }

Callers 1

launchMethod · 0.80

Calls 15

record_contextFunction · 0.85
record_blockFunction · 0.85
cudaStreamQueryFunction · 0.85
nowFunction · 0.50
captureFunction · 0.50
minFunction · 0.50
cudaEventRecordFunction · 0.50
cudaStreamSynchronizeFunction · 0.50
cudaEventDestroyFunction · 0.50
copy_i32_from_mappedFunction · 0.50
stampFunction · 0.50
cudaGraphLaunchFunction · 0.50

Tested by

no test coverage detected