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)1)
#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 455 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 566 of file SimaPreparedRuntimeAbi.h.

566sima_prepared_runtime_context_accessor_checked(const GstContext* context,
568 if (!context) {
569 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_NO_CONTEXT);
570 return nullptr;
571 }
572 if (!sima_prepared_runtime_context_matches(context)) {
573 sima_prepared_runtime_set_lookup_status(status,
575 return nullptr;
576 }
577 const auto* handle = sima_prepared_runtime_context_handle(context);
578 if (!handle) {
579 sima_prepared_runtime_set_lookup_status(status,
581 return nullptr;
582 }
583 if (handle->abi_version != SIMA_PREPARED_RUNTIME_ABI_VERSION) {
584 sima_prepared_runtime_set_lookup_status(
586 return nullptr;
587 }
588 if (!handle->ref || !handle->unref || !handle->accessor) {
589 sima_prepared_runtime_set_lookup_status(
591 return nullptr;
592 }
593 const auto* accessor = handle->accessor(handle->user_data);
594 if (!accessor) {
595 sima_prepared_runtime_set_lookup_status(
597 return nullptr;
598 }
599 if (accessor->abi_version != SIMA_PREPARED_RUNTIME_ABI_VERSION) {
600 sima_prepared_runtime_set_lookup_status(
602 return nullptr;
603 }
604 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
605 return accessor;
606}

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 630 of file SimaPreparedRuntimeAbi.h.

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

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 700 of file SimaPreparedRuntimeAbi.h.

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

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 723 of file SimaPreparedRuntimeAbi.h.

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

sima_prepared_runtime_context_handle()​

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

Definition at line 553 of file SimaPreparedRuntimeAbi.h.

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

sima_prepared_runtime_context_matches()​

gboolean sima_prepared_runtime_context_matches (const GstContext * context)
inline static

Definition at line 537 of file SimaPreparedRuntimeAbi.h.

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

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 677 of file SimaPreparedRuntimeAbi.h.

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

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 654 of file SimaPreparedRuntimeAbi.h.

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

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 609 of file SimaPreparedRuntimeAbi.h.

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

sima_prepared_runtime_context_structure()​

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

Definition at line 545 of file SimaPreparedRuntimeAbi.h.

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

sima_prepared_runtime_handle_boxed_copy()​

gpointer sima_prepared_runtime_handle_boxed_copy (gpointer boxed)
inline static

Definition at line 505 of file SimaPreparedRuntimeAbi.h.

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

sima_prepared_runtime_handle_boxed_free()​

void sima_prepared_runtime_handle_boxed_free (gpointer boxed)
inline static

Definition at line 513 of file SimaPreparedRuntimeAbi.h.

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

sima_prepared_runtime_handle_get_type()​

GType sima_prepared_runtime_handle_get_type (void)
inline static

Definition at line 520 of file SimaPreparedRuntimeAbi.h.

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

sima_prepared_runtime_lookup_status_name()​

const gchar* sima_prepared_runtime_lookup_status_name (SimaPreparedRuntimeLookupStatus status)
inline static

Definition at line 480 of file SimaPreparedRuntimeAbi.h.

480sima_prepared_runtime_lookup_status_name(SimaPreparedRuntimeLookupStatus status) {
481 switch (status) {
483 return "ok";
485 return "no_context";
487 return "wrong_context_type";
489 return "missing_handle";
491 return "handle_abi_mismatch";
493 return "handle_accessor_null";
495 return "handle_callback_missing";
497 return "stage_not_found";
499 return "stage_kind_mismatch";
500 default:
501 return "unknown";
502 }
503}

sima_prepared_runtime_set_lookup_status()​

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

Definition at line 530 of file SimaPreparedRuntimeAbi.h.

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

Macro Definitions​

SIMA_PREPARED_RUNTIME_ABI_VERSION​

#define SIMA_PREPARED_RUNTIME_ABI_VERSION   ((guint)1)

Definition at line 18 of file SimaPreparedRuntimeAbi.h.

18#define SIMA_PREPARED_RUNTIME_ABI_VERSION ((guint)1)

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)1)
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
216 int32_t aspect_ratio = -1;
217 int32_t normalize = -1;
218 int32_t tessellate = -1;
219
220 bool has_q_scale = false;
221 float q_scale = 1.0f;
222 bool has_q_zp = false;
223 int32_t q_zp = 0;
224 int32_t num_in_tensor = -1;
225 std::vector<sima_ev_tensor_desc> input_tensors;
226 std::vector<sima_ev_tensor_desc> output_tensors;
228 std::vector<float> q_scale_array;
229 std::vector<int32_t> q_zp_array;
230 std::vector<float> dq_scale_array;
231 std::vector<int32_t> dq_zp_array;
232 std::vector<int32_t> round_off_array;
233 std::vector<int32_t> byte_align_array;
234 std::vector<std::string> input_dtype_array;
235 std::vector<std::string> output_dtype_array;
236 std::vector<std::string> out_dtype_array;
237 std::vector<std::string> runtime_output_names;
238 std::vector<std::string> published_output_names;
241
242 bool has_channel_mean = false;
243 std::array<float, 3> channel_mean = {0.0f, 0.0f, 0.0f};
244 bool has_channel_stddev = false;
245 std::array<float, 3> channel_stddev = {1.0f, 1.0f, 1.0f};
246
247 std::string input_img_type;
248 std::string output_img_type;
249 std::string input_dtype;
250 std::string output_dtype;
251 std::string out_dtype;
252 std::string scaling_type;
253 std::string padding_type;
254};
255
257 std::string stage_key;
259 std::vector<ProcessCvuPreparedLogicalInput> logical_inputs;
260 std::vector<ProcessCvuPreparedPhysicalInput> physical_inputs;
262 TensorBufferPublishContract output_publish_contract;
263 std::optional<TensorBufferPreparedMetaTemplate> output_meta_template;
266 GstCaps* sink_caps = nullptr;
267 GstCaps* src_caps = nullptr;
268
271 reset();
272 }
273
276
278 : stage_key(std::move(other.stage_key)), typed_config(std::move(other.typed_config)),
279 logical_inputs(std::move(other.logical_inputs)),
280 physical_inputs(std::move(other.physical_inputs)),
281 routing_contract(std::move(other.routing_contract)),
282 output_publish_contract(std::move(other.output_publish_contract)),
283 output_meta_template(std::move(other.output_meta_template)),
284 primary_output_name(std::move(other.primary_output_name)),
285 primary_output_packed_caps(other.primary_output_packed_caps), sink_caps(other.sink_caps),
286 src_caps(other.src_caps) {
287 other.sink_caps = nullptr;
288 other.src_caps = nullptr;
289 }
290
292 if (this != &other) {
293 reset();
294 stage_key = std::move(other.stage_key);
295 typed_config = std::move(other.typed_config);
296 logical_inputs = std::move(other.logical_inputs);
297 physical_inputs = std::move(other.physical_inputs);
298 routing_contract = std::move(other.routing_contract);
299 output_publish_contract = std::move(other.output_publish_contract);
300 output_meta_template = std::move(other.output_meta_template);
301 primary_output_name = std::move(other.primary_output_name);
302 primary_output_packed_caps = other.primary_output_packed_caps;
303 sink_caps = other.sink_caps;
304 src_caps = other.src_caps;
305 other.sink_caps = nullptr;
306 other.src_caps = nullptr;
307 }
308 return *this;
309 }
310
311 void reset() {
312 if (sink_caps) {
313 gst_caps_unref(sink_caps);
314 sink_caps = nullptr;
315 }
316 if (src_caps) {
317 gst_caps_unref(src_caps);
318 src_caps = nullptr;
319 }
320 }
321};
322
324 std::size_t input_elem_offset = 0U;
325 std::size_t output_elem_offset = 0U;
326 std::size_t elem_count = 0U;
327 std::uint64_t input_byte_offset = 0U;
328 std::uint64_t output_byte_offset = 0U;
329 double q_scale = 0.0;
330 std::int64_t q_zp = 0;
331 std::vector<std::int64_t> shape;
332 std::vector<std::int64_t> input_stride_bytes;
333 std::vector<std::int64_t> output_stride_bytes;
334 bool input_contiguous = true;
335 bool output_contiguous = true;
336};
337
339 std::string stage_key;
340 std::string input_dtype;
341 std::vector<std::int64_t> tensor_shape;
342 std::string tensor_layout;
343 std::size_t input_elem_bytes = 0U;
344 std::uint64_t required_input_bytes = 0U;
345 std::uint64_t required_output_bytes = 0U;
346 bool has_scalar_quant = false;
347 double q_scale = 0.0;
348 std::int64_t q_zp = 0;
349 std::vector<DequantPreparedSpan> quant_spans;
350 TensorBufferPublishContract identity_publish_contract;
351 std::optional<TensorBufferPreparedMetaTemplate> prepared_meta_template;
352 GstCaps* sink_caps = nullptr;
353 GstCaps* src_caps = nullptr;
354
357 reset();
358 }
359
362
364 : stage_key(std::move(other.stage_key)), input_dtype(std::move(other.input_dtype)),
365 tensor_shape(std::move(other.tensor_shape)), tensor_layout(std::move(other.tensor_layout)),
366 input_elem_bytes(other.input_elem_bytes), required_input_bytes(other.required_input_bytes),
367 required_output_bytes(other.required_output_bytes),
368 has_scalar_quant(other.has_scalar_quant), q_scale(other.q_scale), q_zp(other.q_zp),
369 quant_spans(std::move(other.quant_spans)),
370 identity_publish_contract(std::move(other.identity_publish_contract)),
371 prepared_meta_template(std::move(other.prepared_meta_template)), sink_caps(other.sink_caps),
372 src_caps(other.src_caps) {
373 other.input_elem_bytes = 0U;
374 other.required_input_bytes = 0U;
375 other.required_output_bytes = 0U;
376 other.has_scalar_quant = false;
377 other.q_scale = 0.0;
378 other.q_zp = 0;
379 other.sink_caps = nullptr;
380 other.src_caps = nullptr;
381 }
382
384 if (this != &other) {
385 reset();
386 stage_key = std::move(other.stage_key);
387 input_dtype = std::move(other.input_dtype);
388 tensor_shape = std::move(other.tensor_shape);
389 tensor_layout = std::move(other.tensor_layout);
390 input_elem_bytes = other.input_elem_bytes;
391 required_input_bytes = other.required_input_bytes;
392 required_output_bytes = other.required_output_bytes;
393 has_scalar_quant = other.has_scalar_quant;
394 q_scale = other.q_scale;
395 q_zp = other.q_zp;
396 quant_spans = std::move(other.quant_spans);
397 identity_publish_contract = std::move(other.identity_publish_contract);
398 prepared_meta_template = std::move(other.prepared_meta_template);
399 sink_caps = other.sink_caps;
400 src_caps = other.src_caps;
401 other.input_elem_bytes = 0U;
402 other.required_input_bytes = 0U;
403 other.required_output_bytes = 0U;
404 other.has_scalar_quant = false;
405 other.q_scale = 0.0;
406 other.q_zp = 0;
407 other.sink_caps = nullptr;
408 other.src_caps = nullptr;
409 }
410 return *this;
411 }
412
413 void reset() {
414 if (sink_caps) {
415 gst_caps_unref(sink_caps);
416 sink_caps = nullptr;
417 }
418 if (src_caps) {
419 gst_caps_unref(src_caps);
420 src_caps = nullptr;
421 }
422 }
423};
424
426 std::string stage_key;
427 std::vector<std::vector<int>> output_shapes;
428 std::vector<std::vector<int>> slice_shapes;
429 std::vector<double> default_dq_scales;
430 std::vector<double> default_dq_zps;
431 TensorBufferPublishContract identity_publish_contract;
432 std::optional<TensorBufferPreparedMetaTemplate> prepared_meta_template;
433};
434
436 std::string stage_key;
438 std::optional<CastPreparedStage> cast;
439 std::optional<ProcessMlaPreparedStage> processmla;
440 std::optional<ProcessCvuPreparedStage> processcvu;
441 std::optional<DequantPreparedStage> dequant;
442 std::optional<DetessDequantPreparedStage> detessdequant;
443};
444
445} // namespace simaai::gst
446
448
451 gpointer user_data;
452 void (*ref)(gpointer user_data);
453 void (*unref)(gpointer user_data);
454 const SimaPreparedRuntimeAccessor* (*accessor)(gpointer user_data);
456
459 gpointer user_data;
460
461 const gchar* (*session_id)(gpointer user_data);
462 const gchar* (*model_id)(gpointer user_data);
463
464 guint (*stage_count)(gpointer user_data);
465 const simaai::gst::PreparedStageSpec* (*stage_by_index)(gpointer user_data, guint index);
466 const simaai::gst::PreparedStageSpec* (*stage_by_key)(gpointer user_data, const gchar* stage_key);
467 const simaai::gst::CastPreparedStage* (*cast_stage_by_key)(gpointer user_data,
468 const gchar* stage_key);
469 const simaai::gst::ProcessMlaPreparedStage* (*processmla_stage_by_key)(gpointer user_data,
470 const gchar* stage_key);
471 const simaai::gst::ProcessCvuPreparedStage* (*processcvu_stage_by_key)(gpointer user_data,
472 const gchar* stage_key);
473 const simaai::gst::DequantPreparedStage* (*dequant_stage_by_key)(gpointer user_data,
474 const gchar* stage_key);
475 const simaai::gst::DetessDequantPreparedStage* (*detessdequant_stage_by_key)(
476 gpointer user_data, const gchar* stage_key);
477};
478
479static inline const gchar*
480sima_prepared_runtime_lookup_status_name(SimaPreparedRuntimeLookupStatus status) {
481 switch (status) {
483 return "ok";
485 return "no_context";
487 return "wrong_context_type";
489 return "missing_handle";
491 return "handle_abi_mismatch";
493 return "handle_accessor_null";
495 return "handle_callback_missing";
497 return "stage_not_found";
499 return "stage_kind_mismatch";
500 default:
501 return "unknown";
502 }
503}
504
505static inline gpointer sima_prepared_runtime_handle_boxed_copy(gpointer boxed) {
506 auto* handle = static_cast<SimaPreparedRuntimeHandle*>(boxed);
507 if (handle && handle->ref) {
508 handle->ref(handle->user_data);
509 }
510 return boxed;
511}
512
513static inline void sima_prepared_runtime_handle_boxed_free(gpointer boxed) {
514 auto* handle = static_cast<SimaPreparedRuntimeHandle*>(boxed);
515 if (handle && handle->unref) {
516 handle->unref(handle->user_data);
517 }
518}
519
520static inline GType sima_prepared_runtime_handle_get_type(void) {
521 static const gchar* kTypeName = "SimaPreparedRuntimeHandle";
522 GType type = g_type_from_name(kTypeName);
523 if (type != 0) {
524 return type;
525 }
526 return g_boxed_type_register_static(kTypeName, sima_prepared_runtime_handle_boxed_copy,
527 sima_prepared_runtime_handle_boxed_free);
528}
529
530static inline void sima_prepared_runtime_set_lookup_status(SimaPreparedRuntimeLookupStatus* status,
532 if (status) {
533 *status = value;
534 }
535}
536
537static inline gboolean sima_prepared_runtime_context_matches(const GstContext* context) {
538 if (!context) {
539 return FALSE;
540 }
541 return g_strcmp0(gst_context_get_context_type(context), SIMA_PREPARED_RUNTIME_CONTEXT_TYPE) == 0;
542}
543
544static inline const GstStructure*
545sima_prepared_runtime_context_structure(const GstContext* context) {
546 if (!sima_prepared_runtime_context_matches(context)) {
547 return NULL;
548 }
549 return gst_context_get_structure(context);
550}
551
552static inline const SimaPreparedRuntimeHandle*
553sima_prepared_runtime_context_handle(const GstContext* context) {
554 const GstStructure* structure = sima_prepared_runtime_context_structure(context);
555 if (!structure) {
556 return NULL;
557 }
558 const GValue* handle_val = gst_structure_get_value(structure, SIMA_PREPARED_RUNTIME_KEY_HANDLE);
559 if (!handle_val || G_VALUE_TYPE(handle_val) != sima_prepared_runtime_handle_get_type()) {
560 return NULL;
561 }
562 return static_cast<const SimaPreparedRuntimeHandle*>(g_value_get_boxed(handle_val));
563}
564
565static inline const SimaPreparedRuntimeAccessor*
566sima_prepared_runtime_context_accessor_checked(const GstContext* context,
568 if (!context) {
569 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_NO_CONTEXT);
570 return nullptr;
571 }
572 if (!sima_prepared_runtime_context_matches(context)) {
573 sima_prepared_runtime_set_lookup_status(status,
575 return nullptr;
576 }
577 const auto* handle = sima_prepared_runtime_context_handle(context);
578 if (!handle) {
579 sima_prepared_runtime_set_lookup_status(status,
581 return nullptr;
582 }
583 if (handle->abi_version != SIMA_PREPARED_RUNTIME_ABI_VERSION) {
584 sima_prepared_runtime_set_lookup_status(
586 return nullptr;
587 }
588 if (!handle->ref || !handle->unref || !handle->accessor) {
589 sima_prepared_runtime_set_lookup_status(
591 return nullptr;
592 }
593 const auto* accessor = handle->accessor(handle->user_data);
594 if (!accessor) {
595 sima_prepared_runtime_set_lookup_status(
597 return nullptr;
598 }
599 if (accessor->abi_version != SIMA_PREPARED_RUNTIME_ABI_VERSION) {
600 sima_prepared_runtime_set_lookup_status(
602 return nullptr;
603 }
604 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
605 return accessor;
606}
607
608static inline const simaai::gst::PreparedStageSpec*
609sima_prepared_runtime_context_stage_lookup_checked(const GstContext* context,
610 const gchar* stage_key,
612 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
613 if (!accessor || !accessor->stage_by_key || !stage_key || !*stage_key) {
614 if (status && (!stage_key || !*stage_key)) {
616 }
617 return nullptr;
618 }
619 const auto* stage = accessor->stage_by_key(accessor->user_data, stage_key);
620 if (!stage) {
621 sima_prepared_runtime_set_lookup_status(status,
623 return nullptr;
624 }
625 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
626 return stage;
627}
628
629static inline const simaai::gst::CastPreparedStage*
630sima_prepared_runtime_context_cast_stage_lookup_checked(const GstContext* context,
631 const gchar* stage_key,
633 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
634 if (!accessor || !accessor->cast_stage_by_key || !stage_key || !*stage_key) {
635 if (status && (!stage_key || !*stage_key)) {
637 }
638 return nullptr;
639 }
640 const auto* stage = accessor->cast_stage_by_key(accessor->user_data, stage_key);
641 if (!stage) {
642 const auto* generic =
643 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
644 sima_prepared_runtime_set_lookup_status(
647 return nullptr;
648 }
649 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
650 return stage;
651}
652
653static inline const simaai::gst::ProcessMlaPreparedStage*
654sima_prepared_runtime_context_processmla_stage_lookup_checked(
655 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
656 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
657 if (!accessor || !accessor->processmla_stage_by_key || !stage_key || !*stage_key) {
658 if (status && (!stage_key || !*stage_key)) {
660 }
661 return nullptr;
662 }
663 const auto* stage = accessor->processmla_stage_by_key(accessor->user_data, stage_key);
664 if (!stage) {
665 const auto* generic =
666 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
667 sima_prepared_runtime_set_lookup_status(
670 return nullptr;
671 }
672 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
673 return stage;
674}
675
676static inline const simaai::gst::ProcessCvuPreparedStage*
677sima_prepared_runtime_context_processcvu_stage_lookup_checked(
678 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
679 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
680 if (!accessor || !accessor->processcvu_stage_by_key || !stage_key || !*stage_key) {
681 if (status && (!stage_key || !*stage_key)) {
683 }
684 return nullptr;
685 }
686 const auto* stage = accessor->processcvu_stage_by_key(accessor->user_data, stage_key);
687 if (!stage) {
688 const auto* generic =
689 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
690 sima_prepared_runtime_set_lookup_status(
693 return nullptr;
694 }
695 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
696 return stage;
697}
698
699static inline const simaai::gst::DequantPreparedStage*
700sima_prepared_runtime_context_dequant_stage_lookup_checked(
701 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
702 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
703 if (!accessor || !accessor->dequant_stage_by_key || !stage_key || !*stage_key) {
704 if (status && (!stage_key || !*stage_key)) {
706 }
707 return nullptr;
708 }
709 const auto* stage = accessor->dequant_stage_by_key(accessor->user_data, stage_key);
710 if (!stage) {
711 const auto* generic =
712 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
713 sima_prepared_runtime_set_lookup_status(
716 return nullptr;
717 }
718 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
719 return stage;
720}
721
723sima_prepared_runtime_context_detessdequant_stage_lookup_checked(
724 const GstContext* context, const gchar* stage_key, SimaPreparedRuntimeLookupStatus* status) {
725 const auto* accessor = sima_prepared_runtime_context_accessor_checked(context, status);
726 if (!accessor || !accessor->detessdequant_stage_by_key || !stage_key || !*stage_key) {
727 if (status && (!stage_key || !*stage_key)) {
729 }
730 return nullptr;
731 }
732 const auto* stage = accessor->detessdequant_stage_by_key(accessor->user_data, stage_key);
733 if (!stage) {
734 const auto* generic =
735 accessor->stage_by_key ? accessor->stage_by_key(accessor->user_data, stage_key) : nullptr;
736 sima_prepared_runtime_set_lookup_status(
739 return nullptr;
740 }
741 sima_prepared_runtime_set_lookup_status(status, SIMA_PREPARED_RUNTIME_LOOKUP_STATUS_OK);
742 return stage;
743}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.1.