载入中...
搜索中...
未找到
OnnxExecute.cpp
浏览该文件的文档.
1#include <algorithm>
2#include <array>
3#include <cmath>
4#include <limits>
5#include <numeric>
6#include <set>
7#include <sstream>
9#include "tensor/CpuKernels.h"
11#include "tensor/OnnxInternal.h"
12#include "tensor/Tensor.h"
13
14// OnnxExecute.cpp
16bool isSupported(const Node& n) {
17 if (n.domain == "com.microsoft" && n.op == "DynamicQuantizeLSTM") {
18 if (n.inputs.size() != 12 || n.outputs.empty() || n.outputs.size() > 3) return false;
19 for (const auto& [key, a] : n.attrs) {
20 if (key == "direction") {
21 if (a.type != 3 || (a.text != "forward" && a.text != "reverse" && a.text != "bidirectional"))
22 return false;
23 } else if (key == "hidden_size" || key == "input_forget") {
24 if (a.type != 2) return false;
25 } else if (key == "clip") {
26 if (a.type != 1) return false;
27 } else
28 return false;
29 }
30 return true;
31 }
32 if (!n.domain.empty()) return false;
33 if (n.op == "If" || n.op == "Loop") {
34 const std::set<std::string> keys =
35 n.op == "If" ? std::set<std::string>{"then_branch", "else_branch"} : std::set<std::string>{"body"};
36 if (n.attrs.size() != keys.size() || n.outputs.empty() ||
37 (n.op == "If" ? n.inputs.size() != 1 : n.inputs.size() < 2))
38 return false;
39 for (const auto& key : keys) {
40 auto it = n.attrs.find(key);
41 if (it == n.attrs.end() || it->second.type != 5 || !it->second.graph) return false;
42 }
43 return true;
44 }
45
46 static const std::map<std::string, std::set<std::string>> allowed{
47 {"DynamicQuantizeLinear", {}},
48 {"QuantizeLinear", {"axis"}},
49 {"DequantizeLinear", {"axis"}},
50 {"MatMulInteger", {}},
51 {"ConvInteger", {"auto_pad", "dilations", "group", "kernel_shape", "pads", "strides"}},
52 {"Constant", {"value"}},
53 {"Clip", {}},
54 {"Pad", {"mode"}},
55 {"CumSum", {"exclusive", "reverse"}},
56 {"SequenceEmpty", {"dtype"}},
57 {"SequenceAt", {}},
58 {"SequenceInsert", {}},
59 {"SplitToSequence", {"axis", "keepdims"}},
60 {"ConcatFromSequence", {"axis", "new_axis"}},
61 {"RandomUniformLike", {"dtype", "seed", "low", "high"}},
62 {"RandomNormalLike", {"dtype", "seed", "mean", "scale"}},
63 {"InstanceNormalization", {"epsilon"}},
64 {"ConvTranspose", {"auto_pad", "dilations", "group", "kernel_shape", "output_padding", "pads", "strides"}},
65 {"Resize", {"coordinate_transformation_mode", "mode", "nearest_mode", "cubic_coeff_a"}},
66 {"Range", {}},
67 {"TopK", {"axis", "largest", "sorted"}},
68 {"ScatterND", {"reduction"}},
69 {"ScatterElements", {"axis", "reduction"}},
70 {"ReduceProd", {"axes", "keepdims"}},
71 {"ReduceMax", {"axes", "keepdims"}},
72 {"Slice", {}},
73 {"Concat", {"axis"}},
74 {"Expand", {}},
75 {"ConstantOfShape", {"value"}},
76 {"Where", {}},
77 {"Equal", {}},
78 {"Less", {}},
79 {"Greater", {}},
80 {"And", {}},
81 {"Not", {}},
82 {"Reciprocal", {}},
83 {"LeakyRelu", {"alpha"}},
84 {"Floor", {}},
85 {"Round", {}},
86 {"Atan", {}},
87 {"Identity", {}},
88 {"Cast", {"to"}},
89 {"Gather", {"axis"}},
90 {"Shape", {"start", "end"}},
91 {"Reshape", {"allowzero"}},
92 {"Transpose", {"perm"}},
93 {"Unsqueeze", {}},
94 {"Squeeze", {}},
95 {"MatMul", {}},
96 {"Add", {}},
97 {"Sub", {}},
98 {"Mul", {}},
99 {"Div", {}},
100 {"Sqrt", {}},
101 {"Exp", {}},
102 {"Log", {}},
103 {"Sin", {}},
104 {"Cos", {}},
105 {"Relu", {}},
106 {"Sigmoid", {}},
107 {"Tanh", {}},
108 {"Neg", {}},
109 {"Abs", {}},
110 {"Pow", {}},
111 {"Softmax", {"axis"}},
112 {"ReduceMean", {"axes", "keepdims"}},
113 {"ReduceSum", {"keepdims", "noop_with_empty_axes"}}};
114 auto op = allowed.find(n.op);
115 if (op == allowed.end()) return false;
116 size_t minimum = 1, maximum = 1, outputs = 1;
117 if (n.op == "Clip") maximum = 3;
118 if (n.op == "Pad") {
119 minimum = 2;
120 maximum = 3;
121 }
122 if (n.op == "CumSum") minimum = maximum = 2;
123 if (n.op == "SequenceEmpty") minimum = maximum = 0;
124 if (n.op == "SequenceAt") minimum = maximum = 2;
125 if (n.op == "SequenceInsert") {
126 minimum = 2;
127 maximum = 3;
128 }
129 if (n.op == "SplitToSequence") maximum = 2;
130 if (n.op == "InstanceNormalization") minimum = maximum = 3;
131 if (n.op == "ConvTranspose") {
132 minimum = 2;
133 maximum = 3;
134 }
135 if (n.op == "Resize") {
136 minimum = 3;
137 maximum = 4;
138 }
139 if (n.op == "Range" || n.op == "ScatterElements" || n.op == "ScatterND") minimum = maximum = 3;
140 if (n.op == "TopK") {
141 minimum = maximum = 2;
142 outputs = 2;
143 }
144 if (n.op == "Slice") {
145 minimum = 3;
146 maximum = 5;
147 }
148 if (n.op == "Concat") maximum = 100000;
149 if (n.op == "Where") minimum = maximum = 3;
150 if (n.op == "Expand" || n.op == "Equal" || n.op == "Less" || n.op == "Greater" || n.op == "And")
151 minimum = maximum = 2;
152 if (n.op == "Constant") minimum = maximum = 0;
153 if (n.op == "DynamicQuantizeLinear") outputs = 3;
154 if (n.op == "QuantizeLinear" || n.op == "DequantizeLinear") {
155 minimum = 2;
156 maximum = 3;
157 }
158 if (n.op == "MatMulInteger" || n.op == "ConvInteger") {
159 minimum = 2;
160 maximum = 4;
161 }
162 if (n.op == "Gather" || n.op == "Reshape" || n.op == "Unsqueeze" || n.op == "MatMul" || n.op == "Add" ||
163 n.op == "Sub" || n.op == "Mul" || n.op == "Div" || n.op == "Pow")
164 minimum = maximum = 2;
165 if (n.op == "Squeeze" || n.op == "ReduceSum") maximum = 2;
166 if (n.inputs.size() < minimum || n.inputs.size() > maximum || n.outputs.size() != outputs) return false;
167 for (const auto& [key, a] : n.attrs) {
168 if (!op->second.contains(key)) return false;
169 const int expected = (key == "alpha" || key == "epsilon" || key == "cubic_coeff_a" || key == "seed" ||
170 key == "low" || key == "high" || key == "mean" || key == "scale")
171 ? 1
172 : key == "value" ? 4
173 : (key == "auto_pad" || key == "reduction" || key == "coordinate_transformation_mode" ||
174 key == "mode" || key == "nearest_mode")
175 ? 3
176 : (key == "perm" || key == "axes" || key == "dilations" || key == "kernel_shape" ||
177 key == "pads" || key == "strides" || key == "output_padding")
178 ? 7
179 : 2;
180 if (a.type != expected) return false;
181 if (key == "reduction" && a.text != "none") return false;
182 if (key == "auto_pad" && a.text != "NOTSET") return false;
183 if (key == "allowzero" && a.integer != 0) return false;
184 }
185 if (n.op == "Pad" && n.attrs.contains("mode") && n.attrs.at("mode").text != "constant" &&
186 n.attrs.at("mode").text != "edge" && n.attrs.at("mode").text != "reflect")
187 return false;
188 if (n.op == "Resize") {
189 const auto mode = n.attrs.contains("mode") ? n.attrs.at("mode").text : "nearest";
190 const auto coordinate = n.attrs.contains("coordinate_transformation_mode")
191 ? n.attrs.at("coordinate_transformation_mode").text
192 : "half_pixel";
193 const auto nearest = n.attrs.contains("nearest_mode") ? n.attrs.at("nearest_mode").text : "round_prefer_floor";
194 if (mode == "nearest") {
195 if (coordinate != "asymmetric" || nearest != "floor") return false;
196 } else if (mode != "linear" || (coordinate != "half_pixel" && coordinate != "asymmetric"))
197 return false;
198 }
199 return true;
200}
201namespace {
202std::vector<int> dims(const RuntimeTensor& x) {
203 std::vector<int> out;
204 for (auto d : x.shape) {
205 if (d <= 0) throw Failure("Empty float kernel input", DiagnosticCode::Unsupported);
206 out.push_back(static_cast<int>(d));
207 }
208 return out;
209}
210} // namespace
211std::vector<RuntimeTensor> execute(const Node& n, const std::vector<const RuntimeTensor*>& in, OnnxCompute* compute) {
212 if (n.domain == "com.microsoft" && n.op == "DynamicQuantizeLSTM") return executeQuantLstm(n, in, compute);
213 if (n.op == "Constant") {
214 auto a = n.attrs.find("value");
215 if (a == n.attrs.end() || !a->second.tensor) throw Failure("Constant requires tensor value");
216 return single(*a->second.tensor);
217 }
218 if (n.op.find("Quantize") != std::string::npos || n.op == "DequantizeLinear" || n.op == "MatMulInteger" ||
219 n.op == "ConvInteger")
220 return executeQuant(n, in, compute);
221 const auto& x = required(in, 0);
222 if (n.op == "Identity") return single(x);
223 if (n.op == "Shape") {
224 const int64_t rank = x.shape.size();
225 auto norm = [rank](int64_t i) { return std::clamp(i < 0 ? i + rank : i, int64_t(0), rank); };
226 const auto begin = norm(attr(n, "start", 0)), end = norm(attr(n, "end", rank));
227 std::vector<int64_t> shape;
228 if (begin < end) shape.assign(x.shape.begin() + begin, x.shape.begin() + end);
229 return single(make(OnnxElement::Int64, {static_cast<int64_t>(shape.size())}, shape));
230 }
231 if (n.op == "Cast") {
232 const auto target = static_cast<OnnxElement>(attr(n, "to", 0));
234 return single(dispatchFloat(*compute, {&x}, x.shape, "y[i]=float(x0[i]);"));
235 const auto size = elementSize(target);
236 RuntimeTensor out{target, x.shape, std::vector<uint8_t>(count(x.shape) * size)};
237 for (size_t i = 0; i < count(x.shape); ++i) {
239 const float v =
240 x.element == OnnxElement::Float32 ? read<float>(x, i) : static_cast<float>(integer(x, i));
241 std::memcpy(out.bytes.data() + i * 4, &v, 4);
242 } else {
243 int64_t v;
244 if (x.element == OnnxElement::Float32) {
245 const double f = read<float>(x, i);
246 if (!std::isfinite(f) || f < -9223372036854775808.0 || f >= 9223372036854775808.0)
247 throw Failure("Cast overflow");
248 v = target == OnnxElement::Bool ? (f != 0) : static_cast<int64_t>(f);
249 } else
250 v = integer(x, i);
251 if (target == OnnxElement::Bool) v = v != 0;
252 std::memcpy(out.bytes.data() + i * size, &v, size);
253 }
254 }
255 return single(std::move(out));
256 }
257 if (n.op == "Gather") {
258 const auto& idx = required(in, 1);
259 const int a = axis(attr(n, "axis", 0), x.shape.size());
260 if (idx.element != OnnxElement::Int32 && idx.element != OnnxElement::Int64)
261 throw Failure("Gather indices must be int32/int64");
262 size_t inner = 1, outer = 1;
263 for (size_t i = a + 1; i < x.shape.size(); ++i) inner *= x.shape[i];
264 for (int i = 0; i < a; ++i) outer *= x.shape[i];
265 std::vector<int64_t> shape(x.shape.begin(), x.shape.begin() + a);
266 shape.insert(shape.end(), idx.shape.begin(), idx.shape.end());
267 shape.insert(shape.end(), x.shape.begin() + a + 1, x.shape.end());
268 const size_t stride = inner * elementSize(x.element), ni = count(idx.shape);
269 RuntimeTensor out{x.element, shape, std::vector<uint8_t>(count(shape) * elementSize(x.element))};
270 for (size_t o = 0; o < outer; ++o)
271 for (size_t i = 0; i < ni; ++i) {
272 auto j = integer(idx, i);
273 if (j < 0) j += x.shape[a];
274 if (j < 0 || j >= x.shape[a]) throw Failure("Gather index out of range");
275 if (stride)
276 std::memcpy(out.bytes.data() + (o * ni + i) * stride,
277 x.bytes.data() + (o * x.shape[a] + j) * stride, stride);
278 }
279 return single(std::move(out));
280 }
281 if (n.op == "Reshape" || n.op == "Unsqueeze" || n.op == "Squeeze") {
282 auto shape = x.shape;
283 if (n.op == "Reshape") {
284 shape = ints(required(in, 1));
285 int infer = -1;
286 size_t known = 1;
287 for (size_t i = 0; i < shape.size(); ++i) {
288 if (shape[i] == 0) {
289 if (i >= x.shape.size()) throw Failure("Reshape zero axis out of range");
290 shape[i] = x.shape[i];
291 }
292 if (shape[i] == -1) {
293 if (infer != -1) throw Failure("Multiple inferred dimensions");
294 infer = static_cast<int>(i);
295 } else {
296 if (shape[i] < 0 || shape[i] > INT32_MAX ||
297 (shape[i] && known > 128u * 1024u * 1024u / static_cast<size_t>(shape[i])))
298 throw Failure("Reshape overflow");
299 known *= static_cast<size_t>(shape[i]);
300 }
301 }
302 if (infer >= 0) {
303 if (!known || count(x.shape) % known) throw Failure("Invalid inferred shape");
304 shape[infer] = count(x.shape) / known;
305 }
306 } else {
307 std::vector<int64_t> axes;
308 if (in.size() > 1 && in[1])
309 axes = ints(*in[1]);
310 else if (n.op == "Unsqueeze")
311 throw Failure("Unsqueeze needs axes");
312 else
313 for (size_t i = 0; i < shape.size(); ++i)
314 if (shape[i] == 1) axes.push_back(i);
315 const size_t rank = shape.size() + (n.op == "Unsqueeze" ? axes.size() : 0);
316 std::set<int> positions;
317 for (auto a : axes)
318 if (!positions.insert(axis(a, rank)).second) throw Failure("Duplicate squeeze axis");
319 if (n.op == "Unsqueeze") {
320 for (int a : positions) shape.insert(shape.begin() + a, 1);
321 } else
322 for (auto it = positions.rbegin(); it != positions.rend(); ++it) {
323 if (shape[*it] != 1) throw Failure("Squeeze dimension not one");
324 shape.erase(shape.begin() + *it);
325 }
326 }
327 if (count(shape) != count(x.shape)) throw Failure("Reshape element count mismatch");
329 out.shape = std::move(shape);
330 return single(std::move(out));
331 }
332 if (n.op == "Transpose") {
333 std::vector<int64_t> order = attrs(n, "perm", {});
334 if (order.empty())
335 for (size_t i = x.shape.size(); i > 0; --i) order.push_back(i - 1);
336 if (order.size() != x.shape.size()) throw Failure("Invalid transpose rank");
337 std::set<int64_t> used;
338 std::vector<int64_t> shape;
339 for (auto a : order) {
340 if (a < 0 || a >= static_cast<int64_t>(x.shape.size()) || !used.insert(a).second)
341 throw Failure("Invalid transpose permutation");
342 shape.push_back(x.shape[a]);
343 }
344 RuntimeTensor out{x.element, shape, std::vector<uint8_t>(x.bytes.size())};
345 const auto size = elementSize(x.element);
346 std::vector<size_t> strides(x.shape.size(), 1);
347 for (size_t i = x.shape.size(); i > 1; --i) strides[i - 2] = strides[i - 1] * x.shape[i - 1];
348 for (size_t i = 0; i < count(shape); ++i) {
349 size_t rest = i, source = 0;
350 for (size_t j = shape.size(); j > 0; --j) {
351 source += (rest % shape[j - 1]) * strides[order[j - 1]];
352 rest /= shape[j - 1];
353 }
354 std::memcpy(out.bytes.data() + i * size, x.bytes.data() + source * size, size);
355 }
356 return single(std::move(out));
357 }
358 if (auto indexResult = executeIndex(n, in)) return std::move(*indexResult);
359 if (auto shapeResult = executeShape(n, in)) return single(std::move(*shapeResult));
360 if (auto miscResult = executeMisc(n, in, compute)) return single(std::move(*miscResult));
361 if (auto neuralResult = executeNeural(n, in, compute)) return single(std::move(*neuralResult));
362 if (auto numericResult = executeNumeric(n, in, compute)) return single(std::move(*numericResult));
363 const auto a = floats(x);
364 if (n.op == "Softmax") {
365 auto xd = dims(x);
366 std::vector<float> out(a.size());
367 kernels::softmax(a.data(), xd.data(), static_cast<int>(xd.size()), axis(attr(n, "axis", -1), xd.size()), false,
368 out.data());
369 return single(make(OnnxElement::Float32, x.shape, out));
370 }
371 static const std::map<std::string, OpType> unary{
372 {"Sqrt", OpType::Sqrt}, {"Exp", OpType::Exp}, {"Log", OpType::Log}, {"Sin", OpType::Sin},
373 {"Cos", OpType::Cos}, {"Relu", OpType::Relu}, {"Sigmoid", OpType::Sigmoid}, {"Tanh", OpType::Tanh},
374 {"Neg", OpType::Neg}, {"Abs", OpType::Abs}};
375 auto op = unary.find(n.op);
376 if (op == unary.end()) throw Failure("Unsupported operator", DiagnosticCode::Unsupported);
377 std::vector<float> out(a.size());
378 kernels::unaryOp(op->second, a.data(), static_cast<int>(a.size()), out.data(), 0, 0);
379 return single(make(OnnxElement::Float32, x.shape, out));
380}
381} // namespace eve::tensor::onnx_detail
382
383// OnnxGpuKernels.cpp
384namespace eve::tensor::onnx_detail {
385namespace {
386std::string prefix(bool as, bool bs) {
387 std::ostringstream s;
388 s << "#version 450\nlayout(local_size_x=64) in;\n"
389 "layout(std430,binding=0) readonly buffer A {uint a[];};\n"
390 "layout(std430,binding=1) readonly buffer B {uint b[];};\n"
391 "layout(std430,binding=2) readonly buffer Z {int zp[];};\n"
392 "layout(std430,binding=3) writeonly buffer Y {int y[];};\n"
393 "int av(uint i){int v=int((a[i/4]>>((i%4)*8))&255u);return "
394 << (as ? "v>=128?v-256:v" : "v")
395 << ";}\n"
396 "int bv(uint i){int v=int((b[i/4]>>((i%4)*8))&255u);return "
397 << (bs ? "v>=128?v-256:v" : "v") << ";}\n";
398 return s.str();
399}
400// Compatibility host-byte calls use the same resident kernel generators. The
401// adapter below requests completion through the provider's synchronous contract.
402class Synchronous final : public OnnxCompute {
403 OnnxCompute& target;
404
405public:
406 explicit Synchronous(OnnxCompute& t) : target(t) {}
407 Result<std::vector<uint8_t>> dispatch(const OnnxKernel& k) override { return target.dispatch(k); }
408};
409OnnxBuffer hostBuffer(std::span<const uint8_t> bytes) {
410 auto p = std::make_shared<const std::vector<uint8_t>>(bytes.begin(), bytes.end());
411 return {p, {}, p->size()};
412}
413std::vector<int32_t> integerOutput(const OnnxBuffer& result) {
414 if (!result.host || result.host->size() % 4) throw Failure("Invalid synchronous integer output");
415 std::vector<int32_t> out(result.host->size() / 4);
416 std::memcpy(out.data(), result.host->data(), result.host->size());
417 return out;
418}
419} // namespace
420std::vector<int32_t> gpuMatmul(OnnxCompute& d, affine::ByteView a, affine::ByteView b, size_t m, size_t k, size_t n,
421 int az, std::span<const int32_t> bz) {
422 Synchronous sync(d);
423 return integerOutput(gpuMatmulResident(sync, hostBuffer(a.bytes), hostBuffer(b.bytes), a.signedValues,
424 b.signedValues, m, k, n, az, bz));
425}
427 std::span<const int32_t> wz) {
428 Synchronous sync(d);
429 return integerOutput(
430 gpuConvResident(sync, hostBuffer(x.bytes), hostBuffer(w.bytes), x.signedValues, w.signedValues, c, xz, wz));
431}
433 std::span<const int32_t> z, size_t size, size_t terms) {
434 if (terms > INT32_MAX / 65025 || !size || size > 64u * 65535u)
435 throw Failure("GPU integer kernel exceeds exact accumulator or dispatch limit", DiagnosticCode::Unsupported);
436 std::vector<uint8_t> bytes(z.size_bytes());
437 std::memcpy(bytes.data(), z.data(), bytes.size());
438 auto host = std::make_shared<const std::vector<uint8_t>>(std::move(bytes));
439 const std::array<OnnxBuffer, 3> inputs{{std::move(a), std::move(b), {host, {}, host->size()}}};
440 auto r = d.enqueue(source, inputs, size * 4, static_cast<uint32_t>(size));
441 if (!r.ok()) throw Failure(r.error()->message(), r.error()->code());
442 return std::move(r.value());
443}
444OnnxBuffer gpuMatmulResident(OnnxCompute& d, OnnxBuffer a, OnnxBuffer b, bool as, bool bs, size_t m, size_t k, size_t n,
445 int az, std::span<const int32_t> bz, size_t bOffset) {
446 if (bz.size() != 1 && bz.size() != n) throw Failure("GPU matmul zero-point extent mismatch");
447 std::ostringstream s;
448 s << prefix(as, bs) << "void main(){uint i=gl_GlobalInvocationID.x;if(i>=" << m * n << "u)return;"
449 << "uint r=i/" << n << "u,c=i%" << n << "u;int v=0;for(uint j=0;j<" << k << "u;++j)"
450 << "v+=(av(r*" << k << "u+j)-(" << az << "))*(bv(" << bOffset << "u+j*" << n << "u+c)-zp["
451 << (bz.size() == 1 ? "0" : "c") << "]);y[i]=v;}";
452 return enqueueInteger(d, s.str(), std::move(a), std::move(b), bz, m * n, k);
453}
454
456 int xz, std::span<const int32_t> wz) {
457 const int64_t oh =
458 (int64_t(c.height) + c.padTop + c.padBottom - int64_t(c.dilationH) * (c.kernelH - 1) - 1) / c.strideH + 1;
459 const int64_t ow =
460 (int64_t(c.width) + c.padLeft + c.padRight - int64_t(c.dilationW) * (c.kernelW - 1) - 1) / c.strideW + 1;
461 if ((oh - 1) * c.strideH > INT32_MAX || (ow - 1) * c.strideW > INT32_MAX ||
462 (oh - 1) * c.strideH - c.padTop + int64_t(c.kernelH - 1) * c.dilationH > INT32_MAX ||
463 (ow - 1) * c.strideW - c.padLeft + int64_t(c.kernelW - 1) * c.dilationW > INT32_MAX)
464 throw Failure("GPU convolution coordinate overflow", DiagnosticCode::Unsupported);
465 const size_t size = size_t(c.batch) * c.outputs * oh * ow;
466 const int cg = c.channels / c.groups;
467 std::ostringstream s;
468 s << prefix(xs, ws) << "void main(){uint i=gl_GlobalInvocationID.x;if(i>=" << size << "u)return;"
469 << "int xx=int(i%" << ow << "u),yy=int(i/" << ow << "u%" << oh << "u),o=int(i/" << ow * oh << "u%" << c.outputs
470 << "u),batch=int(i/" << ow * oh * c.outputs << "u);int v=0;"
471 << "for(int ch=0;ch<" << cg << ";++ch)for(int ky=0;ky<" << c.kernelH << ";++ky)for(int kx=0;kx<" << c.kernelW
472 << ";++kx){"
473 << "int iy=yy*" << c.strideH << "-" << c.padTop << "+ky*" << c.dilationH << ",ix=xx*" << c.strideW << "-"
474 << c.padLeft << "+kx*" << c.dilationW << ";"
475 << "if(iy<0||ix<0||iy>=" << c.height << "||ix>=" << c.width << ")continue;"
476 << "uint ai=uint(((batch*" << c.channels << "+o/" << c.outputs / c.groups << "*" << cg << "+ch)*" << c.height
477 << "+iy)*" << c.width << "+ix);"
478 << "uint bi=uint(((o*" << cg << "+ch)*" << c.kernelH << "+ky)*" << c.kernelW << "+kx);"
479 << "v+=(av(ai)-(" << xz << "))*(bv(bi)-zp[" << (wz.size() == 1 ? "0" : "o") << "]);}y[i]=v;}";
480 return enqueueInteger(d, s.str(), std::move(x), std::move(w), wz, size, size_t(cg) * c.kernelH * c.kernelW);
481}
482} // namespace eve::tensor::onnx_detail
483
484// OnnxIndexOps.cpp
485namespace eve::tensor::onnx_detail {
486std::optional<std::vector<RuntimeTensor>> executeIndex(const Node& n, const std::vector<const RuntimeTensor*>& in) {
487 const auto& x = required(in, 0);
488 auto one = [](RuntimeTensor t) { return single(std::move(t)); };
489 if (n.op == "Range") {
490 const auto& end = required(in, 1);
491 const auto& delta = required(in, 2);
492 if (count(x.shape) != 1 || count(end.shape) != 1 || count(delta.shape) != 1 || x.element != end.element ||
493 x.element != delta.element)
494 throw Failure("Range requires matching scalars");
495 if (x.element == OnnxElement::Float32) {
496 const double start = read<float>(x, 0), stop = read<float>(end, 0), step = read<float>(delta, 0);
497 if (!std::isfinite(start) || !std::isfinite(stop) || !std::isfinite(step) || step == 0)
498 throw Failure("Invalid Range");
499 const double length = std::max(0., std::ceil((stop - start) / step));
500 if (length > 128u * 1024u * 1024u) throw Failure("Range too large");
501 std::vector<float> v(static_cast<size_t>(length));
502 for (size_t i = 0; i < v.size(); ++i) v[i] = static_cast<float>(start + i * step);
503 return one(make(x.element, {static_cast<int64_t>(v.size())}, v));
504 }
505 if (x.element != OnnxElement::Int64 && x.element != OnnxElement::Int32)
506 throw Failure("Range integer dtype unsupported");
507 const int64_t start = integer(x), stop = integer(end), step = integer(delta);
508 if (!step || step == INT64_MIN) throw Failure("Invalid Range step");
509 uint64_t length = 0;
510 if (step > 0 && stop > start) length = 1 + (uint64_t(stop) - uint64_t(start) - 1) / uint64_t(step);
511 if (step < 0 && stop < start) length = 1 + (uint64_t(start) - uint64_t(stop) - 1) / uint64_t(-step);
512 if (length > 128u * 1024u * 1024u) throw Failure("Range too large");
514 x.element, {static_cast<int64_t>(length)}, std::vector<uint8_t>(length * elementSize(x.element))};
515 int64_t v = start;
516 for (size_t i = 0; i < length; ++i) {
517 std::memcpy(out.bytes.data() + i * elementSize(x.element), &v, elementSize(x.element));
518 if (i + 1 < length) v += step;
519 }
520 return one(std::move(out));
521 }
522 if (n.op == "TopK") {
523 const auto& kt = required(in, 1);
524 if (count(kt.shape) != 1) throw Failure("TopK requires one K");
525 int a = axis(attr(n, "axis", -1), x.shape.size());
526 const int64_t k = integer(kt), size = x.shape[a];
527 if (k < 0 || k > size) throw Failure("Invalid TopK K");
528 size_t outer = 1, inner = 1;
529 for (int j = 0; j < a; ++j) outer *= x.shape[j];
530 for (size_t j = a + 1; j < x.shape.size(); ++j) inner *= x.shape[j];
531 auto shape = x.shape;
532 shape[a] = k;
533 RuntimeTensor values{x.element, shape, std::vector<uint8_t>(count(shape) * elementSize(x.element))};
534 std::vector<int64_t> indices(count(shape));
535 for (size_t o = 0; o < outer; ++o)
536 for (size_t i = 0; i < inner; ++i) {
537 std::vector<int64_t> order(size);
538 std::iota(order.begin(), order.end(), 0);
539 std::stable_sort(order.begin(), order.end(), [&](int64_t aa, int64_t bb) {
540 auto compare = [&](auto u, auto v) { return attr(n, "largest", 1) ? u > v : u < v; };
541 const size_t ai = (o * size + aa) * inner + i, bi = (o * size + bb) * inner + i;
542 return x.element == OnnxElement::Float32 ? compare(read<float>(x, ai), read<float>(x, bi))
543 : compare(integer(x, ai), integer(x, bi));
544 });
545 for (int64_t j = 0; j < k; ++j) {
546 size_t dst = (o * k + j) * inner + i, src = (o * size + order[j]) * inner + i;
547 indices[dst] = order[j];
548 std::memcpy(values.bytes.data() + dst * elementSize(x.element),
549 x.bytes.data() + src * elementSize(x.element), elementSize(x.element));
550 }
551 }
552 std::vector<RuntimeTensor> outputs;
553 outputs.reserve(2);
554 outputs.emplace_back(std::move(values));
555 outputs.emplace_back(make(OnnxElement::Int64, shape, indices));
556 return outputs;
557 }
558 if (n.op == "ScatterElements" || n.op == "ScatterND") {
559 const auto& idx = required(in, 1);
560 const auto& updates = required(in, 2);
561 if (updates.element != x.element || (idx.element != OnnxElement::Int64 && idx.element != OnnxElement::Int32))
562 throw Failure("Scatter dtype mismatch");
563 auto out = x;
564 const auto bytes = elementSize(x.element);
565 if (n.op == "ScatterElements") {
566 if (idx.shape != updates.shape || idx.shape.size() != x.shape.size())
567 throw Failure("ScatterElements shape mismatch");
568 int a = axis(attr(n, "axis", 0), x.shape.size());
569 for (size_t j = 0; j < x.shape.size(); ++j)
570 if (j != a && idx.shape[j] > x.shape[j]) throw Failure("Scatter index shape exceeds data");
571 for (size_t i = 0; i < count(idx.shape); ++i) {
572 size_t rest = i, source = 0, stride = 1;
573 for (size_t j = x.shape.size(); j > 0; --j) {
574 int64_t c = rest % idx.shape[j - 1];
575 rest /= idx.shape[j - 1];
576 if (j - 1 == a) {
577 c = integer(idx, i);
578 if (c < 0) c += x.shape[j - 1];
579 }
580 if (c < 0 || c >= x.shape[j - 1]) throw Failure("Scatter index out of range");
581 source += c * stride;
582 stride *= x.shape[j - 1];
583 }
584 std::memcpy(out.bytes.data() + source * bytes, updates.bytes.data() + i * bytes, bytes);
585 }
586 } else {
587 if (idx.shape.empty() || idx.shape.back() < 1 || static_cast<size_t>(idx.shape.back()) > x.shape.size())
588 throw Failure("ScatterND index rank mismatch");
589 const size_t depth = idx.shape.back();
590 std::vector<int64_t> expected(idx.shape.begin(), idx.shape.end() - 1);
591 expected.insert(expected.end(), x.shape.begin() + depth, x.shape.end());
592 if (expected != updates.shape) throw Failure("ScatterND updates shape mismatch");
593 size_t chunk = 1;
594 for (size_t j = depth; j < x.shape.size(); ++j) chunk *= x.shape[j];
595 for (size_t i = 0; i < count(idx.shape) / depth; ++i) {
596 size_t target = 0;
597 for (size_t j = 0; j < depth; ++j) {
598 auto c = integer(idx, i * depth + j);
599 if (c < 0) c += x.shape[j];
600 if (c < 0 || c >= x.shape[j]) throw Failure("ScatterND index out of range");
601 target = target * x.shape[j] + c;
602 }
603 if (chunk)
604 std::memcpy(out.bytes.data() + target * chunk * bytes, updates.bytes.data() + i * chunk * bytes,
605 chunk * bytes);
606 }
607 }
608 return one(std::move(out));
609 }
610 if (n.op == "ReduceProd" || n.op == "ReduceMax") {
611 auto axes = attrs(n, "axes", {});
612 if (axes.empty())
613 for (size_t i = 0; i < x.shape.size(); ++i) axes.push_back(i);
614 std::set<int> reduced;
615 for (auto a : axes)
616 if (!reduced.insert(axis(a, x.shape.size())).second) throw Failure("Duplicate reduction axis");
617 auto mapShape = x.shape;
618 std::vector<int64_t> shape;
619 for (size_t j = 0; j < x.shape.size(); ++j) {
620 if (reduced.contains(static_cast<int>(j))) {
621 mapShape[j] = 1;
622 if (attr(n, "keepdims", 1)) shape.push_back(1);
623 } else
624 shape.push_back(x.shape[j]);
625 }
626 if (x.element == OnnxElement::Float32) {
627 std::vector<float> out(count(shape), n.op == "ReduceProd" ? 1.f : -std::numeric_limits<float>::infinity());
628 for (size_t i = 0; i < count(x.shape); ++i) {
629 size_t t = broadcastIndex(i, mapShape, x.shape);
630 const float v = read<float>(x, i);
631 out[t] = n.op == "ReduceProd" ? out[t] * v : std::max(out[t], v);
632 }
633 return one(make(x.element, shape, out));
634 }
635 if (x.element != OnnxElement::Int64 && x.element != OnnxElement::Int32)
636 throw Failure("Integer reduction dtype unsupported");
637 std::vector<int64_t> out(count(shape), n.op == "ReduceProd" ? 1 : INT64_MIN);
638 for (size_t i = 0; i < count(x.shape); ++i) {
639 auto& a = out[broadcastIndex(i, mapShape, x.shape)];
640 const auto b = integer(x, i);
641 if (n.op == "ReduceMax")
642 a = std::max(a, b);
643 else {
644 if (a && b &&
645 (a > 0 ? (b > 0 ? a > INT64_MAX / b : b < INT64_MIN / a)
646 : (b > 0 ? a < INT64_MIN / b : a < INT64_MAX / b)))
647 throw Failure("ReduceProd overflow");
648 a *= b;
649 }
650 }
651 if (x.element == OnnxElement::Int64) return one(make(x.element, shape, out));
652 std::vector<int32_t> narrow;
653 for (auto v : out) {
654 if (v < INT32_MIN || v > INT32_MAX) throw Failure("Int32 reduction overflow");
655 narrow.push_back(static_cast<int32_t>(v));
656 }
657 return one(make(x.element, shape, narrow));
658 }
659 return std::nullopt;
660}
661} // namespace eve::tensor::onnx_detail
662
663// OnnxLstm.cpp
664namespace eve::tensor::onnx_detail {
665namespace {
666template <class T>
667T checked(Result<T> r) {
668 if (!r.ok()) throw Failure(r.error()->message(), r.error()->code());
669 return std::move(r.value());
670}
671void shape(const RuntimeTensor& t, const std::vector<int64_t>& expected) {
672 if (t.shape != expected) throw Failure("LSTM input shape mismatch");
673}
674std::vector<float> optionalFloats(const std::vector<const RuntimeTensor*>& in, size_t i,
675 const std::vector<int64_t>& dims) {
676 if (i >= in.size() || !in[i]) return std::vector<float>(count(dims), 0);
677 shape(*in[i], dims);
678 return floats(*in[i]);
679}
680struct Weights {
681 const RuntimeTensor& tensor;
682 std::vector<float> scales;
683 std::vector<int64_t> zeros;
685 Weights(const RuntimeTensor& t, const RuntimeTensor& s, const RuntimeTensor& z, size_t d, size_t g, size_t r)
686 : tensor(t), scales(floats(s)), zeros(ints(z)), directions(d), gates(g), rows(r) {
687 if (t.element != OnnxElement::Int8 && t.element != OnnxElement::UInt8)
688 throw Failure("LSTM weights must be 8-bit");
689 if (t.element != z.element || s.shape != z.shape ||
690 (s.shape != std::vector<int64_t>{static_cast<int64_t>(d)} &&
691 s.shape != std::vector<int64_t>{static_cast<int64_t>(d), static_cast<int64_t>(g)}))
692 throw Failure("LSTM quantization parameter shape mismatch");
693 shape(t, {static_cast<int64_t>(d), static_cast<int64_t>(r), static_cast<int64_t>(g)});
694 for (float v : scales)
695 if (!(v > 0) || !std::isfinite(v)) throw Failure("Invalid LSTM weight scale");
696 }
697 std::vector<float> multiply(const affine::QuantizedActivation& a, size_t batch, size_t direction,
698 OnnxCompute* compute) const {
699 std::vector<float> out(batch * gates);
700 const bool sign = tensor.element == OnnxElement::Int8;
701 if (compute) {
702 std::vector<int32_t> z(scales.size() == directions ? 1 : gates);
703 for (size_t i = 0; i < z.size(); ++i) z[i] = static_cast<int32_t>(zeros[direction * z.size() + i]);
704 ByteStorage activation(a.values);
705 ByteStorage accumulator(gpuMatmulResident(*compute, activation.buffer(), tensor.bytes.buffer(), false, sign,
706 batch, rows, gates, a.zeroPoint, z, direction * rows * gates));
707 std::vector<int32_t> sums(batch * gates);
708 std::memcpy(sums.data(), static_cast<const ByteStorage&>(accumulator).data(),
709 sums.size() * sizeof(int32_t));
710 for (size_t b = 0; b < batch; ++b)
711 for (size_t g = 0; g < gates; ++g)
712 out[b * gates + g] = static_cast<float>(sums[b * gates + g]) * a.scale *
713 scales[direction * z.size() + (z.size() == 1 ? 0 : g)];
714 return out;
715 }
716 // Per-output-channel affine zero points do not require unpacking a weight matrix.
717 for (size_t b = 0; b < batch; ++b)
718 for (size_t g = 0; g < gates; ++g) {
719 const size_t p = scales.size() == directions ? direction : direction * gates + g;
720 int64_t sum = 0;
721 for (size_t k = 0; k < rows; ++k) {
722 const int byte = tensor.bytes[(direction * rows + k) * gates + g];
723 const int w = sign && byte >= 128 ? byte - 256 : byte;
724 sum += static_cast<int64_t>(int(a.values[b * rows + k]) - a.zeroPoint) * (w - zeros[p]);
725 }
726 if (sum < INT32_MIN || sum > INT32_MAX) throw Failure("LSTM integer accumulator overflow");
727 out[b * gates + g] = static_cast<float>(sum) * a.scale * scales[p];
728 }
729 return out;
730 }
731};
732} // namespace
733std::vector<RuntimeTensor> executeQuantLstm(const Node& n, const std::vector<const RuntimeTensor*>& in,
735 const auto& xt = required(in, 0);
736 if (xt.shape.size() != 3) throw Failure("LSTM X must be [time,batch,input]");
737 const auto x = floats(xt);
738 const int64_t time = xt.shape[0], batch = xt.shape[1], input = xt.shape[2], hidden = attr(n, "hidden_size", 0);
739 const auto direction = n.attrs.contains("direction") ? n.attrs.at("direction").text : "forward";
740 const int64_t dirs = direction == "bidirectional" ? 2 : 1;
741 if (time <= 0 || batch <= 0 || input <= 0 || hidden <= 0 || hidden > 16384)
742 throw Failure("Invalid LSTM dimensions");
743 const size_t gates = 4 * hidden;
744 const size_t projectionSize = count({time, batch, static_cast<int64_t>(gates)});
745 if (projectionSize > 128u * 1024u * 1024u) throw Failure("LSTM projection exceeds memory limit");
746 Weights w(required(in, 1), required(in, 8), required(in, 9), dirs, gates, input);
747 Weights r(required(in, 2), required(in, 10), required(in, 11), dirs, gates, hidden);
748 auto biases = optionalFloats(in, 3, {dirs, 8 * hidden});
749 auto h = optionalFloats(in, 5, {dirs, batch, hidden}), c = optionalFloats(in, 6, {dirs, batch, hidden});
750 auto p = optionalFloats(in, 7, {dirs, 3 * hidden});
751 std::vector<int64_t> lengths(batch, time);
752 if (in.size() > 4 && in[4]) {
753 if (in[4]->element != OnnxElement::Int32) throw Failure("LSTM sequence lengths require int32");
754 shape(*in[4], {batch});
755 lengths = ints(*in[4]);
756 }
757 for (auto len : lengths)
758 if (len < 0 || len > time) throw Failure("Invalid LSTM sequence length");
759 const int64_t coupled = attr(n, "input_forget", 0);
760 if (coupled != 0 && coupled != 1) throw Failure("Invalid coupled gate flag");
761 const float clip = n.attrs.contains("clip") ? n.attrs.at("clip").real : std::numeric_limits<float>::max();
762 if (!(clip > 0) || !std::isfinite(clip)) throw Failure("Invalid LSTM clipping threshold");
763 auto sigmoid = [clip](float z) { return 1.f / (1.f + std::exp(-std::clamp(z, -clip, clip))); };
764 auto tanh = [clip](float z) { return std::tanh(std::clamp(z, -clip, clip)); };
765 std::vector<float> y(count({time, dirs, batch, hidden}), 0);
766 const auto qx = checked(affine::dynamicQuantize(x));
767 for (int64_t d = 0; d < dirs; ++d) {
768 const auto projected = w.multiply(qx, time * batch, d, compute);
769 const bool reverse = direction == "reverse" || d == 1;
770 for (int64_t step = 0; step < time; ++step) {
771 const auto qh = checked(affine::dynamicQuantize(std::span(h).subspan(d * batch * hidden, batch * hidden)));
772 const auto recurrent = r.multiply(qh, batch, d, compute);
773 for (int64_t b = 0; b < batch; ++b) {
774 if (step >= lengths[b]) continue;
775 const int64_t t = reverse ? lengths[b] - 1 - step : step;
776 const size_t state = (d * batch + b) * hidden;
777 for (int64_t j = 0; j < hidden; ++j) {
778 auto gate = [&](int g) {
779 const size_t channel = g * hidden + j;
780 return projected[(t * batch + b) * gates + channel] + recurrent[b * gates + channel] +
781 biases[d * 8 * hidden + channel] + biases[d * 8 * hidden + gates + channel];
782 };
783 const float i = sigmoid(gate(0) + p[d * 3 * hidden + j] * c[state + j]);
784 const float f =
785 coupled ? 1 - i : sigmoid(gate(2) + p[d * 3 * hidden + 2 * hidden + j] * c[state + j]);
786 c[state + j] = f * c[state + j] + i * tanh(gate(3));
787 const float o = sigmoid(gate(1) + p[d * 3 * hidden + hidden + j] * c[state + j]);
788 h[state + j] = o * tanh(c[state + j]);
789 y[((t * dirs + d) * batch + b) * hidden + j] = h[state + j];
790 }
791 }
792 }
793 }
794 std::vector<RuntimeTensor> result;
795 result.reserve(3);
796 result.emplace_back(make(OnnxElement::Float32, {time, dirs, batch, hidden}, y));
797 result.emplace_back(make(OnnxElement::Float32, {dirs, batch, hidden}, h));
798 result.emplace_back(make(OnnxElement::Float32, {dirs, batch, hidden}, c));
799 return result;
800}
801} // namespace eve::tensor::onnx_detail
double z
double y
double m[16]
double x
LogicalId target
Duration start
float w
Definition AnimClip.cpp:738
const std::string & s
glm::vec4 p[6]
SQObjectPtr key
Definition ECS.cpp:155
EvpackChunkInput input
Definition Evpack.cpp:170
int rows
float maximum[3]
float minimum[3]
tensor::Graph g
Definition GpuGraph.cpp:7
ShaderImageInput shape
glm::vec4 clip
glm::vec3 n
Definition Grass.cpp:63
int inputs
Definition GridGraph.cpp:23
double r
std::uint32_t aa
std::vector< std::uint32_t > indices
std::vector< float > positions
float v
std::int32_t second
std::int32_t c
int h
float length
JointPoint2D axis
bool required
Poco::JSON::Object::Ptr result
uint64_t used
std::uint64_t bytes
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::vector< std::int32_t > order
ScriptMotionSinkStore< ScriptMotionFloatSink > floats
std::vector< float > scales
size_t directions
const RuntimeTensor & tensor
std::vector< int64_t > zeros
size_t gates
OnnxCompute * compute
int idx
float f
std::set< std::string > values
float d
float t
RoadLaneDirection direction
std::array< std::array< double, 3 >, 3 > axes
ScriptStructure out
std::string_view source
size_t begin
size_t end
std::string element
int count
float step
Definition TreeMesh.cpp:451
float size
Definition TreeMesh.cpp:158
UIHostHandle host
std::uint32_t depth
GPU execution boundary for native ONNX; retains no model and retains compiled resources for the lifet...
Definition OnnxCompute.h:25
Result< ForceVector > checked(ForceVector value)
Definition ForceMath.h:21
Result< QuantizedActivation > dynamicQuantize(std::span< const float > input)
Quantize finite FP32 activations with ONNX DynamicQuantizeLinear semantics.
void softmax(const float *in, const int *dims, int rank, int axis, bool logMode, float *out)
Softmax.
void unaryOp(OpType type, const float *in, int count, float *out, float s0, float s1)
Unary op.
OnnxBuffer gpuConvResident(OnnxCompute &d, OnnxBuffer x, OnnxBuffer w, bool xs, bool ws, const affine::ConvShape &c, int xz, std::span< const int32_t > wz)
Gpu conv resident.
int64_t integer(const RuntimeTensor &v, size_t i=0)
Integer.
std::optional< RuntimeTensor > executeMisc(const Node &, const std::vector< const RuntimeTensor * > &, OnnxCompute *)
Execute misc.
Definition OnnxMisc.cpp:11
std::vector< int64_t > ints(const RuntimeTensor &v)
Ints.
std::vector< int32_t > gpuConv(OnnxCompute &d, affine::ByteView x, affine::ByteView w, const affine::ConvShape &c, int xz, std::span< const int32_t > wz)
Gpu conv.
int64_t attr(const Node &n, const char *key, int64_t fallback)
Attr.
std::optional< RuntimeTensor > executeNumeric(const Node &, const std::vector< const RuntimeTensor * > &, OnnxCompute *)
Execute numeric.
Definition OnnxMisc.cpp:444
size_t broadcastIndex(size_t i, const std::vector< int64_t > &shape, const std::vector< int64_t > &output)
Broadcast index.
std::vector< int64_t > attrs(const Node &n, const char *key, std::vector< int64_t > fallback)
Attrs.
std::vector< RuntimeTensor > executeQuant(const Node &node, const std::vector< const RuntimeTensor * > &inputs, OnnxCompute *compute=nullptr)
Execute quant.
Definition OnnxQuant.cpp:34
std::optional< RuntimeTensor > executeNeural(const Node &, const std::vector< const RuntimeTensor * > &, OnnxCompute *)
Execute neural.
Definition OnnxMisc.cpp:206
RuntimeTensor make(OnnxElement e, std::vector< int64_t > shape, const std::vector< T > &values)
Make.
std::vector< int32_t > gpuMatmul(OnnxCompute &d, affine::ByteView a, affine::ByteView b, size_t m, size_t k, size_t n, int az, std::span< const int32_t > bz)
Gpu matmul.
std::vector< RuntimeTensor > single(RuntimeTensor x)
Transfers one owned runtime tensor into an output list. @cost One small container allocation per outp...
RuntimeTensor dispatchFloat(OnnxCompute &, const std::vector< const RuntimeTensor * > &, const std::vector< int64_t > &, const std::string &, size_t work=0)
Dispatches float.
Definition OnnxMisc.cpp:416
OnnxBuffer gpuMatmulResident(OnnxCompute &d, OnnxBuffer a, OnnxBuffer b, bool as, bool bs, size_t m, size_t k, size_t n, int az, std::span< const int32_t > bz, size_t bOffset)
Gpu matmul resident.
bool isSupported(const Node &n)
True when supported.
size_t elementSize(OnnxElement e)
Element size.
std::vector< RuntimeTensor > executeQuantLstm(const Node &n, const std::vector< const RuntimeTensor * > &in, OnnxCompute *compute)
Execute quant lstm.
std::optional< RuntimeTensor > executeShape(const Node &, const std::vector< const RuntimeTensor * > &)
Execute shape.
std::vector< RuntimeTensor > execute(const Node &n, const std::vector< const RuntimeTensor * > &in, OnnxCompute *compute)
Execute.
std::optional< std::vector< RuntimeTensor > > executeIndex(const Node &n, const std::vector< const RuntimeTensor * > &in)
Execute index.
OnnxBuffer enqueueInteger(OnnxCompute &d, const std::string &source, OnnxBuffer a, OnnxBuffer b, std::span< const int32_t > z, size_t size, size_t terms)
OnnxElement
ONNX wire element types; distinct from block-quantized Tensor storage.
Definition OnnxModel.h:18
Immutable buffer shared by graph aliases; exactly one storage is authoritative.
Definition OnnxStorage.h:19
Borrowed packed 8-bit values, valid for the duration of a synchronous call.
Definition AffineQuant.h:24
Explicit 1D/2D NCHW convolution geometry; missing 1D height is one.
Definition AffineQuant.h:65