Skip to main content

Model.h File

Model — the simplified entry point for loading and running an MPK on the Modalix chip. More...

Included Headers

#include "builder/NodeGroup.h" #include "model/PreprocessPlan.h" #include "nodes/io/Input.h" #include "pipeline/BoxDecodeType.h" #include "pipeline/Run.h" #include "pipeline/TensorSpec.h" #include <cstddef> #include <array> #include <cstdint> #include <memory> #include <optional> #include <string> #include <unordered_map> #include <vector>

Namespaces Index

namespacesimaai
namespaceneat
namespaceinternal

Classes Index

classModel

Loaded form of an MPK; the simplified entry point to run inference on Modalix. More...

structModelInfo

Diagnostic snapshot of how the route planner resolved the model. More...

structRouteNeeds

What the model fundamentally needs in its pre/post chain (derived from manifest dtypes). More...

structRouteCapabilities

What pre/post adapters the MPK provides (read from manifest stages). More...

structRouteSelection

What the planner actually included in the materialized route. More...

structOutputTopology

Output topology: how many tensors the model emits, and whether they're physically packed. More...

structInferenceTerminalPolicy

Where the inference pipeline should terminate. More...

structPreprocessRequirements

Concrete preprocess parameters resolved by the planner from the MPK manifest. More...

structOptions

User-provided options at Model construction time. More...

structSessionOptions

Options for Model::session() — controls how the model assembles into a NodeGroup. More...

classRunner

Long-lived execution handle returned by Model::build(...). More...

Description

Model — the simplified entry point for loading and running an MPK on the Modalix chip.

Model is the user-facing wrapper around an MPK (model pack) .tar.gz. It loads the file, extracts and validates the manifest, runs the route planner, and exposes ready-to-use NodeGroup fragments (preprocess, inference, postprocess) plus convenience run() and build() methods that drive a one-shot inference. Internally a Model is a Session wrapper: the same composition, validation, and runtime machinery the Session API exposes powers Model underneath. New users start with Model::run(input); advanced users compose their own Session from model.session() plus extra Nodes.

See Also

"Models" in the design deep dive (§0.7 — The main concepts)

See Also

"Sessions: the assembly contract" (§0.12) for what Model wraps

See Also

"MPK contract" (§0.16) for the file format Model loads

File Listing

The file content with the documentation metadata removed is:

