Skip to main content

GraphOptions.h File

Graph/Run options, the Sample type, pull-status enums, and verbosity controls. More...

Included Headers

#include "pipeline/GraphReport.h" #include "pipeline/FormatSpec.h" #include "pipeline/PayloadType.h" #include "pipeline/TensorTypes.h" #include "pipeline/Tensor.h" #include "pipeline/TensorCore.h" #include <algorithm> #include <cstddef> #include <functional> #include <initializer_list> #include <iterator> #include <optional> #include <string> #include <utility> #include <vector>

Namespaces Index

namespacecv
namespacesimaai
namespaceneat

Classes Index

structVerboseOptions

Per-topic framework verbosity controls. More...

structRtspServerOptions

Options for Graph::run_rtsp() — controls the RTSP server's mount point and ports. More...

structValidateOptions

Options for Graph::validate(). More...

structProcessCvuOptions

Simple process-CVU backend placement for model pre/post stages. More...

structProcessMlaOptions

process-MLA execution options. More...

structPreparedRunnerOptions

Experimental prepared-route runner options. More...

structGraphOptions

Per-Graph construction options. More...

structOutputTensorOptions

Options for Graph::add_output_tensor() — the tensor-friendly output helper. More...

structPullError

Structured error returned by Run::pull() when status is Error. More...

structSample

Typed payload returned by Run::pull() and consumed by Run::push(). More...

classiterator
classconst_iterator

Description

Graph/Run options, the Sample type, pull-status enums, and verbosity controls.

Defines the option structs the framework consumes at construction/build time and the Sample type that flows out of Run::pull(). Key types here:

  • VerboseOptions / VerbosityLevel — diagnostic verbosity controls (per topic).
  • GraphOptions — per-Graph knobs (callback timeout, naming, processor preference).
  • RtspServerOptions / ValidateOptions / OutputTensorOptions — option packs for specific calls.
  • RunMode — Async vs Sync timing mode.
  • Sample / SampleKind — the typed payload pull() returns; can be a Tensor, a TensorSet (multiple physical outputs), or a Bundle (recursive multi-logical-output).
  • PullStatus / PullError — structured pull results.
See Also

Graph, Run, Tensor

File Listing

The file content with the documentation metadata removed is:

