| 417 | virtual int64_t total_token_capacity() const noexcept = 0; |
| 418 | virtual int64_t target_frame_capacity() const noexcept = 0; |
| 419 | virtual double rebuild_clear_ms() const noexcept = 0; |
| 420 | virtual double rebuild_build_ms() const noexcept = 0; |
| 421 | virtual double rebuild_alloc_ms() const noexcept = 0; |
| 422 | virtual double rebuild_init_ms() const noexcept = 0; |
| 423 | }; |
| 424 | |
| 425 | class ForwardGraph final : public GeneratorForwardGraph { |
| 426 | public: |
| 427 | ForwardGraph( |
| 428 | std::shared_ptr<WeightsRuntime> runtime, |
| 429 | size_t graph_arena_bytes, |
| 430 | int64_t total_token_capacity, |
| 431 | int64_t target_frame_capacity, |
| 432 | OmniVoiceGeneratorPerfMode perf_mode) |
| 433 | : runtime_(std::move(runtime)), |
| 434 | graph_arena_bytes_(graph_arena_bytes), |
| 435 | perf_mode_(perf_mode) { |
| 436 | rebuild(total_token_capacity, target_frame_capacity); |
| 437 | } |
| 438 | |
| 439 | ~ForwardGraph() { |
| 440 | clear_graph(); |
| 441 | } |
| 442 | |
| 443 | bool matches( |
| 444 | const WeightsRuntime & runtime, |
| 445 | int64_t total_tokens, |
| 446 | int64_t target_frames) const override { |
| 447 | return runtime_.get() == &runtime && |
| 448 | total_tokens_capacity_ >= total_tokens && |
| 449 | target_frame_capacity_ >= target_frames; |
| 450 | } |
| 451 | |
| 452 | void rebuild(int64_t total_token_capacity, int64_t target_frame_capacity) override { |
| 453 | if (total_token_capacity <= 0 || target_frame_capacity <= 0) { |
| 454 | throw std::runtime_error("OmniVoice generator total token capacity is invalid"); |
| 455 | } |
| 456 | const auto clear_start = Clock::now(); |
| 457 | clear_graph(); |
| 458 | const auto clear_end = Clock::now(); |
| 459 | rebuild_clear_ms_ = engine::debug::elapsed_ms(clear_start, clear_end); |
| 460 | total_tokens_capacity_ = total_token_capacity; |
| 461 | target_frame_capacity_ = target_frame_capacity; |
| 462 | |
| 463 | const auto build_start = Clock::now(); |
| 464 | ggml_init_params input_params{16ull * 1024ull * 1024ull, nullptr, true}; |
| 465 | input_ctx_.reset(ggml_init(input_params)); |
| 466 | if (input_ctx_ == nullptr) { |
| 467 | throw std::runtime_error("failed to initialize OmniVoice generator input context"); |
| 468 | } |
| 469 | ggml_init_params params{graph_arena_bytes_, nullptr, true}; |
| 470 | ctx_.reset(ggml_init(params)); |
| 471 | if (ctx_ == nullptr) { |
| 472 | throw std::runtime_error("failed to initialize OmniVoice generator graph context"); |
| 473 | } |
| 474 | |
| 475 | const auto & config = runtime_->assets().config; |
| 476 | const auto & weights = runtime_->weights(); |
nothing calls this directly
no test coverage detected