MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / Graph

Method Graph

src/framework/modules/titanet_runtime.cpp:469–517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467class TitaNetRuntime::Graph {
468 public:
469 Graph(
470 std::shared_ptr<const TitaNetWeights> weights,
471 std::shared_ptr<const TitaNetBackendWeights> backend_weights,
472 int64_t frames,
473 core::ExecutionContext & execution_context)
474 : weights_(std::move(weights)),
475 backend_weights_(std::move(backend_weights)),
476 frames_(frames),
477 backend_(execution_context.backend()),
478 compute_threads_(std::max(1, execution_context.config().threads)) {
479 const auto build_start = Clock::now();
480 if (frames_ <= 0) {
481 throw std::runtime_error("invalid TitaNet graph shape");
482 }
483 if (backend_ == nullptr) {
484 throw std::runtime_error("TitaNet execution backend is not initialized");
485 }
486 ggml_init_params params{256ull * 1024ull * 1024ull, nullptr, true};
487 ctx_.reset(ggml_init(params));
488 if (ctx_ == nullptr) {
489 throw std::runtime_error("failed to initialize ggml context");
490 }
491 core::ModuleBuildContext build_ctx{
492 ctx_.get(),
493 "titanet_spk",
494 execution_context.backend_type(),
495 };
496 auto input = core::make_tensor(build_ctx, GGML_TYPE_F32, core::TensorShape::from_dims({1, weights_->config.n_mels, frames_}));
497 input_ = input.tensor;
498 output_ = build_titanet_graph(build_ctx, input, *backend_weights_).tensor;
499 ggml_set_output(output_);
500 graph_ = ggml_new_graph_custom(ctx_.get(), 8192, false);
501 ggml_build_forward_expand(graph_, output_);
502 buffer_ = ggml_backend_alloc_ctx_tensors(ctx_.get(), backend_);
503 if (buffer_ == nullptr) {
504 throw std::runtime_error("failed to allocate graph");
505 }
506 if (engine::core::uses_host_graph_plan(backend_)) {
507 const auto plan_start = Clock::now();
508 plan_ = engine::core::create_backend_graph_plan_if_host(backend_, graph_);
509 plan_create_ms_ = engine::debug::elapsed_ms(plan_start, Clock::now());
510 if (plan_ == nullptr) {
511 throw std::runtime_error("failed to create TitaNet graph plan");
512 }
513 }
514 const auto build_end = Clock::now();
515 debug::timing_log_scalar("titanet.graph.build_ms", engine::debug::elapsed_ms(build_start, build_end));
516 debug::timing_log_scalar("titanet.graph.plan_create_ms", plan_create_ms_);
517 }
518
519 ~Graph() {
520 if (plan_ != nullptr) {

Callers

nothing calls this directly

Calls 15

maxFunction · 0.85
ggml_initFunction · 0.85
make_tensorFunction · 0.85
build_titanet_graphFunction · 0.85
ggml_set_outputFunction · 0.85
ggml_new_graph_customFunction · 0.85
uses_host_graph_planFunction · 0.85
elapsed_msFunction · 0.50
timing_log_scalarFunction · 0.50

Tested by

no test coverage detected