1
19#pragma once
20
25#include "pipeline/Tensor.h"
27
28#include <algorithm>
29#include <cstddef>
30#include <functional>
31#include <initializer_list>
32#include <iterator>
33#include <optional>
34#include <string>
35#include <utility>
36#include <vector>
37
38namespace cv {
39class Mat;
40}
41
42namespace simaai::neat {
43
52enum class VerbosityLevel {
53 Quiet,
55 Verbose,
56};
57
68
70 bool progress = true;
71
73 bool progress_force = false;
74
76 bool gstreamer = false;
77
79 bool planner = false;
80
82 bool graph = false;
83
85 bool pipeline = false;
86
88 bool inputstream = false;
89
91 bool tensor = false;
92
94 bool plugins = false;
95
97 [[nodiscard]] static VerboseOptions quiet() {
100 opt.progress = false;
101 opt.progress_force = false;
102 opt.gstreamer = false;
103 opt.planner = false;
104 opt.graph = false;
105 opt.pipeline = false;
106 opt.inputstream = false;
107 opt.tensor = false;
108 opt.plugins = false;
109 return opt;
110 }
111
113 [[nodiscard]] static VerboseOptions production() {
116 opt.progress = true;
117 opt.progress_force = false;
118 opt.gstreamer = false;
119 opt.planner = false;
120 opt.graph = false;
121 opt.pipeline = false;
122 opt.inputstream = false;
123 opt.tensor = false;
124 opt.plugins = false;
125 return opt;
126 }
127
130 [[nodiscard]] static VerboseOptions debug_plugins() {
132 opt.gstreamer = true;
133 opt.plugins = true;
134 return opt;
135 }
136
138 [[nodiscard]] static VerboseOptions debug_all() {
141 opt.progress = true;
142 opt.progress_force = true;
143 opt.gstreamer = true;
144 opt.planner = true;
145 opt.graph = true;
146 opt.pipeline = true;
147 opt.inputstream = true;
148 opt.tensor = true;
149 opt.plugins = true;
150 return opt;
151 }
152};
153
159 std::string mount =
160 "image";
161 int port = 8554;
169 int rtp_port_base = -1;
171};
172
182 bool parse_launch = true;
183 bool enforce_names = true;
184};
185
195enum class RunMode {
196 Async,
197 Sync,
198};
199
217 std::string pre_run_target = "AUTO";
218 std::string post_run_target = "AUTO";
219
224 bool async = true;
225};
226
234 bool async = true;
235
241
249};
250
261 std::string mode;
262 int ring_depth = 0;
263 bool profile = false;
272 std::string dequant_flags;
273};
274
298 std::string processcvu_requested_run_target = "AUTO";
299
303
306
309
314};
315
326
327 int target_width = -1;
328 int target_height = -1;
329 int target_fps = -1;
330};
331
341enum class SampleKind {
342 Tensor,
343 TensorSet,
344 Bundle,
345 Unknown,
346};
347
352enum class PullStatus {
353 Ok,
354 Timeout,
355 Closed,
356 Error,
357};
358
367struct PullError {
368 std::string message;
369 std::string code;
370 std::optional<GraphReport> report;
371};
372
382struct Sample {
384 bool owned =
385 true;
386
387 std::optional<simaai::neat::Tensor> tensor;
389 std::vector<Sample> fields;
390
391 std::string
394 std::string media_type;
396 std::string payload_tag;
400 std::string format;
401
402 int64_t frame_id = -1;
403 std::string stream_id;
404 std::string stream_label;
405 std::string port_name;
408 int output_index = -1;
410 int memory_index = -1;
411 int route_slot = -1;
412 std::string segment_name;
413 int64_t input_seq = -1;
415 -1;
416 int64_t pts_ns = -1;
417 int64_t dts_ns = -1;
418 int64_t duration_ns = -1;
419
421 bool empty() const noexcept {
422 return kind == SampleKind::Unknown && !tensor.has_value() && tensors.empty() && fields.empty();
423 }
424
430 std::size_t size() const noexcept {
431 if (kind == SampleKind::Bundle) {
432 return fields.size();
433 }
434 return empty() ? 0U : 1U;
435 }
436
438 void reserve(std::size_t n) {
439 if (kind == SampleKind::Unknown && empty()) {
441 }
442 fields.reserve(n);
443 }
444
446 void push_back(Sample sample) {
447 if (kind == SampleKind::Unknown && empty()) {
449 }
450 fields.push_back(std::move(sample));
453 }
454 }
455
458 if (kind == SampleKind::Bundle) {
459 return fields.front();
460 }
461 return *this;
462 }
463 const Sample& front() const {
464 if (kind == SampleKind::Bundle) {
465 return fields.front();
466 }
467 return *this;
468 }
469
472 if (kind == SampleKind::Bundle) {
473 return fields.back();
474 }
475 return *this;
476 }
477 const Sample& back() const {
478 if (kind == SampleKind::Bundle) {
479 return fields.back();
480 }
481 return *this;
482 }
483
485 Sample& operator[](std::size_t i) {
486 if (kind == SampleKind::Bundle) {
487 return fields[i];
488 }
489 return *this;
490 }
491 const Sample& operator[](std::size_t i) const {
492 if (kind == SampleKind::Bundle) {
493 return fields[i];
494 }
495 return *this;
496 }
497
498 class iterator {
499 public:
500 using difference_type = std::ptrdiff_t;
502 using pointer = Sample*;
503 using reference = Sample&;
504 using iterator_category = std::forward_iterator_tag;
505
506 iterator(Sample* owner, std::size_t index) : owner_(owner), index_(index) {}
508 return owner_->kind == SampleKind::Bundle ? owner_->fields[index_] : *owner_;
509 }
511 return &(**this);
512 }
514 ++index_;
515 return *this;
516 }
517 bool operator==(const iterator& other) const {
518 return owner_ == other.owner_ && index_ == other.index_;
519 }
520 bool operator!=(const iterator& other) const {
521 return !(*this == other);
522 }
523
524 private:
525 Sample* owner_ = nullptr;
526 std::size_t index_ = 0;
527 };
528
530 public:
531 using difference_type = std::ptrdiff_t;
533 using pointer = const Sample*;
534 using reference = const Sample&;
535 using iterator_category = std::forward_iterator_tag;
536
537 const_iterator(const Sample* owner, std::size_t index) : owner_(owner), index_(index) {}
539 return owner_->kind == SampleKind::Bundle ? owner_->fields[index_] : *owner_;
540 }
542 return &(**this);
543 }
545 ++index_;
546 return *this;
547 }
548 bool operator==(const const_iterator& other) const {
549 return owner_ == other.owner_ && index_ == other.index_;
550 }
551 bool operator!=(const const_iterator& other) const {
552 return !(*this == other);
553 }
554
555 private:
556 const Sample* owner_ = nullptr;
557 std::size_t index_ = 0;
558 };
559
561 return iterator(this, 0);
562 }
564 return iterator(this, size());
565 }
567 return const_iterator(this, 0);
568 }
570 return const_iterator(this, size());
571 }
573 return begin();
574 }
576 return end();
577 }
578
579#if defined(SIMA_WITH_OPENCV)
580 static const char* image_format_string(ImageSpec::PixelFormat fmt) {
581 switch (fmt) {
583 return "RGB";
585 return "BGR";
587 return "GRAY8";
589 return "NV12";
591 return "I420";
593 default:
594 return "UNKNOWN";
595 }
596 }
597
598 static Sample from_image(const cv::Mat& image,
600 bool read_only = true) {
601#if defined(__GNUC__) || defined(__clang__)
602#pragma GCC diagnostic push
603#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
604#endif
605 Tensor tensor = Tensor::from_cv_mat(image, fmt, read_only);
606#if defined(__GNUC__) || defined(__clang__)
607#pragma GCC diagnostic pop
608#endif
609 if (read_only && tensor.storage &&
611 tensor = tensor.clone();
612 tensor.read_only = false;
613 }
614 Sample out;
615 out.kind = SampleKind::TensorSet;
616 out.tensors = TensorList{std::move(tensor)};
617 out.payload_type = PayloadType::Image;
618 out.media_type = "video/x-raw";
619 out.format = image_format_string(fmt);
620 out.payload_tag = out.format;
621 return out;
622 }
623
624 static Sample from_image(const cv::Mat& image, ImageSpec::PixelFormat fmt, TensorMemory memory) {
625 Tensor tensor = Tensor::from_cv_mat(image, fmt, memory);
626 Sample out;
627 out.kind = SampleKind::TensorSet;
628 out.tensors = TensorList{std::move(tensor)};
629 out.payload_type = PayloadType::Image;
630 out.media_type = "video/x-raw";
631 out.format = image_format_string(fmt);
632 out.payload_tag = out.format;
633 return out;
634 }
635#endif
636};
637
639inline PayloadType sample_payload_type(const Sample& sample) {
640 if (sample.payload_type != PayloadType::Auto) {
641 return sample.payload_type;
642 }
643 const PayloadType from_media = payload_type_from_media_type(sample.media_type);
644 if (from_media != PayloadType::Auto) {
645 return from_media;
646 }
647 if (sample.kind == SampleKind::Tensor && sample.tensor.has_value()) {
648 if (sample.tensor->semantic.encoded.has_value() ||
649 sample.tensor->semantic.byte_stream.has_value()) {
651 }
652 if (sample.tensor->semantic.image.has_value()) {
653 return PayloadType::Image;
654 }
656 }
657 if (sample.kind == SampleKind::TensorSet && !sample.tensors.empty()) {
658 const Tensor& first = sample.tensors.front();
659 if (first.semantic.encoded.has_value() || first.semantic.byte_stream.has_value()) {
661 }
662 const bool all_image =
663 std::all_of(sample.tensors.begin(), sample.tensors.end(),
664 [](const Tensor& tensor) { return tensor.semantic.image.has_value(); });
665 return all_image ? PayloadType::Image : PayloadType::Tensor;
666 }
667 return PayloadType::Auto;
668}
669
671inline std::string sample_media_type(const Sample& sample) {
672 if (!sample.media_type.empty()) {
673 return sample.media_type;
674 }
676}
677
679inline Sample make_tensor_sample(const std::string& port_name, simaai::neat::Tensor tensor) {
680 Sample out;
682 out.stream_label = port_name;
683 out.tensors = TensorList{std::move(tensor)};
685 return out;
686}
687
688#if defined(SIMA_WITH_OPENCV)
690inline Sample make_image_sample(const cv::Mat& image,
692 bool read_only = true) {
693 return Sample::from_image(image, fmt, read_only);
694}
695
697inline Sample make_image_sample(const cv::Mat& image, ImageSpec::PixelFormat fmt,
698 TensorMemory memory) {
699 return Sample::from_image(image, fmt, memory);
700}
701#endif
702
704inline Sample make_bundle_sample(std::initializer_list<Sample> fields) {
705 Sample out;
707 out.fields = fields;
708 return out;
709}
710
712inline bool sample_is_multi_output(const Sample& sample) {
713 return sample.kind == SampleKind::Bundle ||
714 (sample.kind == SampleKind::TensorSet && sample.tensors.size() > 1U);
715}
716
718inline bool sample_has_tensor_list(const Sample& sample) {
719 return sample.kind == SampleKind::TensorSet && !sample.tensors.empty();
720}
721
723TensorList& sample_tensor_list(Sample& sample, const char* where = nullptr);
725const TensorList& sample_tensor_list(const Sample& sample, const char* where = nullptr);
727Tensor& require_single_tensor(Sample& sample, const char* where = nullptr);
729const Tensor& require_single_tensor(const Sample& sample, const char* where = nullptr);
731TensorList tensors_from_sample(const Sample& sample, bool require_nonempty = true);
734
735} // namespace simaai::neat

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.