| 214 | |
| 215 | void allocate_graph_resources( |
| 216 | const engine::core::ExecutionContext & execution_context, |
| 217 | ggml_cgraph * graph, |
| 218 | ggml_gallocr_t & gallocr, |
| 219 | const char * label) { |
| 220 | gallocr = ggml_gallocr_new(ggml_backend_get_default_buffer_type(execution_context.backend())); |
| 221 | if (gallocr == nullptr || |
| 222 | !ggml_gallocr_reserve(gallocr, graph) || |
| 223 | !ggml_gallocr_alloc_graph(gallocr, graph)) { |
| 224 | if (gallocr != nullptr) { |
| 225 | ggml_gallocr_free(gallocr); |
| 226 | gallocr = nullptr; |
| 227 | } |
| 228 | throw std::runtime_error(std::string("failed to allocate backend tensors for ") + label); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | int64_t valid_frames_from_mask(const std::vector<float> & mask, int64_t batch, int64_t frames) { |
| 233 | if (batch <= 0 || frames <= 0) { |
| 234 | throw std::runtime_error("S3 valid_frames_from_mask requires positive batch and frames"); |
| 235 | } |
| 236 | if (static_cast<int64_t>(mask.size()) != batch * frames) { |
| 237 | throw std::runtime_error("S3 mask size mismatch"); |
| 238 | } |
| 239 | int64_t valid = 0; |
| 240 | for (int64_t frame = 0; frame < frames; ++frame) { |
| 241 | const float value = mask[static_cast<size_t>(frame)]; |
| 242 | if (value >= 0.5f) { |
| 243 | ++valid; |
| 244 | continue; |
| 245 | } |
no test coverage detected