MCPcopy Create free account
hub / github.com/ml-explore/mlx / commit

Method commit

mlx/backend/cuda/device.cpp:463–536  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

461}
462
463void CommandEncoder::commit() {
464 nvtx3::scoped_range r("CommandEncoder::commit");
465 if (!temporaries_.empty()) {
466 add_completed_handler([temporaries = std::move(temporaries_)]() {});
467 }
468 if (use_cuda_graphs() && node_count_ > 0) {
469 if (!from_nodes_.empty()) {
470#if CUDART_VERSION >= 13000
471 CHECK_CUDA_ERROR(cudaGraphAddDependencies(
472 graph_,
473 from_nodes_.data(),
474 to_nodes_.data(),
475 nullptr, // edgeData
476 from_nodes_.size()));
477#else
478 CHECK_CUDA_ERROR(cudaGraphAddDependencies(
479 graph_, from_nodes_.data(), to_nodes_.data(), from_nodes_.size()));
480#endif
481 }
482
483 device_.make_current();
484
485 if (!is_graph_updatable_) {
486 CudaGraphExec graph_exec;
487 graph_exec.instantiate(graph_);
488 CHECK_CUDA_ERROR(cudaGraphLaunch(graph_exec, stream_));
489 } else {
490 auto graph_key = graph_nodes_key_ + ":" + graph_deps_key_;
491 auto& graph_exec = graph_cache_[graph_key];
492
493 if (graph_exec != nullptr) {
494 cudaGraphExecUpdateResult update_result;
495#if CUDART_VERSION >= 12000
496 cudaGraphExecUpdateResultInfo info;
497 cudaGraphExecUpdate(graph_exec, graph_, &info);
498 update_result = info.result;
499#else
500 cudaGraphNode_t error_node;
501 cudaGraphExecUpdate(graph_exec, graph_, &error_node, &update_result);
502#endif // CUDART_VERSION >= 12000
503 if (update_result != cudaGraphExecUpdateSuccess) {
504 cudaGetLastError(); // reset error
505 graph_exec.reset();
506 }
507 }
508 if (graph_exec == nullptr) {
509 graph_exec.instantiate(graph_);
510 }
511
512 CHECK_CUDA_ERROR(cudaGraphLaunch(graph_exec, stream_));
513 }
514
515 // Save cuda graph to dot file
516 if (const char* filename = save_cuda_graphs_dot_file(); filename) {
517 static int count = 0;
518 auto path = fmt::format("{}_{}.dot", filename, ++count);
519 CHECK_CUDA_ERROR(cudaGraphDebugDotPrint(graph_, path.c_str(), 0));
520 }

Callers 3

evalFunction · 0.45
finalizeFunction · 0.45
updateMethod · 0.45

Calls 10

use_cuda_graphsFunction · 0.85
CudaGraphClass · 0.85
make_currentMethod · 0.80
instantiateMethod · 0.80
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
resetMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected