Skip to main content

Preproc.h File

Preproc Node — fused CVU preprocessing kernel (resize + colorconvert + normalize). More...

Included Headers

#include "builder/InputContractConfigurable.h" #include "builder/NodeContractConfigurable.h" #include "builder/NodeContractProvider.h" #include "builder/Node.h" #include "builder/OutputSpec.h" #include <nlohmann/json.hpp> #include <cstdint> #include <memory> #include <optional> #include <string> #include <utility> #include <vector>

Namespaces Index

namespacesimaai
namespaceneat
namespacenodes

Classes Index

structPreprocOptions

Construction options for a Preproc Node. More...

classPreproc

Fused CVU preprocessing Node — resize + color-convert + normalize (+ optional tess). More...

Description

Preproc Node — fused CVU preprocessing kernel (resize + colorconvert + normalize).

One-shot CVU pre-processor that runs upstream of the MLA: resizes the input image, converts color space, applies per-channel mean/stddev normalization, and (optionally) tessellates the result into MLA-tile geometry. Implements the "Preproc" PreprocessGraphFamily (BF16 path with MLA-side tess); used as the front end of vision pipelines on the BF16 input path.

File Listing

The file content with the documentation metadata removed is:

1
12#pragma once
13
14#include "builder/InputContractConfigurable.h"
15#include "builder/NodeContractConfigurable.h"
16#include "builder/NodeContractProvider.h"
17#include "builder/Node.h"
18#include "builder/OutputSpec.h"
19#ifdef SIMA_NEAT_INTERNAL
20#include "model/internal/ModelRouteRetarget.h"
21#endif
22
23#include <nlohmann/json.hpp>
24
25#include <cstdint>
26#include <memory>
27#include <optional>
28#include <string>
29#include <utility>
30#include <vector>
31
32namespace simaai::neat {
33class Model;
34
46 PreprocOptions() = default;
48 explicit PreprocOptions(const simaai::neat::Model& model);
49
50 std::vector<int> input_shape;
51 std::vector<int> output_shape;
52 std::vector<int> slice_shape;
53
54 int scaled_width = 0;
55 int scaled_height = 0;
56
57 int batch_size = 1;
58
59 bool normalize = true;
60 bool aspect_ratio = true;
61 bool tessellate = true;
62 bool dynamic_input_dims = true;
64
65 int input_offset = 0;
66 int input_stride = 1;
67 int output_stride = 1;
68
69 std::optional<std::int64_t> q_zp;
70 std::optional<double> q_scale;
71
72 std::vector<float> channel_mean = {0.0f, 0.0f, 0.0f};
73 std::vector<float> channel_stddev = {1.0f, 1.0f, 1.0f};
74
75 std::string input_img_type;
76 std::string output_img_type = "RGB";
77 std::string output_dtype = "INT16";
78 std::string scaling_type = "BILINEAR";
79 std::string padding_type = "CENTER";
80 int pad_value = 0;
81
82 std::string graph_name = "preproc";
83 std::string node_name = "preproc";
84 std::string element_name;
85 std::string cpu = "CVU";
86 std::string next_cpu = "CVU";
87 std::string debug = "EVXX_DBG_DISABLED";
88
89 std::string upstream_name = "decoder";
90 std::string graph_input_name = "input_image";
91
92 int num_buffers = 0;
94 bool num_buffers_locked = false;
95 bool model_managed_contract = false;
96#ifdef SIMA_NEAT_INTERNAL
97 std::shared_ptr<const simaai::neat::internal::ModelLineageBinding> model_lineage;
98#endif
99
101 void set_input_shape(std::vector<int> shape) {
102 input_shape = std::move(shape);
103 }
104
106 void set_output_shape(std::vector<int> shape) {
107 output_shape = std::move(shape);
108 }
109
111 void set_slice_shape(std::vector<int> shape) {
112 slice_shape = std::move(shape);
113 }
114
116 static int shape_dim(const std::vector<int>& shape, std::size_t index) {
117 return shape.size() > index ? shape[index] : 0;
118 }
119
121 static int shape_channels(const std::vector<int>& shape) {
122 return shape.size() >= 3 ? shape.back() : 0;
123 }
124
126 int input_height() const {
127 return shape_dim(input_shape, 0);
128 }
129
131 int input_width() const {
132 return shape_dim(input_shape, 1);
133 }
134
136 int input_channels() const {
138 }
139
141 int output_height() const {
142 return shape_dim(output_shape, 0);
143 }
144
146 int output_width() const {
147 return shape_dim(output_shape, 1);
148 }
149
151 int output_channels() const {
153 }
154
156 int slice_height() const {
157 return shape_dim(slice_shape, 0);
158 }
159
161 int slice_width() const {
162 return shape_dim(slice_shape, 1);
163 }
164
166 int slice_channels() const {
168 }
169
171 bool has_input_shape() const {
172 return input_height() > 0 && input_width() > 0 && input_channels() > 0;
173 }
174
176 bool has_output_shape() const {
177 return output_height() > 0 && output_width() > 0 && output_channels() > 0;
178 }
179
181 bool has_slice_shape() const {
182 return slice_height() > 0 && slice_width() > 0 && slice_channels() > 0;
183 }
184};
185
194class Preproc final : public Node,
195 public OutputSpecProvider,
196 public InputContractConfigurable,
197 public NodeContractProvider,
198 public NodeContractConfigurable {
199public:
201 explicit Preproc(PreprocOptions opt = {});
202
204 std::string kind() const override {
205 return "Preproc";
206 }
208 NodeCapsBehavior caps_behavior() const override {
209 return NodeCapsBehavior::Static;
210 }
212 std::string backend_fragment(int node_index) const override;
214 std::vector<std::string> element_names(int node_index) const override;
216 OutputSpec output_spec(const OutputSpec& input) const override;
218 void apply_input_contract(const InputContract& contract, std::string* err) override;
222 bool compile_node_contract(const ContractCompileInput& input, CompiledNodeContract* out,
223 std::string* err) const override;
225 void apply_compiled_contract(const CompiledNodeContract& contract, std::string* err) override;
226
228 const PreprocOptions& options() const {
229 return opt_;
230 }
232 const std::string& config_path() const {
233 return config_path_;
234 }
236 const std::string& config_snapshot_path() const {
237 return config_path_;
238 }
240 const nlohmann::json* config_json() const;
241
242private:
243 struct PreprocConfigHolder;
244
245 void materialize_config_from_input_contract(const InputContract& contract);
246 PreprocOptions opt_;
247 std::shared_ptr<PreprocConfigHolder> config_holder_;
248 std::string config_path_;
249};
250
251} // namespace simaai::neat
252
253namespace simaai::neat::nodes {
255std::shared_ptr<simaai::neat::Node> Preproc(PreprocOptions opt = {});
256} // namespace simaai::neat::nodes

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.