Skip to main content

SimaPreparedRuntimeAbi.h File

Included Headers​

#include <gst/gst.h> #include <gstsimaaitensorbuffer.h> #include "gst/ProcessMlaRuntimeConfig.h" #include <ev/ev_tensor_abi.h> #include <array> #include <cstdint> #include <optional> #include <string> #include <utility> #include <vector>

Namespaces Index​

namespacesimaai
namespacegst

Classes Index​

structCastPreparedStage
structProcessMlaPreparedStage
structDims
structCvuInputMemoryBinding
structCvuOutputBinding
structCvuRoutingContract
structProcessCvuPreparedLogicalInput
structProcessCvuPreparedPhysicalInput
structPreparedProcessCvuTypedConfig
structProcessCvuPreparedStage
structDequantPreparedSpan
structDequantPreparedStage
structDetessDequantPreparedStage
structPreparedStageSpec
structSimaPreparedRuntimeHandle
structSimaPreparedRuntimeAccessor

Typedefs Index​

typedefstruct SimaPreparedRuntimeAccessor SimaPreparedRuntimeAccessor
typedefstruct SimaPreparedRuntimeHandle SimaPreparedRuntimeHandle

Enumerations Index​

enumSimaPreparedRuntimeLookupStatus { ... }

Functions Index​

static const gchar *sima_prepared_runtime_lookup_status_name (SimaPreparedRuntimeLookupStatus status)
static gpointersima_prepared_runtime_handle_boxed_copy (gpointer boxed)
static voidsima_prepared_runtime_handle_boxed_free (gpointer boxed)
static GTypesima_prepared_runtime_handle_get_type (void)
static voidsima_prepared_runtime_set_lookup_status (SimaPreparedRuntimeLookupStatus *status, SimaPreparedRuntimeLookupStatus value)
static gbooleansima_prepared_runtime_context_matches (const GstContext *context)
static const GstStructure *sima_prepared_runtime_context_structure (const GstContext *context)
static const SimaPreparedRuntimeHandle *sima_prepared_runtime_context_handle (const GstContext *context)
static const SimaPreparedRuntimeAccessor *sima_prepared_runtime_context_accessor_checked (const GstContext *context, SimaPreparedRuntimeLookupStatus *status)
static const simaai::gst::PreparedStageSpec *sima_prepared_runtime_context_stage_lookup_checked (const GstContext *context, const gchar *stage_key, SimaPreparedRuntimeLookupStatus *status)
static const simaai::gst::CastPreparedStage *sima_prepared_runtime_context_cast_stage_lookup_checked (const GstContext *context, const gchar *stage_key, SimaPreparedRuntimeLookupStatus *status)
static const simaai::gst::ProcessMlaPreparedStage *sima_prepared_runtime_context_processmla_stage_lookup_checked (const GstContext *context, const gchar *stage_key, SimaPreparedRuntimeLookupStatus *status)
static const simaai::gst::ProcessCvuPreparedStage *sima_prepared_runtime_context_processcvu_stage_lookup_checked (const GstContext *context, const gchar *stage_key, SimaPreparedRuntimeLookupStatus *status)
static const simaai::gst::DequantPreparedStage *sima_prepared_runtime_context_dequant_stage_lookup_checked (const GstContext *context, const gchar *stage_key, SimaPreparedRuntimeLookupStatus *status)
static const simaai::gst::DetessDequantPreparedStage *sima_prepared_runtime_context_detessdequant_stage_lookup_checked (const GstContext *context, const gchar *stage_key, SimaPreparedRuntimeLookupStatus *status)

Macro Definitions Index​

#defineSIMA_PREPARED_RUNTIME_CONTEXT_TYPE   "sima.model.prepared-runtime"
#defineSIMA_PREPARED_RUNTIME_ABI_VERSION   ((guint)2)
#defineSIMA_PREPARED_RUNTIME_KEY_SESSION_ID   "session_id"
#defineSIMA_PREPARED_RUNTIME_KEY_MODEL_ID   "model_id"
#defineSIMA_PREPARED_RUNTIME_KEY_HANDLE   "prepared_runtime_handle"

Typedefs​

SimaPreparedRuntimeAccessor​

typedef struct SimaPreparedRuntimeAccessor SimaPreparedRuntimeAccessor

SimaPreparedRuntimeHandle​

typedef struct SimaPreparedRuntimeHandle SimaPreparedRuntimeHandle

Definition at line 456 of file SimaPreparedRuntimeAbi.h.

Enumerations​

SimaPreparedRuntimeLookupStatus​

enum SimaPreparedRuntimeLookupStatus
Enumeration values
SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK (= 0)
SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_NO_CONTEXT (= 1)
SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_WRONG_CONTEXT_TYPE (= 2)
SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_MISSING_HANDLE (= 3)
SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_HANDLE_ABI_MISMATCH (= 4)
SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_HANDLE_ACCESSOR_NULL (= 5)
SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_HANDLE_CALLBACK_MISSING (= 6)
SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_STAGE_NOT_FOUND (= 7)
SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_STAGE_KIND_MISMATCH (= 8)

Definition at line 24 of file SimaPreparedRuntimeAbi.h.

Functions​

sima_prepared_runtime_context_accessor_checked()​