1
18#pragma once
19
20#include "builder/NodeGroup.h"
22#include "nodes/io/Input.h"
24#include "pipeline/Run.h"
26
27#include <cstddef>
28#include <array>
29#include <cstdint>
30#include <memory>
31#include <optional>
32#include <string>
33#include <unordered_map>
34#include <vector>
35
36#if defined(SIMA_WITH_OPENCV)
37#include <opencv2/core/mat.hpp>
38#endif
39
40namespace simaai::neat {
41
42namespace internal {
43struct ModelAccess;
44} // namespace internal
45
48
77class Model {
78public:
86 struct ModelInfo {
88 struct RouteNeeds {
90 false;
92 false;
93 bool pre_cast = false;
95 false;
97 false;
98 bool post_cast = false;
99 };
100
103 bool has_pre_quantization = false;
105 false;
106 bool has_pre_cast = false;
108 false;
110 bool has_post_cast = false;
112 false;
113 };
114
119 bool infer_only = false;
120 std::string preprocess_graph;
122 std::string selected_post_kind;
124 };
125
128 std::size_t physical_outputs = 0U;
129 std::size_t logical_outputs =
130 0U;
131 bool packed_outputs = false;
132 };
133
134 std::string mpk_json_path;
135 std::string model_name;
136
141
142 std::vector<std::string> pre_kernels;
143 std::vector<std::string> post_kernels;
144 std::vector<std::string>
146 };
147
156 bool mla_only = false;
157 std::optional<std::size_t>
159 std::optional<std::string>
161 std::optional<std::string> last_plugin_id;
162 std::optional<std::string>
164 };
165
174 bool has_preproc_stage = false;
175 bool quant_needed = false;
176 bool tess_needed = false;
177 std::string input_media_type;
179 std::string input_format;
180 std::string output_format;
181 std::string output_dtype;
183 std::vector<int> axis_perm;
184 std::vector<int> output_shape;
185 std::vector<int> slice_shape;
186 std::optional<double> q_scale;
188 std::optional<std::int64_t> q_zp;
189 };
190
204 struct Options {
207
208 // ── Postprocessing / detection ─────────────────────────────────────────────────────────
217 float score_threshold = 0.0f;
219 0.0f;
220 int top_k = 0;
229
230 // ── Naming / wiring ────────────────────────────────────────────────────────────────────
233 std::string upstream_name = "decoder";
236 std::string name_suffix;
237
238 // ── Extraction lifecycle ───────────────────────────────────────────────────────────────
246
249
252
257
260
263
267 };
268
276 bool include_appsrc = true;
277 bool include_appsink = true;
278 std::string upstream_name;
280 std::string name_suffix;
281 std::string
290 std::string processcvu_requested_run_target = "AUTO";
291
296
300
304
308 };
309
315 enum class Stage {
317 Inference,
319 Full
320 };
321
332 explicit Model(const std::string& mpk_path);
341 explicit Model(const std::string& mpk_path, const Options& opt);
342
343 Model(Model&&) noexcept;
344 Model& operator=(Model&&) noexcept;
345 ~Model();
346
347 // ── Stage composition ────────────────────────────────────────────────────────────────────
349 simaai::neat::NodeGroup preprocess() const;
351 simaai::neat::NodeGroup inference() const;
353 simaai::neat::NodeGroup postprocess() const;
356 simaai::neat::NodeGroup session() const;
362 simaai::neat::NodeGroup session(SessionOptions opt) const;
363
364 // ── Introspection ────────────────────────────────────────────────────────────────────────
368 std::vector<TensorSpec> input_specs() const;
372 std::vector<TensorSpec> output_specs() const;
387 ModelInfo info() const;
389 std::unordered_map<std::string, std::string> metadata() const;
390
391 // ── Advanced / graph composition ─────────────────────────────────────────────────────────
393 NodeGroup fragment(Stage stage) const;
396 std::string backend_fragment(Stage stage) const;
397
399 simaai::neat::InputOptions input_appsrc_options(bool tensor_mode) const;
401 std::vector<simaai::neat::InputOptions> input_appsrc_options_list(bool tensor_mode) const;
403 std::string find_config_path_by_plugin(const std::string& plugin_id) const;
405 std::string find_config_path_by_processor(const std::string& processor) const;
408 std::string infer_output_name() const;
409
429 class Runner {
430 public:
432 Runner() = default;
440 std::vector<std::string> ingress_names);
442 Runner(simaai::neat::Run run, std::vector<std::string> ingress_names);
443
445 explicit operator bool() const noexcept;
446#if defined(SIMA_WITH_OPENCV)
451 bool push(const std::vector<cv::Mat>& inputs);
452#endif
454 bool push(const simaai::neat::TensorList& inputs);
456 bool push(const simaai::neat::SampleList& inputs);
463 simaai::neat::SampleList pull(int timeout_ms = -1);
464#if defined(SIMA_WITH_OPENCV)
466 simaai::neat::TensorList run(const std::vector<cv::Mat>& inputs, int timeout_ms = -1);
467#endif
469 simaai::neat::TensorList run(const simaai::neat::TensorList& inputs, int timeout_ms = -1);
471 simaai::neat::SampleList run(const simaai::neat::SampleList& inputs, int timeout_ms = -1);
472
481 int warmup(const simaai::neat::TensorList& inputs, int warm = -1, int timeout_ms = -1);
483 void close();
491 std::string metrics_report(
499 std::string report(const simaai::neat::RunReportOptions& opt = {}) const;
502
503 private:
504 simaai::neat::Run run_{};
505 std::optional<simaai::neat::InputOptions> tensor_input_opt_for_cv_{};
506 std::vector<std::string> ingress_names_;
507 };
508
509private:
510 static const SessionOptions& default_session_options();
511 static const simaai::neat::RunOptions& default_run_options();
512
513public:
544 const SessionOptions& opt = default_session_options(),
545 const simaai::neat::RunOptions& run_opt = default_run_options());
548 const SessionOptions& opt = default_session_options(),
549 const simaai::neat::RunOptions& run_opt = default_run_options());
550#if defined(SIMA_WITH_OPENCV)
552 Runner build(const std::vector<cv::Mat>& inputs,
553 const SessionOptions& opt = default_session_options(),
554 const simaai::neat::RunOptions& run_opt = default_run_options());
555#endif
556
557 // ── One-shot execution (synchronous) ─────────────────────────────────────────────────────
569 simaai::neat::TensorList run(const simaai::neat::TensorList& inputs, int timeout_ms = -1);
571 simaai::neat::SampleList run(const simaai::neat::SampleList& inputs, int timeout_ms = -1);
572#if defined(SIMA_WITH_OPENCV)
574 simaai::neat::TensorList run(const std::vector<cv::Mat>& inputs, int timeout_ms = -1);
575#endif
576
577private:
578 friend struct internal::ModelAccess;
579 struct Impl;
580 std::unique_ptr<Impl> impl_;
581};
582
583} // namespace simaai::neat

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.