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
81 std::string graph_name = "preproc";
82 std::string node_name = "preproc";
83 std::string element_name;
84 std::string cpu = "CVU";
85 std::string next_cpu = "CVU";
86 std::string debug = "EVXX_DBG_DISABLED";
87
88 std::string upstream_name = "decoder";
89 std::string graph_input_name = "input_image";
90
91 int num_buffers = 0;
93 bool num_buffers_locked = false;
94 bool model_managed_contract = false;
95#ifdef SIMA_NEAT_INTERNAL
96 std::shared_ptr<const simaai::neat::internal::ModelLineageBinding> model_lineage;
97#endif
98
100 void set_input_shape(std::vector<int> shape) {
101 input_shape = std::move(shape);
102 }
103
105 void set_output_shape(std::vector<int> shape) {
106 output_shape = std::move(shape);
107 }
108
110 void set_slice_shape(std::vector<int> shape) {
111 slice_shape = std::move(shape);
112 }
113
115 static int shape_dim(const std::vector<int>& shape, std::size_t index) {
116 return shape.size() > index ? shape[index] : 0;
117 }
118
120 static int shape_channels(const std::vector<int>& shape) {
121 return shape.size() >= 3 ? shape.back() : 0;
122 }
123
125 int input_height() const {
126 return shape_dim(input_shape, 0);
127 }
128
130 int input_width() const {
131 return shape_dim(input_shape, 1);
132 }
133
135 int input_channels() const {
137 }
138
140 int output_height() const {
141 return shape_dim(output_shape, 0);
142 }
143
145 int output_width() const {
146 return shape_dim(output_shape, 1);
147 }
148
150 int output_channels() const {
152 }
153
155 int slice_height() const {
156 return shape_dim(slice_shape, 0);
157 }
158
160 int slice_width() const {
161 return shape_dim(slice_shape, 1);
162 }
163
165 int slice_channels() const {
167 }
168
170 bool has_input_shape() const {
171 return input_height() > 0 && input_width() > 0 && input_channels() > 0;
172 }
173
175 bool has_output_shape() const {
176 return output_height() > 0 && output_width() > 0 && output_channels() > 0;
177 }
178
180 bool has_slice_shape() const {
181 return slice_height() > 0 && slice_width() > 0 && slice_channels() > 0;
182 }
183};
184
193class Preproc final : public Node,
194 public OutputSpecProvider,
195 public InputContractConfigurable,
196 public NodeContractProvider,
197 public NodeContractConfigurable {
198public:
200 explicit Preproc(PreprocOptions opt = {});
201
203 std::string kind() const override {
204 return "Preproc";
205 }
207 NodeCapsBehavior caps_behavior() const override {
208 return NodeCapsBehavior::Static;
209 }
211 std::string backend_fragment(int node_index) const override;
213 std::vector<std::string> element_names(int node_index) const override;
215 OutputSpec output_spec(const OutputSpec& input) const override;
217 void apply_input_contract(const InputContract& contract, std::string* err) override;
221 bool compile_node_contract(const ContractCompileInput& input, CompiledNodeContract* out,
222 std::string* err) const override;
224 void apply_compiled_contract(const CompiledNodeContract& contract, std::string* err) override;
225
227 const PreprocOptions& options() const {
228 return opt_;
229 }
231 const std::string& config_path() const {
232 return config_path_;
233 }
235 const std::string& config_snapshot_path() const {
236 return config_path_;
237 }
239 const nlohmann::json* config_json() const;
240
241private:
242 struct PreprocConfigHolder;
243
244 void materialize_config_from_input_contract(const InputContract& contract);
245 PreprocOptions opt_;
246 std::shared_ptr<PreprocConfigHolder> config_holder_;
247 std::string config_path_;
248};
249
250} // namespace simaai::neat
251
252namespace simaai::neat::nodes {
254std::shared_ptr<simaai::neat::Node> Preproc(PreprocOptions opt = {});
255} // namespace simaai::neat::nodes

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.