const SimaPreparedRuntimeAccessor * sima_prepared_runtime_context_accessor_checked (const GstContext * context, SimaPreparedRuntimeLookupStatus * status)
inline static

Definition at line 567 of file SimaPreparedRuntimeAbi.h.

567sima_prepared_runtime_context_accessor_checked(const GstContext* context,
569 if (!context) {
570 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_NO_CONTEXT);
571 return nullptr;
572 }
573 if (!sima_prepared_runtime_context_matches(context)) {
574 sima_prepared_runtime_set_lookup_status(status,
576 return nullptr;
577 }
578 const auto* handle = sima_prepared_runtime_context_handle(context);
579 if (!handle) {
580 sima_prepared_runtime_set_lookup_status(status,
582 return nullptr;
583 }
584 if (handle->abi_version != SIMA_PREPARED_RUNTIME_ABI_VERSION) {
585 sima_prepared_runtime_set_lookup_status(
587 return nullptr;
588 }
589 if (!handle->ref || !handle->unref || !handle->accessor) {
590 sima_prepared_runtime_set_lookup_status(
592 return nullptr;
593 }
594 const auto* accessor = handle->accessor(handle->user_data);
595 if (!accessor) {
596 sima_prepared_runtime_set_lookup_status(
598 return nullptr;
599 }
600 if (accessor->abi_version != SIMA_PREPARED_RUNTIME_ABI_VERSION) {
601 sima_prepared_runtime_set_lookup_status(
603 return nullptr;
604 }
605 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
606 return accessor;
607}

sima_prepared_runtime_context_cast_stage_lookup_checked()​

const simaai::gst::CastPreparedStage * sima_prepared_runtime_context_cast_stage_lookup_checked (const GstContext * context, const gchar * stage_key, SimaPreparedRuntimeLookupStatus * status)
inline static

Definition at line 631 of file SimaPreparedRuntimeAbi.h.

631sima_prepared_runtime_context_cast_stage_lookup_checked(const GstContext* context,
632 const gchar* stage_key,
634 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
635 if (!accessor || !accessor->cast_stage_by_key || !stage_key || !*stage_key) {
636 if (status && (!stage_key || !*stage_key)) {
638 }
639 return nullptr;
640 }
641 const auto* stage = accessor->cast_stage_by_key(accessor->user_data, stage_key);
642 if (!stage) {
643 const auto* generic =
644 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
645 sima_prepared_runtime_set_lookup_status(
648 return nullptr;
649 }
650 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
651 return stage;
652}

sima_prepared_runtime_context_dequant_stage_lookup_checked()​

const simaai::gst::DequantPreparedStage * sima_prepared_runtime_context_dequant_stage_lookup_checked (const GstContext * context, const gchar * stage_key, SimaPreparedRuntimeLookupStatus * status)
inline static

Definition at line 701 of file SimaPreparedRuntimeAbi.h.

701sima_prepared_runtime_context_dequant_stage_lookup_checked(
702 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
703 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
704 if (!accessor || !accessor->dequant_stage_by_key || !stage_key || !*stage_key) {
705 if (status && (!stage_key || !*stage_key)) {
707 }
708 return nullptr;
709 }
710 const auto* stage = accessor->dequant_stage_by_key(accessor->user_data, stage_key);
711 if (!stage) {
712 const auto* generic =
713 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
714 sima_prepared_runtime_set_lookup_status(
717 return nullptr;
718 }
719 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
720 return stage;
721}

sima_prepared_runtime_context_detessdequant_stage_lookup_checked()​

const simaai::gst::DetessDequantPreparedStage * sima_prepared_runtime_context_detessdequant_stage_lookup_checked (const GstContext * context, const gchar * stage_key, SimaPreparedRuntimeLookupStatus * status)
inline static

Definition at line 724 of file SimaPreparedRuntimeAbi.h.

724sima_prepared_runtime_context_detessdequant_stage_lookup_checked(
725 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
726 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
727 if (!accessor || !accessor->detessdequant_stage_by_key || !stage_key || !*stage_key) {
728 if (status && (!stage_key || !*stage_key)) {
730 }
731 return nullptr;
732 }
733 const auto* stage = accessor->detessdequant_stage_by_key(accessor->user_data, stage_key);
734 if (!stage) {
735 const auto* generic =
736 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
737 sima_prepared_runtime_set_lookup_status(
740 return nullptr;
741 }
742 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
743 return stage;
744}

sima_prepared_runtime_context_handle()​

const SimaPreparedRuntimeHandle * sima_prepared_runtime_context_handle (const GstContext * context)
inline static

Definition at line 554 of file SimaPreparedRuntimeAbi.h.

554sima_prepared_runtime_context_handle(const GstContext* context) {
555 const GstStructure* structure = sima_prepared_runtime_context_structure(context);
556 if (!structure) {
557 return NULL;
558 }
559 const GValue* handle_val = gst_structure_get_value(structure, SIMA_PREPARED_RUNTIME_KEY_HANDLE);
560 if (!handle_val || G_VALUE_TYPE(handle_val) != sima_prepared_runtime_handle_get_type()) {
561 return NULL;
562 }
563 return static_cast<const SimaPreparedRuntimeHandle*>(g_value_get_boxed(handle_val));
564}

sima_prepared_runtime_context_matches()​

gboolean sima_prepared_runtime_context_matches (const GstContext * context)
inline static

Definition at line 538 of file SimaPreparedRuntimeAbi.h.

538static inline gboolean sima_prepared_runtime_context_matches(const GstContext* context) {
539 if (!context) {
540 return FALSE;
541 }
542 return g_strcmp0(gst_context_get_context_type(context), SIMA_PREPARED_RUNTIME_CONTEXT_TYPE) == 0;
543}

sima_prepared_runtime_context_processcvu_stage_lookup_checked()​

const simaai::gst::ProcessCvuPreparedStage * sima_prepared_runtime_context_processcvu_stage_lookup_checked (const GstContext * context, const gchar * stage_key, SimaPreparedRuntimeLookupStatus * status)
inline static

Definition at line 678 of file SimaPreparedRuntimeAbi.h.

678sima_prepared_runtime_context_processcvu_stage_lookup_checked(
679 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
680 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
681 if (!accessor || !accessor->processcvu_stage_by_key || !stage_key || !*stage_key) {
682 if (status && (!stage_key || !*stage_key)) {
684 }
685 return nullptr;
686 }
687 const auto* stage = accessor->processcvu_stage_by_key(accessor->user_data, stage_key);
688 if (!stage) {
689 const auto* generic =
690 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
691 sima_prepared_runtime_set_lookup_status(
694 return nullptr;
695 }
696 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
697 return stage;
698}

sima_prepared_runtime_context_processmla_stage_lookup_checked()​

const simaai::gst::ProcessMlaPreparedStage * sima_prepared_runtime_context_processmla_stage_lookup_checked (const GstContext * context, const gchar * stage_key, SimaPreparedRuntimeLookupStatus * status)
inline static

Definition at line 655 of file SimaPreparedRuntimeAbi.h.

655sima_prepared_runtime_context_processmla_stage_lookup_checked(
656 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
657 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
658 if (!accessor || !accessor->processmla_stage_by_key || !stage_key || !*stage_key) {
659 if (status && (!stage_key || !*stage_key)) {
661 }
662 return nullptr;
663 }
664 const auto* stage = accessor->processmla_stage_by_key(accessor->user_data, stage_key);
665 if (!stage) {
666 const auto* generic =
667 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
668 sima_prepared_runtime_set_lookup_status(
671 return nullptr;
672 }
673 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
674 return stage;
675}

sima_prepared_runtime_context_stage_lookup_checked()​

const simaai::gst::PreparedStageSpec * sima_prepared_runtime_context_stage_lookup_checked (const GstContext * context, const gchar * stage_key, SimaPreparedRuntimeLookupStatus * status)
inline static

Definition at line 610 of file SimaPreparedRuntimeAbi.h.

610sima_prepared_runtime_context_stage_lookup_checked(const GstContext* context,
611 const gchar* stage_key,
613 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
614 if (!accessor || !accessor->stage_by_key || !stage_key || !*stage_key) {
615 if (status && (!stage_key || !*stage_key)) {
617 }
618 return nullptr;
619 }
620 const auto* stage = accessor->stage_by_key(accessor->user_data, stage_key);
621 if (!stage) {
622 sima_prepared_runtime_set_lookup_status(status,
624 return nullptr;
625 }
626 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
627 return stage;
628}

sima_prepared_runtime_context_structure()​

const GstStructure * sima_prepared_runtime_context_structure (const GstContext * context)
inline static

Definition at line 546 of file SimaPreparedRuntimeAbi.h.

546sima_prepared_runtime_context_structure(const GstContext* context) {
547 if (!sima_prepared_runtime_context_matches(context)) {
548 return NULL;
549 }
550 return gst_context_get_structure(context);
551}

sima_prepared_runtime_handle_boxed_copy()​

gpointer sima_prepared_runtime_handle_boxed_copy (gpointer boxed)
inline static

Definition at line 506 of file SimaPreparedRuntimeAbi.h.

506static inline gpointer sima_prepared_runtime_handle_boxed_copy(gpointer boxed) {
507 auto* handle = static_cast<SimaPreparedRuntimeHandle*>(boxed);
508 if (handle && handle->ref) {
509 handle->ref(handle->user_data);
510 }
511 return boxed;
512}

sima_prepared_runtime_handle_boxed_free()​

void sima_prepared_runtime_handle_boxed_free (gpointer boxed)
inline static

Definition at line 514 of file SimaPreparedRuntimeAbi.h.

514static inline void sima_prepared_runtime_handle_boxed_free(gpointer boxed) {
515 auto* handle = static_cast<SimaPreparedRuntimeHandle*>(boxed);
516 if (handle && handle->unref) {
517 handle->unref(handle->user_data);
518 }
519}

sima_prepared_runtime_handle_get_type()​

GType sima_prepared_runtime_handle_get_type (void)
inline static

Definition at line 521 of file SimaPreparedRuntimeAbi.h.

521static inline GType sima_prepared_runtime_handle_get_type(void) {
522 static const gchar* kTypeName = "SimaPreparedRuntimeHandle";
523 GType type = g_type_from_name(kTypeName);
524 if (type != 0) {
525 return type;
526 }
527 return g_boxed_type_register_static(kTypeName, sima_prepared_runtime_handle_boxed_copy,
528 sima_prepared_runtime_handle_boxed_free);
529}

sima_prepared_runtime_lookup_status_name()​

const gchar * sima_prepared_runtime_lookup_status_name (SimaPreparedRuntimeLookupStatus status)
inline static

Definition at line 481 of file SimaPreparedRuntimeAbi.h.

481sima_prepared_runtime_lookup_status_name(SimaPreparedRuntimeLookupStatus status) {
482 switch (status) {
484 return "ok";
486 return "no_context";
488 return "wrong_context_type";
490 return "missing_handle";
492 return "handle_abi_mismatch";
494 return "handle_accessor_null";
496 return "handle_callback_missing";
498 return "stage_not_found";
500 return "stage_kind_mismatch";
501 default:
502 return "unknown";
503 }
504}

sima_prepared_runtime_set_lookup_status()​

void sima_prepared_runtime_set_lookup_status (SimaPreparedRuntimeLookupStatus * status, SimaPreparedRuntimeLookupStatus value)
inline static

Definition at line 531 of file SimaPreparedRuntimeAbi.h.

531static inline void sima_prepared_runtime_set_lookup_status(SimaPreparedRuntimeLookupStatus* status,
533 if (status) {
534 *status = value;
535 }
536}

Macro Definitions​

SIMA_PREPARED_RUNTIME_ABI_VERSION​

#define SIMA_PREPARED_RUNTIME_ABI_VERSION   ((guint)2)

Definition at line 18 of file SimaPreparedRuntimeAbi.h.

18#define SIMA_PREPARED_RUNTIME_ABI_VERSION ((guint)2)

SIMA_PREPARED_RUNTIME_CONTEXT_TYPE​

#define SIMA_PREPARED_RUNTIME_CONTEXT_TYPE   "sima.model.prepared-runtime"

Definition at line 17 of file SimaPreparedRuntimeAbi.h.

17#define SIMA_PREPARED_RUNTIME_CONTEXT_TYPE "sima.model.prepared-runtime"

SIMA_PREPARED_RUNTIME_KEY_HANDLE​

#define SIMA_PREPARED_RUNTIME_KEY_HANDLE   "prepared_runtime_handle"

Definition at line 22 of file SimaPreparedRuntimeAbi.h.

22#define SIMA_PREPARED_RUNTIME_KEY_HANDLE "prepared_runtime_handle"

SIMA_PREPARED_RUNTIME_KEY_MODEL_ID​

#define SIMA_PREPARED_RUNTIME_KEY_MODEL_ID   "model_id"

Definition at line 21 of file SimaPreparedRuntimeAbi.h.

21#define SIMA_PREPARED_RUNTIME_KEY_MODEL_ID "model_id"

SIMA_PREPARED_RUNTIME_KEY_SESSION_ID​

#define SIMA_PREPARED_RUNTIME_KEY_SESSION_ID   "session_id"

Definition at line 20 of file SimaPreparedRuntimeAbi.h.

20#define SIMA_PREPARED_RUNTIME_KEY_SESSION_ID "session_id"

File Listing​

The file content with the documentation metadata removed is:

1#pragma once
2
3#include <gst/gst.h>
4
5#include <gstsimaaitensorbuffer.h>
6
8#include <ev/ev_tensor_abi.h>
9
10#include <array>
11#include <cstdint>
12#include <optional>
13#include <string>
14#include <utility>
15#include <vector>
16
17#define SIMA_PREPARED_RUNTIME_CONTEXT_TYPE "sima.model.prepared-runtime"
18#define SIMA_PREPARED_RUNTIME_ABI_VERSION ((guint)2)
19
20#define SIMA_PREPARED_RUNTIME_KEY_SESSION_ID "session_id"
21#define SIMA_PREPARED_RUNTIME_KEY_MODEL_ID "model_id"
22#define SIMA_PREPARED_RUNTIME_KEY_HANDLE "prepared_runtime_handle"
23
34};
35
36namespace simaai::gst {
37
38enum class PreparedStageKind : std::uint8_t {
39 Unknown = 0,
40 Cast = 1,
41 ProcessMla = 2,
42 ProcessCvu = 3,
43 Dequant = 4,
45};
46
48 std::string stage_key;
49 gint direction = 0;
50 TensorBufferPublishContract identity_publish_contract;
51 std::optional<TensorBufferPreparedMetaTemplate> prepared_meta_template;
53 std::uint64_t output_gst_flags = 0U;
54};
55
57 std::string stage_key;
59 TensorBufferReadRequest input_request;
60 TensorBufferPublishContract output_publish_contract;
61 std::optional<TensorBufferPreparedMetaTemplate> output_meta_template;
62 GstCaps* sink_caps = nullptr;
63 GstCaps* src_caps = nullptr;
64
67 reset();
68 }
69
72
74 : stage_key(std::move(other.stage_key)), runtime_cfg(std::move(other.runtime_cfg)),
75 input_request(std::move(other.input_request)),
76 output_publish_contract(std::move(other.output_publish_contract)),
77 output_meta_template(std::move(other.output_meta_template)), sink_caps(other.sink_caps),
78 src_caps(other.src_caps) {
79 other.sink_caps = nullptr;
80 other.src_caps = nullptr;
81 }
82
84 if (this != &other) {
85 reset();
86 stage_key = std::move(other.stage_key);
87 runtime_cfg = std::move(other.runtime_cfg);
88 input_request = std::move(other.input_request);
89 output_publish_contract = std::move(other.output_publish_contract);
90 output_meta_template = std::move(other.output_meta_template);
91 sink_caps = other.sink_caps;
92 src_caps = other.src_caps;
93 other.sink_caps = nullptr;
94 other.src_caps = nullptr;
95 }
96 return *this;
97 }
98
99 void reset() {
100 if (sink_caps) {
101 gst_caps_unref(sink_caps);
102 sink_caps = nullptr;
103 }
104 if (src_caps) {
105 gst_caps_unref(src_caps);
106 src_caps = nullptr;
107 }
108 }
109};
110
111struct Dims {
112 int w = 0;
113 int h = 0;
114};
115
116enum class PreparedTensorMaterializationKind : std::uint8_t {
117 Unknown = 0,
118 Direct = 1,
119 OffsetView = 2,
121};
122
130 std::uint64_t source_size_bytes = 0U;
131 std::int64_t source_byte_offset = 0;
132 std::string group_name;
133 std::string segment_name;
134 std::string graph_input_name;
135 std::vector<std::int64_t> shape;
136 std::string dtype;
137 std::string layout;
138};
139
141 int output_slot = 0;
144 std::int64_t byte_offset = 0;
145 std::string dispatcher_name;
146 std::string cm_output_name;
147 std::string segment_name;
148 enum class ContractKind {
149 Dense,
150 Packed,
151 };
153 std::vector<std::int64_t> shape;
154 std::optional<std::uint64_t> size_bytes;
155 std::string dtype;
156 std::string layout;
157};
158
160 std::vector<CvuInputMemoryBinding> input_bindings;
161 std::vector<CvuOutputBinding> runtime_output_bindings;
162 std::vector<CvuOutputBinding> exposed_output_bindings;
163 std::optional<Dims> global_input_dims;
164 bool is_preproc_graph = false;
166 bool single_input_mode = false;
167};
168
170 int logical_index = -1;
173 std::vector<std::int64_t> shape;
174 std::vector<std::int64_t> stride_bytes;
175 std::int64_t byte_offset = 0;
176 std::uint64_t size_bytes = 0U;
177 std::string dtype;
178 std::string layout;
179 std::string logical_name;
180 std::string backend_name;
181 std::string segment_name;
184 std::optional<TensorBufferQuantView> quant;
185};
186
191 std::uint64_t size_bytes = 0U;
192 std::int64_t source_byte_offset = 0;
193 std::string segment_name;
194};
195
197 std::string graph_name;
198 std::string cpu;
199 std::string requested_run_target = "AUTO";
200 std::string run_target = "AUTO";
201 std::string resolved_exec_backend = "EVXX";
203 int32_t graph_id = -1;
204 std::string default_input_name;
205
206 int32_t scaled_width = -1;
207 int32_t scaled_height = -1;
208 int32_t input_stride = -1;
209 int32_t output_stride = -1;
210 int32_t input_offset = -1;
211 int32_t batch_size = -1;
212 int32_t round_off = -1;
213 int32_t byte_align = -1;
214 std::uint32_t opt_flags = 0U;
215 int32_t pad_value = 0;
216
217 int32_t aspect_ratio = -1;
218 int32_t normalize = -1;
219 int32_t tessellate = -1;
220
221 bool has_q_scale = false;
222 float q_scale = 1.0f;
223 bool has_q_zp = false;
224 int32_t q_zp = 0;
225 int32_t num_in_tensor = -1;
226 std::vector<sima_ev_tensor_desc> input_tensors;
227 std::vector<sima_ev_tensor_desc> output_tensors;
229 std::vector<float> q_scale_array;
230 std::vector<int32_t> q_zp_array;
231 std::vector<float> dq_scale_array;
232 std::vector<int32_t> dq_zp_array;
233 std::vector<int32_t> round_off_array;
234 std::vector<int32_t> byte_align_array;
235 std::vector<std::string> input_dtype_array;
236 std::vector<std::string> output_dtype_array;
237 std::vector<std::string> out_dtype_array;
238 std::vector<std::string> runtime_output_names;
239 std::vector<std::string> published_output_names;
242
243 bool has_channel_mean = false;
244 std::array<float, 3> channel_mean = {0.0f, 0.0f, 0.0f};
245 bool has_channel_stddev = false;
246 std::array<float, 3> channel_stddev = {1.0f, 1.0f, 1.0f};
247
248 std::string input_img_type;
249 std::string output_img_type;
250 std::string input_dtype;
251 std::string output_dtype;
252 std::string out_dtype;
253 std::string scaling_type;
254 std::string padding_type;
255};
256
258 std::string stage_key;
260 std::vector<ProcessCvuPreparedLogicalInput> logical_inputs;
261 std::vector<ProcessCvuPreparedPhysicalInput> physical_inputs;
263 TensorBufferPublishContract output_publish_contract;
264 std::optional<TensorBufferPreparedMetaTemplate> output_meta_template;
267 GstCaps* sink_caps = nullptr;
268 GstCaps* src_caps = nullptr;
269
272 reset();
273 }
274
277
279 : stage_key(std::move(other.stage_key)), typed_config(std::move(other.typed_config)),
280 logical_inputs(std::move(other.logical_inputs)),
281 physical_inputs(std::move(other.physical_inputs)),
282 routing_contract(std::move(other.routing_contract)),
283 output_publish_contract(std::move(other.output_publish_contract)),
284 output_meta_template(std::move(other.output_meta_template)),
285 primary_output_name(std::move(other.primary_output_name)),
286 primary_output_packed_caps(other.primary_output_packed_caps), sink_caps(other.sink_caps),
287 src_caps(other.src_caps) {
288 other.sink_caps = nullptr;
289 other.src_caps = nullptr;
290 }
291
293 if (this != &other) {
294 reset();
295 stage_key = std::move(other.stage_key);
296 typed_config = std::move(other.typed_config);
297 logical_inputs = std::move(other.logical_inputs);
298 physical_inputs = std::move(other.physical_inputs);
299 routing_contract = std::move(other.routing_contract);
300 output_publish_contract = std::move(other.output_publish_contract);
301 output_meta_template = std::move(other.output_meta_template);
302 primary_output_name = std::move(other.primary_output_name);
303 primary_output_packed_caps = other.primary_output_packed_caps;
304 sink_caps = other.sink_caps;
305 src_caps = other.src_caps;
306 other.sink_caps = nullptr;
307 other.src_caps = nullptr;
308 }
309 return *this;
310 }
311
312 void reset() {
313 if (sink_caps) {
314 gst_caps_unref(sink_caps);
315 sink_caps = nullptr;
316 }
317 if (src_caps) {
318 gst_caps_unref(src_caps);
319 src_caps = nullptr;
320 }
321 }
322};
323
325 std::size_t input_elem_offset = 0U;
326 std::size_t output_elem_offset = 0U;
327 std::size_t elem_count = 0U;
328 std::uint64_t input_byte_offset = 0U;
329 std::uint64_t output_byte_offset = 0U;
330 double q_scale = 0.0;
331 std::int64_t q_zp = 0;
332 std::vector<std::int64_t> shape;
333 std::vector<std::int64_t> input_stride_bytes;
334 std::vector<std::int64_t> output_stride_bytes;
335 bool input_contiguous = true;
336 bool output_contiguous = true;
337};
338
340 std::string stage_key;
341 std::string input_dtype;
342 std::vector<std::int64_t> tensor_shape;
343 std::string tensor_layout;
344 std::size_t input_elem_bytes = 0U;
345 std::uint64_t required_input_bytes = 0U;
346 std::uint64_t required_output_bytes = 0U;
347 bool has_scalar_quant = false;
348 double q_scale = 0.0;
349 std::int64_t q_zp = 0;
350 std::vector<DequantPreparedSpan> quant_spans;
351 TensorBufferPublishContract identity_publish_contract;
352 std::optional<TensorBufferPreparedMetaTemplate> prepared_meta_template;
353 GstCaps* sink_caps = nullptr;
354 GstCaps* src_caps = nullptr;
355
358 reset();
359 }
360
363
365 : stage_key(std::move(other.stage_key)), input_dtype(std::move(other.input_dtype)),
366 tensor_shape(std::move(other.tensor_shape)), tensor_layout(std::move(other.tensor_layout)),
367 input_elem_bytes(other.input_elem_bytes), required_input_bytes(other.required_input_bytes),
368 required_output_bytes(other.required_output_bytes),
369 has_scalar_quant(other.has_scalar_quant), q_scale(other.q_scale), q_zp(other.q_zp),
370 quant_spans(std::move(other.quant_spans)),
371 identity_publish_contract(std::move(other.identity_publish_contract)),
372 prepared_meta_template(std::move(other.prepared_meta_template)), sink_caps(other.sink_caps),
373 src_caps(other.src_caps) {
374 other.input_elem_bytes = 0U;
375 other.required_input_bytes = 0U;
376 other.required_output_bytes = 0U;
377 other.has_scalar_quant = false;
378 other.q_scale = 0.0;
379 other.q_zp = 0;
380 other.sink_caps = nullptr;
381 other.src_caps = nullptr;
382 }
383
385 if (this != &other) {
386 reset();
387 stage_key = std::move(other.stage_key);
388 input_dtype = std::move(other.input_dtype);
389 tensor_shape = std::move(other.tensor_shape);
390 tensor_layout = std::move(other.tensor_layout);
391 input_elem_bytes = other.input_elem_bytes;
392 required_input_bytes = other.required_input_bytes;
393 required_output_bytes = other.required_output_bytes;
394 has_scalar_quant = other.has_scalar_quant;
395 q_scale = other.q_scale;
396 q_zp = other.q_zp;
397 quant_spans = std::move(other.quant_spans);
398 identity_publish_contract = std::move(other.identity_publish_contract);
399 prepared_meta_template = std::move(other.prepared_meta_template);
400 sink_caps = other.sink_caps;
401 src_caps = other.src_caps;
402 other.input_elem_bytes = 0U;
403 other.required_input_bytes = 0U;
404 other.required_output_bytes = 0U;
405 other.has_scalar_quant = false;
406 other.q_scale = 0.0;
407 other.q_zp = 0;
408 other.sink_caps = nullptr;
409 other.src_caps = nullptr;
410 }
411 return *this;
412 }
413
414 void reset() {
415 if (sink_caps) {
416 gst_caps_unref(sink_caps);
417 sink_caps = nullptr;
418 }
419 if (src_caps) {
420 gst_caps_unref(src_caps);
421 src_caps = nullptr;
422 }
423 }
424};
425
427 std::string stage_key;
428 std::vector<std::vector<int>> output_shapes;
429 std::vector<std::vector<int>> slice_shapes;
430 std::vector<double> default_dq_scales;
431 std::vector<double> default_dq_zps;
432 TensorBufferPublishContract identity_publish_contract;
433 std::optional<TensorBufferPreparedMetaTemplate> prepared_meta_template;
434};
435
437 std::string stage_key;
439 std::optional<CastPreparedStage> cast;
440 std::optional<ProcessMlaPreparedStage> processmla;
441 std::optional<ProcessCvuPreparedStage> processcvu;
442 std::optional<DequantPreparedStage> dequant;
443 std::optional<DetessDequantPreparedStage> detessdequant;
444};
445
446} // namespace simaai::gst
447
449
452 gpointer user_data;
453 void (*ref)(gpointer user_data);
454 void (*unref)(gpointer user_data);
455 const SimaPreparedRuntimeAccessor* (*accessor)(gpointer user_data);
457
460 gpointer user_data;
461
462 const gchar* (*session_id)(gpointer user_data);
463 const gchar* (*model_id)(gpointer user_data);
464
465 guint (*stage_count)(gpointer user_data);
466 const simaai::gst::PreparedStageSpec* (*stage_by_index)(gpointer user_data, guint index);
467 const simaai::gst::PreparedStageSpec* (*stage_by_key)(gpointer user_data, const gchar* stage_key);
468 const simaai::gst::CastPreparedStage* (*cast_stage_by_key)(gpointer user_data,
469 const gchar* stage_key);
470 const simaai::gst::ProcessMlaPreparedStage* (*processmla_stage_by_key)(gpointer user_data,
471 const gchar* stage_key);
472 const simaai::gst::ProcessCvuPreparedStage* (*processcvu_stage_by_key)(gpointer user_data,
473 const gchar* stage_key);
474 const simaai::gst::DequantPreparedStage* (*dequant_stage_by_key)(gpointer user_data,
475 const gchar* stage_key);
476 const simaai::gst::DetessDequantPreparedStage* (*detessdequant_stage_by_key)(
477 gpointer user_data, const gchar* stage_key);
478};
479
480static inline const gchar*
481sima_prepared_runtime_lookup_status_name(SimaPreparedRuntimeLookupStatus status) {
482 switch (status) {
484 return "ok";
486 return "no_context";
488 return "wrong_context_type";
490 return "missing_handle";
492 return "handle_abi_mismatch";
494 return "handle_accessor_null";
496 return "handle_callback_missing";
498 return "stage_not_found";
500 return "stage_kind_mismatch";
501 default:
502 return "unknown";
503 }
504}
505
506static inline gpointer sima_prepared_runtime_handle_boxed_copy(gpointer boxed) {
507 auto* handle = static_cast<SimaPreparedRuntimeHandle*>(boxed);
508 if (handle && handle->ref) {
509 handle->ref(handle->user_data);
510 }
511 return boxed;
512}
513
514static inline void sima_prepared_runtime_handle_boxed_free(gpointer boxed) {
515 auto* handle = static_cast<SimaPreparedRuntimeHandle*>(boxed);
516 if (handle && handle->unref) {
517 handle->unref(handle->user_data);
518 }
519}
520
521static inline GType sima_prepared_runtime_handle_get_type(void) {
522 static const gchar* kTypeName = "SimaPreparedRuntimeHandle";
523 GType type = g_type_from_name(kTypeName);
524 if (type != 0) {
525 return type;
526 }
527 return g_boxed_type_register_static(kTypeName, sima_prepared_runtime_handle_boxed_copy,
528 sima_prepared_runtime_handle_boxed_free);
529}
530
531static inline void sima_prepared_runtime_set_lookup_status(SimaPreparedRuntimeLookupStatus* status,
533 if (status) {
534 *status = value;
535 }
536}
537
538static inline gboolean sima_prepared_runtime_context_matches(const GstContext* context) {
539 if (!context) {
540 return FALSE;
541 }
542 return g_strcmp0(gst_context_get_context_type(context), SIMA_PREPARED_RUNTIME_CONTEXT_TYPE) == 0;
543}
544
545static inline const GstStructure*
546sima_prepared_runtime_context_structure(const GstContext* context) {
547 if (!sima_prepared_runtime_context_matches(context)) {
548 return NULL;
549 }
550 return gst_context_get_structure(context);
551}
552
553static inline const SimaPreparedRuntimeHandle*
554sima_prepared_runtime_context_handle(const GstContext* context) {
555 const GstStructure* structure = sima_prepared_runtime_context_structure(context);
556 if (!structure) {
557 return NULL;
558 }
559 const GValue* handle_val = gst_structure_get_value(structure, SIMA_PREPARED_RUNTIME_KEY_HANDLE);
560 if (!handle_val || G_VALUE_TYPE(handle_val) != sima_prepared_runtime_handle_get_type()) {
561 return NULL;
562 }
563 return static_cast<const SimaPreparedRuntimeHandle*>(g_value_get_boxed(handle_val));
564}
565
566static inline const SimaPreparedRuntimeAccessor*
567sima_prepared_runtime_context_accessor_checked(const GstContext* context,
569 if (!context) {
570 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_NO_CONTEXT);
571 return nullptr;
572 }
573 if (!sima_prepared_runtime_context_matches(context)) {
574 sima_prepared_runtime_set_lookup_status(status,
576 return nullptr;
577 }
578 const auto* handle = sima_prepared_runtime_context_handle(context);
579 if (!handle) {
580 sima_prepared_runtime_set_lookup_status(status,
582 return nullptr;
583 }
584 if (handle->abi_version != SIMA_PREPARED_RUNTIME_ABI_VERSION) {
585 sima_prepared_runtime_set_lookup_status(
587 return nullptr;
588 }
589 if (!handle->ref || !handle->unref || !handle->accessor) {
590 sima_prepared_runtime_set_lookup_status(
592 return nullptr;
593 }
594 const auto* accessor = handle->accessor(handle->user_data);
595 if (!accessor) {
596 sima_prepared_runtime_set_lookup_status(
598 return nullptr;
599 }
600 if (accessor->abi_version != SIMA_PREPARED_RUNTIME_ABI_VERSION) {
601 sima_prepared_runtime_set_lookup_status(
603 return nullptr;
604 }
605 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
606 return accessor;
607}
608
609static inline const simaai::gst::PreparedStageSpec*
610sima_prepared_runtime_context_stage_lookup_checked(const GstContext* context,
611 const gchar* stage_key,
613 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
614 if (!accessor || !accessor->stage_by_key || !stage_key || !*stage_key) {
615 if (status && (!stage_key || !*stage_key)) {
617 }
618 return nullptr;
619 }
620 const auto* stage = accessor->stage_by_key(accessor->user_data, stage_key);
621 if (!stage) {
622 sima_prepared_runtime_set_lookup_status(status,
624 return nullptr;
625 }
626 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
627 return stage;
628}
629
630static inline const simaai::gst::CastPreparedStage*
631sima_prepared_runtime_context_cast_stage_lookup_checked(const GstContext* context,
632 const gchar* stage_key,
634 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
635 if (!accessor || !accessor->cast_stage_by_key || !stage_key || !*stage_key) {
636 if (status && (!stage_key || !*stage_key)) {
638 }
639 return nullptr;
640 }
641 const auto* stage = accessor->cast_stage_by_key(accessor->user_data, stage_key);
642 if (!stage) {
643 const auto* generic =
644 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
645 sima_prepared_runtime_set_lookup_status(
648 return nullptr;
649 }
650 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
651 return stage;
652}
653
654static inline const simaai::gst::ProcessMlaPreparedStage*
655sima_prepared_runtime_context_processmla_stage_lookup_checked(
656 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
657 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
658 if (!accessor || !accessor->processmla_stage_by_key || !stage_key || !*stage_key) {
659 if (status && (!stage_key || !*stage_key)) {
661 }
662 return nullptr;
663 }
664 const auto* stage = accessor->processmla_stage_by_key(accessor->user_data, stage_key);
665 if (!stage) {
666 const auto* generic =
667 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
668 sima_prepared_runtime_set_lookup_status(
671 return nullptr;
672 }
673 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
674 return stage;
675}
676
677static inline const simaai::gst::ProcessCvuPreparedStage*
678sima_prepared_runtime_context_processcvu_stage_lookup_checked(
679 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
680 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
681 if (!accessor || !accessor->processcvu_stage_by_key || !stage_key || !*stage_key) {
682 if (status && (!stage_key || !*stage_key)) {
684 }
685 return nullptr;
686 }
687 const auto* stage = accessor->processcvu_stage_by_key(accessor->user_data, stage_key);
688 if (!stage) {
689 const auto* generic =
690 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
691 sima_prepared_runtime_set_lookup_status(
694 return nullptr;
695 }
696 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
697 return stage;
698}
699
700static inline const simaai::gst::DequantPreparedStage*
701sima_prepared_runtime_context_dequant_stage_lookup_checked(
702 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
703 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
704 if (!accessor || !accessor->dequant_stage_by_key || !stage_key || !*stage_key) {
705 if (status && (!stage_key || !*stage_key)) {
707 }
708 return nullptr;
709 }
710 const auto* stage = accessor->dequant_stage_by_key(accessor->user_data, stage_key);
711 if (!stage) {
712 const auto* generic =
713 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
714 sima_prepared_runtime_set_lookup_status(
717 return nullptr;
718 }
719 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
720 return stage;
721}
722
724sima_prepared_runtime_context_detessdequant_stage_lookup_checked(
725 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
726 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
727 if (!accessor || !accessor->detessdequant_stage_by_key || !stage_key || !*stage_key) {
728 if (status && (!stage_key || !*stage_key)) {
730 }
731 return nullptr;
732 }
733 const auto* stage = accessor->detessdequant_stage_by_key(accessor->user_data, stage_key);
734 if (!stage) {
735 const auto* generic =
736 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
737 sima_prepared_runtime_set_lookup_status(
740 return nullptr;
741 }
742 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
743 return stage;
744}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.