rustnn C and C++ API
WebNN graph construction and execution
Loading...
Searching...
No Matches
rustnn.hpp
Go to the documentation of this file.
1#pragma once
2
9
10#include <rustnn/rustnn.h>
11
12#include <cstddef>
13#include <cstdint>
14#include <optional>
15#include <stdexcept>
16#include <string>
17#include <type_traits>
18#include <utility>
19#include <vector>
20
21namespace rustnn {
22
25
27class Error : public std::runtime_error {
28public:
29 explicit Error(const std::string &message) : std::runtime_error(message) {}
30};
31
33inline void check(RustnnStatus status) {
34 if (status != RustnnStatus_Success) {
35 const char *message = rustnn_last_error_message();
36 throw Error(message != nullptr ? message : "unknown rustnn error");
37 }
38}
39
55
62
72
79
86
89 bool engine_caching = true;
90 bool runtime_cache = true;
91 bool fail_on_cache_miss = false;
92 bool cuda_graphs = true;
93};
94
99
108
111 std::string label;
112};
113
116public:
117 MLOperandDescriptor(MLOperandDataType data_type, const std::vector<std::uint64_t> &shape) {
119 static_cast<RustnnDataType>(data_type), shape.data(), shape.size(), &value_));
120 }
121
125
127 : value_(std::exchange(other.value_, nullptr)) {}
128
130 if (this != &other) {
132 value_ = std::exchange(other.value_, nullptr);
133 }
134 return *this;
135 }
136
137private:
138 friend class MLGraphBuilder;
139 RustnnOperandDescriptor *value_ = nullptr;
140};
141
144public:
145 MLTensorDescriptor(MLOperandDataType data_type, const std::vector<std::uint64_t> &shape,
146 bool readable, bool writable) {
148 shape.data(), shape.size(), readable,
149 writable, &value_));
150 }
151
155
157 : value_(std::exchange(other.value_, nullptr)) {}
158
160 if (this != &other) {
162 value_ = std::exchange(other.value_, nullptr);
163 }
164 return *this;
165 }
166
167private:
168 friend class MLContext;
169 RustnnTensorDescriptor *value_ = nullptr;
170};
171
174public:
176 MLOperand(const MLOperand &) = delete;
177 MLOperand &operator=(const MLOperand &) = delete;
178
179 MLOperand(MLOperand &&other) noexcept : value_(std::exchange(other.value_, nullptr)) {}
180
181 MLOperand &operator=(MLOperand &&other) noexcept {
182 if (this != &other) {
184 value_ = std::exchange(other.value_, nullptr);
185 }
186 return *this;
187 }
188
189private:
190 friend class MLGraphBuilder;
191 explicit MLOperand(RustnnOperand *value) : value_(value) {}
192 RustnnOperand *value_ = nullptr;
193};
194
196class MLGraph {
197public:
199 MLGraph(const MLGraph &) = delete;
200 MLGraph &operator=(const MLGraph &) = delete;
201
202 MLGraph(MLGraph &&other) noexcept : value_(std::exchange(other.value_, nullptr)) {}
203
204 MLGraph &operator=(MLGraph &&other) noexcept {
205 if (this != &other) {
206 rustnn_graph_destroy(value_);
207 value_ = std::exchange(other.value_, nullptr);
208 }
209 return *this;
210 }
211
212private:
213 friend class MLContext;
214 friend class MLGraphBuilder;
215 explicit MLGraph(RustnnGraph *value) : value_(value) {}
216 RustnnGraph *value_ = nullptr;
217};
218
220class MLTensor {
221public:
223 MLTensor(const MLTensor &) = delete;
224 MLTensor &operator=(const MLTensor &) = delete;
225
226 MLTensor(MLTensor &&other) noexcept : value_(std::exchange(other.value_, nullptr)) {}
227
228 MLTensor &operator=(MLTensor &&other) noexcept {
229 if (this != &other) {
230 rustnn_tensor_destroy(value_);
231 value_ = std::exchange(other.value_, nullptr);
232 }
233 return *this;
234 }
235
236private:
237 friend class MLContext;
238 explicit MLTensor(RustnnTensor *value) : value_(value) {}
239 RustnnTensor *value_ = nullptr;
240};
241
244public:
245 explicit MLContext(const MLContextOptions &options = {}) {
246 const RustnnBackendDevice raw_device_hint{
247 options.device_hint.has_value()
248 ? static_cast<RustnnBackend>(options.device_hint->backend)
250 options.device_hint.has_value()
251 ? static_cast<RustnnDeviceType>(options.device_hint->device_type)
253 options.device_hint.has_value() ? options.device_hint->device_index : 0};
254 const TrtxOptions trtx = options.rustnn_options.has_value()
255 ? options.rustnn_options->trtx
256 : TrtxOptions{};
257 const RustnnOptions raw_rustnn_options{{
258 trtx.engine_caching,
259 trtx.runtime_cache,
260 trtx.fail_on_cache_miss,
261 trtx.cuda_graphs,
262 }};
263 const RustnnContextOptions raw_options{
264 static_cast<RustnnPowerPreference>(options.power_preference),
265 options.accelerated,
266 static_cast<RustnnBackend>(options.backend_hint),
267 options.device_hint.has_value(),
268 raw_device_hint,
269 options.rustnn_options.has_value(),
270 raw_rustnn_options};
271 check(rustnn_context_create(&raw_options, &value_));
272 }
273
275 MLContext(const MLContext &) = delete;
276 MLContext &operator=(const MLContext &) = delete;
277
278 MLContext(MLContext &&other) noexcept : value_(std::exchange(other.value_, nullptr)) {}
279
280 MLContext &operator=(MLContext &&other) noexcept {
281 if (this != &other) {
283 value_ = std::exchange(other.value_, nullptr);
284 }
285 return *this;
286 }
287
290 RustnnTensor *tensor = nullptr;
291 check(rustnn_context_create_tensor(value_, descriptor.value_, &tensor));
292 return MLTensor(tensor);
293 }
294
296 template <typename T>
297 void writeTensor(const MLTensor &tensor, const std::vector<T> &data) {
298 static_assert(std::is_trivially_copyable_v<T>, "tensor elements must be plain data");
299 check(rustnn_context_write_tensor(value_, tensor.value_, data.data(),
300 data.size() * sizeof(T)));
301 }
302
304 template <typename T>
305 std::vector<T> readTensor(const MLTensor &tensor, std::size_t element_count) {
306 static_assert(std::is_trivially_copyable_v<T>, "tensor elements must be plain data");
307 std::vector<T> data(element_count);
308 check(rustnn_context_read_tensor(value_, tensor.value_, data.data(),
309 data.size() * sizeof(T)));
310 return data;
311 }
312
314 void dispatch(MLGraph &graph,
315 const std::vector<std::pair<std::string, const MLTensor *>> &inputs,
316 const std::vector<std::pair<std::string, const MLTensor *>> &outputs) {
317 std::vector<RustnnNamedTensor> named_inputs;
318 named_inputs.reserve(inputs.size());
319 for (const auto &[name, tensor] : inputs) {
320 named_inputs.push_back({name.c_str(), tensor != nullptr ? tensor->value_ : nullptr});
321 }
322 std::vector<RustnnNamedTensor> named_outputs;
323 named_outputs.reserve(outputs.size());
324 for (const auto &[name, tensor] : outputs) {
325 named_outputs.push_back({name.c_str(), tensor != nullptr ? tensor->value_ : nullptr});
326 }
327 check(rustnn_context_dispatch(value_, graph.value_, named_inputs.data(),
328 named_inputs.size(), named_outputs.data(),
329 named_outputs.size()));
330 }
331
332private:
333 friend class MLGraphBuilder;
334 RustnnContext *value_ = nullptr;
335};
336
337#define RUSTNN_ML_UNARY_METHOD(method, function) \
338 MLOperand method(const MLOperand &input) { \
339 RustnnOperand *output = nullptr; \
340 check(function(value_, input.value_, &output)); \
341 return MLOperand(output); \
342 }
343
344#define RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(method, function) \
345 RUSTNN_ML_UNARY_METHOD(method, function) \
346 MLOperand method(const MLOperand &input, \
347 const MLOperatorOptions &options) { \
348 RustnnOperand *output = nullptr; \
349 const RustnnOperatorOptions raw_options{options.label.c_str()}; \
350 check(function##_with_options(value_, input.value_, &raw_options, \
351 &output)); \
352 return MLOperand(output); \
353 }
354
355#define RUSTNN_ML_BINARY_METHOD(method, function) \
356 MLOperand method(const MLOperand &lhs, const MLOperand &rhs) { \
357 RustnnOperand *output = nullptr; \
358 check(function(value_, lhs.value_, rhs.value_, &output)); \
359 return MLOperand(output); \
360 }
361
362#define RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(method, function) \
363 RUSTNN_ML_BINARY_METHOD(method, function) \
364 MLOperand method(const MLOperand &lhs, const MLOperand &rhs, \
365 const MLOperatorOptions &options) { \
366 RustnnOperand *output = nullptr; \
367 const RustnnOperatorOptions raw_options{options.label.c_str()}; \
368 check(function##_with_options(value_, lhs.value_, rhs.value_, \
369 &raw_options, &output)); \
370 return MLOperand(output); \
371 }
372
373#define RUSTNN_ML_TERNARY_METHOD(method, function) \
374 MLOperand method(const MLOperand &first, const MLOperand &second, \
375 const MLOperand &third) { \
376 RustnnOperand *output = nullptr; \
377 check(function(value_, first.value_, second.value_, third.value_, \
378 &output)); \
379 return MLOperand(output); \
380 }
381
388public:
390 explicit MLGraphBuilder(MLContext &context) {
391 check(rustnn_graph_builder_create(context.value_, &value_));
392 }
396
398 : value_(std::exchange(other.value_, nullptr)) {}
399
401 if (this != &other) {
403 value_ = std::exchange(other.value_, nullptr);
404 }
405 return *this;
406 }
407
409 MLOperand input(const std::string &name, const MLOperandDescriptor &descriptor) {
410 RustnnOperand *output = nullptr;
411 check(rustnn_graph_builder_input(value_, name.c_str(), descriptor.value_, &output));
412 return MLOperand(output);
413 }
414
416 template <typename T>
417 MLOperand constant(const MLOperandDescriptor &descriptor, const std::vector<T> &data) {
418 static_assert(std::is_trivially_copyable_v<T>, "tensor elements must be plain data");
419 RustnnOperand *output = nullptr;
420 check(rustnn_graph_builder_constant(value_, descriptor.value_, data.data(),
421 data.size() * sizeof(T), &output));
422 return MLOperand(output);
423 }
424
426 RustnnOperand *output = nullptr;
427 check(rustnn_graph_builder_unary(value_, operation, input.value_, &output));
428 return MLOperand(output);
429 }
430
432 const MLOperatorOptions &options) {
433 RustnnOperand *output = nullptr;
434 const RustnnOperatorOptions raw_options{options.label.c_str()};
436 value_, operation, input.value_, &raw_options, &output));
437 return MLOperand(output);
438 }
439
441 const MLOperand &rhs) {
442 RustnnOperand *output = nullptr;
443 check(rustnn_graph_builder_binary(value_, operation, lhs.value_, rhs.value_, &output));
444 return MLOperand(output);
445 }
446
448 const MLOperand &rhs, const MLOperatorOptions &options) {
449 RustnnOperand *output = nullptr;
450 const RustnnOperatorOptions raw_options{options.label.c_str()};
452 value_, operation, lhs.value_, rhs.value_, &raw_options, &output));
453 return MLOperand(output);
454 }
455
456 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(add, rustnn_graph_builder_add)
457 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(subtract, rustnn_graph_builder_subtract)
458 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(multiply, rustnn_graph_builder_multiply)
459 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(divide, rustnn_graph_builder_divide)
460 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(power, rustnn_graph_builder_power)
461 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(maximum, rustnn_graph_builder_maximum)
462 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(minimum, rustnn_graph_builder_minimum)
463 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(equal, rustnn_graph_builder_equal)
464 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(greater, rustnn_graph_builder_greater)
465 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(greaterOrEqual,
467 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(lesser, rustnn_graph_builder_lesser)
468 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(lesserOrEqual,
470 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(notEqual, rustnn_graph_builder_not_equal)
471 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(logicalAnd,
473 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(logicalOr,
475 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(logicalXor,
477 RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS(matmul, rustnn_graph_builder_matmul)
478
479 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(abs, rustnn_graph_builder_abs)
480 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(roundEven, rustnn_graph_builder_round_even)
481 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(ceil, rustnn_graph_builder_ceil)
482 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(cos, rustnn_graph_builder_cos)
483 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(exp, rustnn_graph_builder_exp)
484 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(floor, rustnn_graph_builder_floor)
485 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(gelu, rustnn_graph_builder_gelu)
486 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(log, rustnn_graph_builder_log)
487 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(negate, rustnn_graph_builder_negate)
488 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(relu, rustnn_graph_builder_relu)
489 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(sigmoid, rustnn_graph_builder_sigmoid)
490 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(sin, rustnn_graph_builder_sin)
491 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(sqrt, rustnn_graph_builder_sqrt)
492 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(tan, rustnn_graph_builder_tan)
493 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(tanh, rustnn_graph_builder_tanh)
494 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(erf, rustnn_graph_builder_erf)
495 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(reciprocal,
497 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(sign, rustnn_graph_builder_sign)
498 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(logicalNot,
500 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(identity, rustnn_graph_builder_identity)
501 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(softplus, rustnn_graph_builder_softplus)
502 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(softsign, rustnn_graph_builder_softsign)
503 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(isNaN, rustnn_graph_builder_is_nan)
504 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(isInfinite,
506 RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS(shape, rustnn_graph_builder_shape)
507
508 RUSTNN_ML_UNARY_METHOD(elu, rustnn_graph_builder_elu)
512 RUSTNN_ML_UNARY_METHOD(linear, rustnn_graph_builder_linear)
513 RUSTNN_ML_UNARY_METHOD(clamp, rustnn_graph_builder_clamp)
514 RUSTNN_ML_UNARY_METHOD(instanceNormalization,
516 RUSTNN_ML_UNARY_METHOD(layerNormalization,
519 RUSTNN_ML_UNARY_METHOD(reverse, rustnn_graph_builder_reverse)
532 RUSTNN_ML_UNARY_METHOD(reduceLogSumExp,
534 RUSTNN_ML_UNARY_METHOD(reduceSumSquare,
537 RUSTNN_ML_UNARY_METHOD(squeeze, rustnn_graph_builder_squeeze)
539
540 RUSTNN_ML_BINARY_METHOD(gemm, rustnn_graph_builder_gemm)
541 RUSTNN_ML_BINARY_METHOD(conv2d, rustnn_graph_builder_conv2d)
542 RUSTNN_ML_BINARY_METHOD(convTranspose2d,
544 RUSTNN_ML_BINARY_METHOD(gather, rustnn_graph_builder_gather)
545 RUSTNN_ML_BINARY_METHOD(gatherElements,
547 RUSTNN_ML_BINARY_METHOD(gatherND, rustnn_graph_builder_gather_nd)
548 RUSTNN_ML_BINARY_METHOD(prelu, rustnn_graph_builder_prelu)
549
550 RUSTNN_ML_TERNARY_METHOD(batchNormalization,
552 RUSTNN_ML_TERNARY_METHOD(where, rustnn_graph_builder_where)
553 RUSTNN_ML_TERNARY_METHOD(scatterElements,
556
557 MLOperand argMin(const MLOperand &input, std::uint32_t axis) {
558 RustnnOperand *output = nullptr;
559 check(rustnn_graph_builder_arg_min(value_, input.value_, axis, &output));
560 return MLOperand(output);
561 }
562
563 MLOperand argMax(const MLOperand &input, std::uint32_t axis) {
564 RustnnOperand *output = nullptr;
565 check(rustnn_graph_builder_arg_max(value_, input.value_, axis, &output));
566 return MLOperand(output);
567 }
568
570 RustnnOperand *output = nullptr;
572 static_cast<RustnnDataType>(data_type), &output));
573 return MLOperand(output);
574 }
575
576 MLOperand cumulativeSum(const MLOperand &input, std::uint32_t axis) {
577 RustnnOperand *output = nullptr;
578 check(rustnn_graph_builder_cumulative_sum(value_, input.value_, axis, &output));
579 return MLOperand(output);
580 }
581
582 MLOperand softmax(const MLOperand &input, std::uint32_t axis) {
583 RustnnOperand *output = nullptr;
584 check(rustnn_graph_builder_softmax(value_, input.value_, axis, &output));
585 return MLOperand(output);
586 }
587
589 const std::vector<std::uint32_t> &new_shape) {
590 RustnnOperand *output = nullptr;
591 check(rustnn_graph_builder_expand(value_, input.value_, new_shape.data(),
592 new_shape.size(), &output));
593 return MLOperand(output);
594 }
595
597 const std::vector<std::uint32_t> &new_shape) {
598 RustnnOperand *output = nullptr;
599 check(rustnn_graph_builder_reshape(value_, input.value_, new_shape.data(),
600 new_shape.size(), &output));
601 return MLOperand(output);
602 }
603
605 const std::vector<std::uint32_t> &repetitions) {
606 RustnnOperand *output = nullptr;
607 check(rustnn_graph_builder_tile(value_, input.value_, repetitions.data(),
608 repetitions.size(), &output));
609 return MLOperand(output);
610 }
611
613 const std::vector<std::uint32_t> &beginning_padding,
614 const std::vector<std::uint32_t> &ending_padding) {
615 RustnnOperand *output = nullptr;
617 value_, input.value_, beginning_padding.data(), beginning_padding.size(),
618 ending_padding.data(), ending_padding.size(), &output));
619 return MLOperand(output);
620 }
621
623 const std::vector<std::uint32_t> &starts,
624 const std::vector<std::uint32_t> &sizes) {
625 RustnnOperand *output = nullptr;
626 check(rustnn_graph_builder_slice(value_, input.value_, starts.data(),
627 starts.size(), sizes.data(), sizes.size(),
628 &output));
629 return MLOperand(output);
630 }
631
632 MLOperand concat(const std::vector<const MLOperand *> &inputs,
633 std::uint32_t axis) {
634 std::vector<const RustnnOperand *> raw_inputs;
635 raw_inputs.reserve(inputs.size());
636 for (const MLOperand *input : inputs) {
637 raw_inputs.push_back(input != nullptr ? input->value_ : nullptr);
638 }
639 RustnnOperand *output = nullptr;
640 check(rustnn_graph_builder_concat(value_, raw_inputs.data(), raw_inputs.size(),
641 axis, &output));
642 return MLOperand(output);
643 }
644
646 const MLOperand *zero_point = nullptr) {
647 RustnnOperand *output = nullptr;
649 value_, input.value_, scale.value_,
650 zero_point != nullptr ? zero_point->value_ : nullptr, &output));
651 return MLOperand(output);
652 }
653
655 const MLOperand *zero_point = nullptr) {
656 RustnnOperand *output = nullptr;
658 value_, input.value_, scale.value_,
659 zero_point != nullptr ? zero_point->value_ : nullptr, &output));
660 return MLOperand(output);
661 }
662
663 std::vector<MLOperand> split(const MLOperand &input,
664 const std::vector<std::uint32_t> &splits) {
665 std::vector<RustnnOperand *> raw_outputs(splits.size());
666 std::size_t outputs_len = 0;
667 check(rustnn_graph_builder_split(value_, input.value_, splits.data(), splits.size(),
668 raw_outputs.data(), raw_outputs.size(),
669 &outputs_len));
670 return wrapOperands(raw_outputs, outputs_len);
671 }
672
673 std::vector<MLOperand> split(const MLOperand &input,
674 std::uint32_t num_splits) {
675 std::vector<RustnnOperand *> raw_outputs(num_splits);
676 std::size_t outputs_len = 0;
678 value_, input.value_, num_splits, raw_outputs.data(), raw_outputs.size(),
679 &outputs_len));
680 return wrapOperands(raw_outputs, outputs_len);
681 }
682
683 std::vector<MLOperand> gru(const MLOperand &input, const MLOperand &weight,
684 const MLOperand &recurrent_weight,
685 std::uint32_t steps, std::uint32_t hidden_size) {
686 std::vector<RustnnOperand *> raw_outputs(1);
687 std::size_t outputs_len = 0;
689 value_, input.value_, weight.value_, recurrent_weight.value_, steps,
690 hidden_size, raw_outputs.data(), raw_outputs.size(), &outputs_len));
691 return wrapOperands(raw_outputs, outputs_len);
692 }
693
695 const MLOperand &recurrent_weight,
696 const MLOperand &hidden_state, std::uint32_t hidden_size) {
697 RustnnOperand *output = nullptr;
699 value_, input.value_, weight.value_, recurrent_weight.value_,
700 hidden_state.value_, hidden_size, &output));
701 return MLOperand(output);
702 }
703
704 std::vector<MLOperand> lstm(const MLOperand &input, const MLOperand &weight,
705 const MLOperand &recurrent_weight,
706 std::uint32_t steps, std::uint32_t hidden_size) {
707 std::vector<RustnnOperand *> raw_outputs(2);
708 std::size_t outputs_len = 0;
710 value_, input.value_, weight.value_, recurrent_weight.value_, steps,
711 hidden_size, raw_outputs.data(), raw_outputs.size(), &outputs_len));
712 return wrapOperands(raw_outputs, outputs_len);
713 }
714
715 std::vector<MLOperand>
716 lstmCell(const MLOperand &input, const MLOperand &weight,
717 const MLOperand &recurrent_weight, const MLOperand &hidden_state,
718 const MLOperand &cell_state, std::uint32_t hidden_size) {
719 std::vector<RustnnOperand *> raw_outputs(2);
720 std::size_t outputs_len = 0;
722 value_, input.value_, weight.value_, recurrent_weight.value_,
723 hidden_state.value_, cell_state.value_, hidden_size, raw_outputs.data(),
724 raw_outputs.size(), &outputs_len));
725 return wrapOperands(raw_outputs, outputs_len);
726 }
727
729 std::vector<std::uint64_t> operandShape(const MLOperand &operand) {
730 std::size_t rank = 0;
731 check(rustnn_graph_builder_operand_shape(value_, operand.value_, nullptr, 0, &rank));
732 std::vector<std::uint64_t> dimensions(rank);
733 check(rustnn_graph_builder_operand_shape(value_, operand.value_, dimensions.data(),
734 dimensions.size(), &rank));
735 return dimensions;
736 }
737
740 check(rustnn_graph_builder_operand_data_type(value_, operand.value_, &data_type));
741 return static_cast<MLOperandDataType>(data_type);
742 }
743
745 std::string webnnText(
746 const std::vector<std::pair<std::string, const MLOperand *>> &outputs) const {
747 std::vector<RustnnNamedOperand> named;
748 named.reserve(outputs.size());
749 for (const auto &[name, operand] : outputs) {
750 named.push_back({name.c_str(), operand != nullptr ? operand->value_ : nullptr});
751 }
752 char *text = nullptr;
753 check(rustnn_graph_builder_webnn_text(value_, named.data(), named.size(), &text));
754 std::string result(text);
756 return result;
757 }
758
760 MLGraph build(const std::vector<std::pair<std::string, const MLOperand *>> &outputs) {
761 std::vector<RustnnNamedOperand> named;
762 named.reserve(outputs.size());
763 for (const auto &[name, operand] : outputs) {
764 named.push_back({name.c_str(), operand != nullptr ? operand->value_ : nullptr});
765 }
766 RustnnGraph *graph = nullptr;
767 RustnnStatus status =
768 rustnn_graph_builder_build(&value_, named.data(), named.size(), &graph);
769 check(status);
770 return MLGraph(graph);
771 }
772
773private:
774 static std::vector<MLOperand>
775 wrapOperands(const std::vector<RustnnOperand *> &raw_operands,
776 std::size_t length) {
777 std::vector<MLOperand> operands;
778 operands.reserve(length);
779 for (std::size_t index = 0; index < length; ++index) {
780 operands.push_back(MLOperand(raw_operands[index]));
781 }
782 return operands;
783 }
784
785 RustnnGraphBuilder *value_ = nullptr;
786};
787
788#undef RUSTNN_ML_UNARY_METHOD
789#undef RUSTNN_ML_UNARY_METHOD_WITH_OPTIONS
790#undef RUSTNN_ML_BINARY_METHOD
791#undef RUSTNN_ML_BINARY_METHOD_WITH_OPTIONS
792#undef RUSTNN_ML_TERNARY_METHOD
793
794} // namespace rustnn
Exception containing the C API's failure message.
Definition rustnn.hpp:27
Error(const std::string &message)
Definition rustnn.hpp:29
Owns a backend context for graph compilation, tensors and dispatch.
Definition rustnn.hpp:243
MLContext & operator=(const MLContext &)=delete
MLContext & operator=(MLContext &&other) noexcept
Definition rustnn.hpp:280
MLContext(MLContext &&other) noexcept
Definition rustnn.hpp:278
friend class MLGraphBuilder
Definition rustnn.hpp:333
std::vector< T > readTensor(const MLTensor &tensor, std::size_t element_count)
Copy a readable tensor into element_count values; T must match its storage.
Definition rustnn.hpp:305
void writeTensor(const MLTensor &tensor, const std::vector< T > &data)
Copy raw bytes from data into a writable tensor; T must match its storage.
Definition rustnn.hpp:297
MLTensor createTensor(const MLTensorDescriptor &descriptor)
Allocate a backend tensor with the descriptor's host access flags.
Definition rustnn.hpp:289
void dispatch(MLGraph &graph, const std::vector< std::pair< std::string, const MLTensor * > > &inputs, const std::vector< std::pair< std::string, const MLTensor * > > &outputs)
Execute a compiled graph with tensors bound by input and output name.
Definition rustnn.hpp:314
MLContext(const MLContext &)=delete
MLContext(const MLContextOptions &options={})
Definition rustnn.hpp:245
MLOperand hardSigmoid(const MLOperand &input)
Definition rustnn.hpp:509
MLOperand softsign(const MLOperand &input)
Definition rustnn.hpp:502
MLOperand maxPool2d(const MLOperand &input)
Definition rustnn.hpp:522
MLOperand averagePool2d(const MLOperand &input)
Definition rustnn.hpp:521
MLOperand gruCell(const MLOperand &input, const MLOperand &weight, const MLOperand &recurrent_weight, const MLOperand &hidden_state, std::uint32_t hidden_size)
Definition rustnn.hpp:694
std::vector< MLOperand > split(const MLOperand &input, const std::vector< std::uint32_t > &splits)
Definition rustnn.hpp:663
MLOperand squeeze(const MLOperand &input)
Definition rustnn.hpp:537
MLOperand greaterOrEqual(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:466
MLOperand exp(const MLOperand &input)
Definition rustnn.hpp:483
MLOperand ceil(const MLOperand &input)
Definition rustnn.hpp:481
MLOperand convTranspose2d(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:543
MLOperand binary(RustnnBinaryOperation operation, const MLOperand &lhs, const MLOperand &rhs, const MLOperatorOptions &options)
Definition rustnn.hpp:447
std::vector< MLOperand > lstmCell(const MLOperand &input, const MLOperand &weight, const MLOperand &recurrent_weight, const MLOperand &hidden_state, const MLOperand &cell_state, std::uint32_t hidden_size)
Definition rustnn.hpp:716
MLOperand softplus(const MLOperand &input)
Definition rustnn.hpp:501
MLOperand abs(const MLOperand &input)
Definition rustnn.hpp:479
MLOperand reshape(const MLOperand &input, const std::vector< std::uint32_t > &new_shape)
Definition rustnn.hpp:596
MLOperand layerNormalization(const MLOperand &input)
Definition rustnn.hpp:517
MLOperand isNaN(const MLOperand &input)
Definition rustnn.hpp:503
MLOperand argMin(const MLOperand &input, std::uint32_t axis)
Definition rustnn.hpp:557
MLOperand batchNormalization(const MLOperand &first, const MLOperand &second, const MLOperand &third)
Definition rustnn.hpp:551
MLOperand gather(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:544
MLOperand reverse(const MLOperand &input)
Definition rustnn.hpp:519
MLGraphBuilder & operator=(MLGraphBuilder &&other) noexcept
Definition rustnn.hpp:400
MLOperand unary(RustnnUnaryOperation operation, const MLOperand &input)
Definition rustnn.hpp:425
MLOperand cos(const MLOperand &input)
Definition rustnn.hpp:482
MLOperand erf(const MLOperand &input)
Definition rustnn.hpp:494
MLOperand sqrt(const MLOperand &input)
Definition rustnn.hpp:491
MLOperand instanceNormalization(const MLOperand &input)
Definition rustnn.hpp:515
MLOperand argMax(const MLOperand &input, std::uint32_t axis)
Definition rustnn.hpp:563
MLOperand lesserOrEqual(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:469
MLOperand notEqual(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:470
MLOperandDataType dataType(const MLOperand &operand)
Definition rustnn.hpp:738
MLOperand sign(const MLOperand &input)
Definition rustnn.hpp:497
std::string webnnText(const std::vector< std::pair< std::string, const MLOperand * > > &outputs) const
Serialize the named outputs as rustnn WebNN graph text.
Definition rustnn.hpp:745
MLOperand prelu(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:548
MLOperand reduceLogSum(const MLOperand &input)
Definition rustnn.hpp:531
MLOperand where(const MLOperand &first, const MLOperand &second, const MLOperand &third)
Definition rustnn.hpp:552
MLGraphBuilder(MLGraphBuilder &&other) noexcept
Definition rustnn.hpp:397
MLOperand isInfinite(const MLOperand &input)
Definition rustnn.hpp:505
MLOperand reduceSum(const MLOperand &input)
Definition rustnn.hpp:524
MLOperand dequantizeLinear(const MLOperand &input, const MLOperand &scale, const MLOperand *zero_point=nullptr)
Definition rustnn.hpp:654
MLOperand logicalOr(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:474
MLOperand cast(const MLOperand &input, MLOperandDataType data_type)
Definition rustnn.hpp:569
MLOperand linear(const MLOperand &input)
Definition rustnn.hpp:512
MLOperand input(const std::string &name, const MLOperandDescriptor &descriptor)
Declare a named graph input with the supplied type and shape.
Definition rustnn.hpp:409
MLOperand leakyRelu(const MLOperand &input)
Definition rustnn.hpp:511
MLOperand logicalNot(const MLOperand &input)
Definition rustnn.hpp:499
MLOperand shape(const MLOperand &input)
Definition rustnn.hpp:506
MLOperand pad(const MLOperand &input, const std::vector< std::uint32_t > &beginning_padding, const std::vector< std::uint32_t > &ending_padding)
Definition rustnn.hpp:612
MLOperand gemm(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:540
MLOperand identity(const MLOperand &input)
Definition rustnn.hpp:500
MLOperand concat(const std::vector< const MLOperand * > &inputs, std::uint32_t axis)
Definition rustnn.hpp:632
std::vector< MLOperand > gru(const MLOperand &input, const MLOperand &weight, const MLOperand &recurrent_weight, std::uint32_t steps, std::uint32_t hidden_size)
Definition rustnn.hpp:683
MLGraphBuilder(const MLGraphBuilder &)=delete
MLOperand roundEven(const MLOperand &input)
Definition rustnn.hpp:480
MLOperand sigmoid(const MLOperand &input)
Definition rustnn.hpp:489
MLOperand greater(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:464
MLOperand sin(const MLOperand &input)
Definition rustnn.hpp:490
MLOperand reduceMax(const MLOperand &input)
Definition rustnn.hpp:526
MLOperand cumulativeSum(const MLOperand &input, std::uint32_t axis)
Definition rustnn.hpp:576
MLOperand slice(const MLOperand &input, const std::vector< std::uint32_t > &starts, const std::vector< std::uint32_t > &sizes)
Definition rustnn.hpp:622
MLOperand quantizeLinear(const MLOperand &input, const MLOperand &scale, const MLOperand *zero_point=nullptr)
Definition rustnn.hpp:645
MLOperand lesser(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:467
MLOperand tan(const MLOperand &input)
Definition rustnn.hpp:492
MLOperand scatterElements(const MLOperand &first, const MLOperand &second, const MLOperand &third)
Definition rustnn.hpp:554
MLOperand unary(RustnnUnaryOperation operation, const MLOperand &input, const MLOperatorOptions &options)
Definition rustnn.hpp:431
MLOperand minimum(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:462
MLOperand matmul(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:477
MLGraphBuilder & operator=(const MLGraphBuilder &)=delete
MLOperand triangular(const MLOperand &input)
Definition rustnn.hpp:520
MLOperand softmax(const MLOperand &input, std::uint32_t axis)
Definition rustnn.hpp:582
MLOperand transpose(const MLOperand &input)
Definition rustnn.hpp:536
MLOperand add(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:456
MLOperand constant(const MLOperandDescriptor &descriptor, const std::vector< T > &data)
Copy constant data into the graph; T must match the descriptor's storage.
Definition rustnn.hpp:417
MLOperand tile(const MLOperand &input, const std::vector< std::uint32_t > &repetitions)
Definition rustnn.hpp:604
MLOperand reduceMin(const MLOperand &input)
Definition rustnn.hpp:527
MLOperand l2Pool2d(const MLOperand &input)
Definition rustnn.hpp:523
MLOperand relu(const MLOperand &input)
Definition rustnn.hpp:488
MLOperand clamp(const MLOperand &input)
Definition rustnn.hpp:513
MLOperand logicalAnd(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:472
std::vector< std::uint64_t > operandShape(const MLOperand &operand)
Return an operand's inferred dimensions.
Definition rustnn.hpp:729
MLOperand divide(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:459
MLOperand hardSwish(const MLOperand &input)
Definition rustnn.hpp:510
MLOperand conv2d(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:541
MLOperand binary(RustnnBinaryOperation operation, const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:440
MLOperand tanh(const MLOperand &input)
Definition rustnn.hpp:493
MLOperand multiply(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:458
MLOperand maximum(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:461
MLOperand resample2d(const MLOperand &input)
Definition rustnn.hpp:518
MLOperand reduceLogSumExp(const MLOperand &input)
Definition rustnn.hpp:533
MLOperand equal(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:463
MLOperand reduceL1(const MLOperand &input)
Definition rustnn.hpp:529
MLOperand gatherND(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:547
MLOperand log(const MLOperand &input)
Definition rustnn.hpp:486
MLOperand elu(const MLOperand &input)
Definition rustnn.hpp:508
MLOperand scatterND(const MLOperand &first, const MLOperand &second, const MLOperand &third)
Definition rustnn.hpp:555
MLGraphBuilder(MLContext &context)
Definition rustnn.hpp:390
MLOperand negate(const MLOperand &input)
Definition rustnn.hpp:487
MLOperand power(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:460
MLOperand reduceProduct(const MLOperand &input)
Definition rustnn.hpp:528
MLOperand logicalXor(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:476
MLOperand subtract(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:457
MLOperand gatherElements(const MLOperand &lhs, const MLOperand &rhs)
Definition rustnn.hpp:546
MLOperand reduceSumSquare(const MLOperand &input)
Definition rustnn.hpp:535
MLOperand reciprocal(const MLOperand &input)
Definition rustnn.hpp:496
MLOperand reduceMean(const MLOperand &input)
Definition rustnn.hpp:525
std::vector< MLOperand > split(const MLOperand &input, std::uint32_t num_splits)
Definition rustnn.hpp:673
MLOperand floor(const MLOperand &input)
Definition rustnn.hpp:484
MLGraph build(const std::vector< std::pair< std::string, const MLOperand * > > &outputs)
Compile named outputs and consume this builder; the context must outlive the graph.
Definition rustnn.hpp:760
MLOperand unsqueeze(const MLOperand &input)
Definition rustnn.hpp:538
MLOperand expand(const MLOperand &input, const std::vector< std::uint32_t > &new_shape)
Definition rustnn.hpp:588
MLOperand reduceL2(const MLOperand &input)
Definition rustnn.hpp:530
MLOperand gelu(const MLOperand &input)
Definition rustnn.hpp:485
std::vector< MLOperand > lstm(const MLOperand &input, const MLOperand &weight, const MLOperand &recurrent_weight, std::uint32_t steps, std::uint32_t hidden_size)
Definition rustnn.hpp:704
Owns a compiled graph. Its originating context must outlive it.
Definition rustnn.hpp:196
MLGraph(const MLGraph &)=delete
MLGraph & operator=(const MLGraph &)=delete
friend class MLContext
Definition rustnn.hpp:213
friend class MLGraphBuilder
Definition rustnn.hpp:214
MLGraph & operator=(MLGraph &&other) noexcept
Definition rustnn.hpp:204
MLGraph(MLGraph &&other) noexcept
Definition rustnn.hpp:202
Owns an operand's element type and shape descriptor.
Definition rustnn.hpp:115
MLOperandDescriptor(const MLOperandDescriptor &)=delete
MLOperandDescriptor & operator=(MLOperandDescriptor &&other) noexcept
Definition rustnn.hpp:129
MLOperandDescriptor(MLOperandDescriptor &&other) noexcept
Definition rustnn.hpp:126
MLOperandDescriptor & operator=(const MLOperandDescriptor &)=delete
friend class MLGraphBuilder
Definition rustnn.hpp:138
MLOperandDescriptor(MLOperandDataType data_type, const std::vector< std::uint64_t > &shape)
Definition rustnn.hpp:117
Owns an operand handle belonging to a graph builder.
Definition rustnn.hpp:173
MLOperand & operator=(const MLOperand &)=delete
friend class MLGraphBuilder
Definition rustnn.hpp:190
MLOperand & operator=(MLOperand &&other) noexcept
Definition rustnn.hpp:181
MLOperand(MLOperand &&other) noexcept
Definition rustnn.hpp:179
MLOperand(const MLOperand &)=delete
Owns a tensor descriptor with host read and write permissions.
Definition rustnn.hpp:143
MLTensorDescriptor(const MLTensorDescriptor &)=delete
MLTensorDescriptor(MLOperandDataType data_type, const std::vector< std::uint64_t > &shape, bool readable, bool writable)
Definition rustnn.hpp:145
MLTensorDescriptor & operator=(const MLTensorDescriptor &)=delete
MLTensorDescriptor & operator=(MLTensorDescriptor &&other) noexcept
Definition rustnn.hpp:159
MLTensorDescriptor(MLTensorDescriptor &&other) noexcept
Definition rustnn.hpp:156
Owns a backend tensor. Its originating context must outlive it.
Definition rustnn.hpp:220
friend class MLContext
Definition rustnn.hpp:237
MLTensor(MLTensor &&other) noexcept
Definition rustnn.hpp:226
MLTensor(const MLTensor &)=delete
MLTensor & operator=(const MLTensor &)=delete
MLTensor & operator=(MLTensor &&other) noexcept
Definition rustnn.hpp:228
void check(RustnnStatus status)
Throw Error if a C API call returned a failing status.
Definition rustnn.hpp:33
MLOperandDataType
Element type, including packed signed and unsigned 4-bit integers.
Definition rustnn.hpp:41
void initializeLogger()
Initialize rustnn's logger using the environment configuration.
Definition rustnn.hpp:24
MLPowerPreference
Power preference used for automatic backend selection.
Definition rustnn.hpp:57
Backend
Backend hint; Automatic delegates selection to rustnn.
Definition rustnn.hpp:64
DeviceType
Kind of device used to execute a graph.
Definition rustnn.hpp:74
enum RustnnStatus rustnn_graph_builder_erf(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the erf operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_gelu(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the gelu operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_elu(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the elu operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_round_even(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the round even operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_lesser_or_equal(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the lesser or equal operation using [MLGraphBuilder].
enum RustnnStatus rustnn_context_dispatch(struct RustnnContext *context, struct RustnnGraph *graph, const struct RustnnNamedTensor *inputs, uintptr_t inputs_len, const struct RustnnNamedTensor *outputs, uintptr_t outputs_len)
Run an [MLGraph] through [MLContext] with named input and output tensors.
void rustnn_operand_destroy(struct RustnnOperand *operand)
Release an [MLOperand] handle.
enum RustnnStatus rustnn_graph_builder_constant(struct RustnnGraphBuilder *builder, const struct RustnnOperandDescriptor *descriptor, const void *data, uintptr_t data_len, struct RustnnOperand **output)
Create a constant [MLOperand] from descriptor and bytes on [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_is_infinite(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the is infinite operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_concat(struct RustnnGraphBuilder *builder, const struct RustnnOperand *const *inputs, uintptr_t inputs_len, uint32_t axis, struct RustnnOperand **output)
Apply the concat operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_add(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the add operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_sqrt(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the sqrt operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_max_pool2d(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the max pool2d operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_operand_data_type(struct RustnnGraphBuilder *builder, const struct RustnnOperand *operand, enum RustnnDataType *data_type)
Read an [MLOperand] data type from [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_reduce_l1(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce l1 operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_softsign(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the softsign operation using [MLGraphBuilder].
const char * rustnn_last_error_message(void)
Return the last C API error message for this thread.
enum RustnnStatus rustnn_graph_builder_matmul(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the matmul operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_binary(struct RustnnGraphBuilder *builder, enum RustnnBinaryOperation operation, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply a selected binary operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_log(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the log operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_sin(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the sin operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_layer_normalization(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the layer normalization operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_negate(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the negate operation using [MLGraphBuilder].
void rustnn_graph_destroy(struct RustnnGraph *graph)
Release an [MLGraph] handle.
void rustnn_operand_descriptor_destroy(struct RustnnOperandDescriptor *descriptor)
Release an [MLOperandDescriptor] handle.
enum RustnnStatus rustnn_graph_builder_floor(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the floor operation using [MLGraphBuilder].
struct RustnnOperandDescriptor RustnnOperandDescriptor
Opaque handle wrapping [MLOperandDescriptor].
Definition rustnn.h:258
enum RustnnStatus rustnn_graph_builder_gru_cell(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const struct RustnnOperand *weight, const struct RustnnOperand *recurrent_weight, const struct RustnnOperand *hidden_state, uint32_t hidden_size, struct RustnnOperand **output)
Apply the gru cell operation using [MLGraphBuilder].
RustnnBinaryOperation
Implementation detail of the C++ API.
Definition rustnn.h:188
RustnnDataType
C representation of [MLOperandDataType].
Definition rustnn.h:43
@ RustnnDataType_Bfloat16
Definition rustnn.h:54
@ RustnnDataType_Uint4
Definition rustnn.h:53
@ RustnnDataType_Uint32
Definition rustnn.h:47
@ RustnnDataType_Float32
Definition rustnn.h:44
@ RustnnDataType_Int4
Definition rustnn.h:52
@ RustnnDataType_Int8
Definition rustnn.h:50
@ RustnnDataType_Float8e4m3
Definition rustnn.h:55
@ RustnnDataType_Uint8
Definition rustnn.h:51
@ RustnnDataType_Uint64
Definition rustnn.h:49
@ RustnnDataType_Int64
Definition rustnn.h:48
@ RustnnDataType_Float16
Definition rustnn.h:45
@ RustnnDataType_Int32
Definition rustnn.h:46
enum RustnnStatus rustnn_graph_builder_batch_normalization(struct RustnnGraphBuilder *builder, const struct RustnnOperand *first, const struct RustnnOperand *second, const struct RustnnOperand *third, struct RustnnOperand **output)
Apply the batch normalization operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_shape(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the shape operation using [MLGraphBuilder].
struct RustnnOperand RustnnOperand
Opaque handle wrapping [MLOperand].
Definition rustnn.h:251
struct RustnnGraphBuilder RustnnGraphBuilder
Opaque handle wrapping [MLGraphBuilder].
Definition rustnn.h:244
enum RustnnStatus rustnn_graph_builder_unary(struct RustnnGraphBuilder *builder, enum RustnnUnaryOperation operation, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply a selected unary operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_is_nan(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the is nan operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_power(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the power operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_minimum(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the minimum operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_sign(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the sign operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_webnn_text(const struct RustnnGraphBuilder *builder, const struct RustnnNamedOperand *outputs, uintptr_t outputs_len, char **text)
Serialize [MLGraphBuilder] output operands as rustnn WebNN text.
RustnnBackend
Backend hint for [MLContextOptions], wrapping [Backend].
Definition rustnn.h:82
@ RustnnBackend_Automatic
Select a backend automatically.
Definition rustnn.h:86
@ RustnnBackend_Litert
Use LiteRT.
Definition rustnn.h:102
@ RustnnBackend_Cann
Use CANN.
Definition rustnn.h:106
@ RustnnBackend_Onnx
Use ONNX Runtime.
Definition rustnn.h:90
@ RustnnBackend_Coreml
Use CoreML.
Definition rustnn.h:98
@ RustnnBackend_Trtx
Use TensorRT-RTX.
Definition rustnn.h:94
enum RustnnStatus rustnn_graph_builder_ceil(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the ceil operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_cos(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the cos operation using [MLGraphBuilder].
struct RustnnTensor RustnnTensor
Opaque handle wrapping [MLTensor].
Definition rustnn.h:265
enum RustnnStatus rustnn_graph_builder_squeeze(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the squeeze operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_conv_transpose2d(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the conv transpose2d operation using [MLGraphBuilder].
enum RustnnStatus rustnn_operand_descriptor_create(enum RustnnDataType data_type, const uint64_t *shape, uintptr_t shape_len, struct RustnnOperandDescriptor **output)
Allocate an [MLOperandDescriptor] from a data type and shape.
enum RustnnStatus rustnn_graph_builder_softmax(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, uint32_t axis, struct RustnnOperand **output)
Apply the softmax operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_build(struct RustnnGraphBuilder **builder, const struct RustnnNamedOperand *outputs, uintptr_t outputs_len, struct RustnnGraph **graph)
Compile a runtime-backed [MLGraphBuilder] into an [MLGraph] and consume it, setting builder to null.
enum RustnnStatus rustnn_graph_builder_clamp(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the clamp operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_split_equal(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, uint32_t num_splits, struct RustnnOperand **outputs, uintptr_t outputs_capacity, uintptr_t *outputs_len)
Apply the split equal operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_multiply(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the multiply operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_hard_sigmoid(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the hard sigmoid operation using [MLGraphBuilder].
struct RustnnContext RustnnContext
Opaque handle wrapping [MLContext].
Definition rustnn.h:230
enum RustnnStatus rustnn_graph_builder_subtract(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the subtract operation using [MLGraphBuilder].
void rustnn_tensor_destroy(struct RustnnTensor *tensor)
Release an [MLTensor] handle.
enum RustnnStatus rustnn_graph_builder_expand(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const uint32_t *new_shape, uintptr_t new_shape_len, struct RustnnOperand **output)
Apply the expand operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_conv2d(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the conv2d operation using [MLGraphBuilder].
RustnnDeviceType
C representation of [DeviceType] for a [BackendDevice] hint.
Definition rustnn.h:112
@ RustnnDeviceType_Npu
NPU device.
Definition rustnn.h:124
@ RustnnDeviceType_Gpu
GPU device.
Definition rustnn.h:120
@ RustnnDeviceType_Cpu
CPU device.
Definition rustnn.h:116
enum RustnnStatus rustnn_graph_builder_sigmoid(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the sigmoid operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_transpose(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the transpose operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_softplus(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the softplus operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_reduce_mean(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce mean operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_gather_elements(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the gather elements operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_quantize_linear(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const struct RustnnOperand *scale, const struct RustnnOperand *zero_point, struct RustnnOperand **output)
Apply the quantize linear operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_leaky_relu(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the leaky relu operation using [MLGraphBuilder].
enum RustnnStatus rustnn_context_create(const struct RustnnContextOptions *options, struct RustnnContext **output)
Create an [MLContext].
enum RustnnStatus rustnn_graph_builder_reduce_max(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce max operation using [MLGraphBuilder].
struct RustnnTensorDescriptor RustnnTensorDescriptor
Opaque handle wrapping [MLTensorDescriptor].
Definition rustnn.h:272
enum RustnnStatus rustnn_graph_builder_reshape(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const uint32_t *new_shape, uintptr_t new_shape_len, struct RustnnOperand **output)
Apply the reshape operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_reduce_min(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce min operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_slice(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const uint32_t *starts, uintptr_t starts_len, const uint32_t *sizes, uintptr_t sizes_len, struct RustnnOperand **output)
Apply the slice operation using [MLGraphBuilder].
void rustnn_tensor_descriptor_destroy(struct RustnnTensorDescriptor *descriptor)
Release an [MLTensorDescriptor] handle.
enum RustnnStatus rustnn_graph_builder_scatter_elements(struct RustnnGraphBuilder *builder, const struct RustnnOperand *first, const struct RustnnOperand *second, const struct RustnnOperand *third, struct RustnnOperand **output)
Apply the scatter elements operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_unary_with_options(struct RustnnGraphBuilder *builder, enum RustnnUnaryOperation operation, const struct RustnnOperand *input, const struct RustnnOperatorOptions *options, struct RustnnOperand **output)
Implementation detail of the C++ API.
enum RustnnStatus rustnn_graph_builder_reduce_log_sum(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce log sum operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_divide(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the divide operation using [MLGraphBuilder].
enum RustnnStatus rustnn_tensor_descriptor_create(enum RustnnDataType data_type, const uint64_t *shape, uintptr_t shape_len, bool readable, bool writable, struct RustnnTensorDescriptor **output)
Allocate an [MLTensorDescriptor].
enum RustnnStatus rustnn_graph_builder_input(struct RustnnGraphBuilder *builder, const char *name, const struct RustnnOperandDescriptor *descriptor, struct RustnnOperand **output)
Declare a named input [MLOperand] on [MLGraphBuilder].
RustnnUnaryOperation
Implementation detail of the C++ API.
Definition rustnn.h:130
enum RustnnStatus rustnn_graph_builder_reciprocal(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reciprocal operation using [MLGraphBuilder].
void rustnn_string_destroy(char *value)
Release a string returned by this C API.
enum RustnnStatus rustnn_graph_builder_relu(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the relu operation using [MLGraphBuilder].
enum RustnnStatus rustnn_context_create_tensor(struct RustnnContext *context, const struct RustnnTensorDescriptor *descriptor, struct RustnnTensor **output)
Allocate an [MLTensor] from an [MLTensorDescriptor].
struct RustnnGraph RustnnGraph
Opaque handle wrapping [MLGraph].
Definition rustnn.h:237
enum RustnnStatus rustnn_graph_builder_reduce_sum(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce sum operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_create_uncompiled(struct RustnnGraphBuilder **output)
Create an uncompiled [MLGraphBuilder] for graph construction and serialization.
void rustnn_init_logger(void)
Install a tracing_subscriber global subscriber if none is installed yet.
enum RustnnStatus rustnn_graph_builder_identity(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the identity operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_tan(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the tan operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_arg_max(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, uint32_t axis, struct RustnnOperand **output)
Apply the arg max operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_logical_or(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the logical or operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_binary_with_options(struct RustnnGraphBuilder *builder, enum RustnnBinaryOperation operation, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, const struct RustnnOperatorOptions *options, struct RustnnOperand **output)
Implementation detail of the C++ API.
RustnnPowerPreference
C representation of [MLPowerPreference].
Definition rustnn.h:63
@ RustnnPowerPreference_HighPerformance
Prefer high performance.
Definition rustnn.h:71
@ RustnnPowerPreference_LowPower
Prefer low power.
Definition rustnn.h:75
@ RustnnPowerPreference_Default
Use the default power preference.
Definition rustnn.h:67
enum RustnnStatus rustnn_graph_builder_logical_not(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the logical not operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_gather_nd(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the gather nd operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_triangular(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the triangular operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_reduce_l2(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce l2 operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_l2_pool2d(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the l2 pool2d operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_resample2d(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the resample2d operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_prelu(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the prelu operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_pad(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const uint32_t *beginning_padding, uintptr_t beginning_padding_len, const uint32_t *ending_padding, uintptr_t ending_padding_len, struct RustnnOperand **output)
Apply the pad operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_gru(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const struct RustnnOperand *weight, const struct RustnnOperand *recurrent_weight, uint32_t steps, uint32_t hidden_size, struct RustnnOperand **outputs, uintptr_t outputs_capacity, uintptr_t *outputs_len)
Apply the gru operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_hard_swish(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the hard swish operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_split(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const uint32_t *splits, uintptr_t splits_len, struct RustnnOperand **outputs, uintptr_t outputs_capacity, uintptr_t *outputs_len)
Apply the split operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_reverse(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reverse operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_lstm(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const struct RustnnOperand *weight, const struct RustnnOperand *recurrent_weight, uint32_t steps, uint32_t hidden_size, struct RustnnOperand **outputs, uintptr_t outputs_capacity, uintptr_t *outputs_len)
Apply the lstm operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_not_equal(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the not equal operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_gemm(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the gemm operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_logical_and(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the logical and operation using [MLGraphBuilder].
RustnnStatus
Result of a C API call.
Definition rustnn.h:11
@ RustnnStatus_Success
The call completed successfully.
Definition rustnn.h:15
enum RustnnStatus rustnn_graph_builder_tile(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const uint32_t *repetitions, uintptr_t repetitions_len, struct RustnnOperand **output)
Apply the tile operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_arg_min(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, uint32_t axis, struct RustnnOperand **output)
Apply the arg min operation using [MLGraphBuilder].
enum RustnnStatus rustnn_context_read_tensor(struct RustnnContext *context, const struct RustnnTensor *tensor, void *data, uintptr_t data_len)
Copy bytes from an [MLTensor] through [MLContext].
enum RustnnStatus rustnn_graph_builder_abs(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the abs operation using [MLGraphBuilder].
void rustnn_graph_builder_destroy(struct RustnnGraphBuilder *builder)
Release an [MLGraphBuilder] handle.
enum RustnnStatus rustnn_graph_builder_instance_normalization(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the instance normalization operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_scatter_nd(struct RustnnGraphBuilder *builder, const struct RustnnOperand *first, const struct RustnnOperand *second, const struct RustnnOperand *third, struct RustnnOperand **output)
Apply the scatter nd operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_cumulative_sum(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, uint32_t axis, struct RustnnOperand **output)
Apply the cumulative sum operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_greater_or_equal(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the greater or equal operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_maximum(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the maximum operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_greater(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the greater operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_unsqueeze(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the unsqueeze operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_create(struct RustnnContext *context, struct RustnnGraphBuilder **output)
Create a runtime-backed [MLGraphBuilder] that exclusively borrows context.
enum RustnnStatus rustnn_context_write_tensor(struct RustnnContext *context, const struct RustnnTensor *tensor, const void *data, uintptr_t data_len)
Copy bytes into an [MLTensor] through [MLContext].
enum RustnnStatus rustnn_graph_builder_lstm_cell(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const struct RustnnOperand *weight, const struct RustnnOperand *recurrent_weight, const struct RustnnOperand *hidden_state, const struct RustnnOperand *cell_state, uint32_t hidden_size, struct RustnnOperand **outputs, uintptr_t outputs_capacity, uintptr_t *outputs_len)
Apply the lstm cell operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_cast(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, enum RustnnDataType data_type, struct RustnnOperand **output)
Apply the cast operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_logical_xor(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the logical xor operation using [MLGraphBuilder].
void rustnn_context_destroy(struct RustnnContext *context)
Release an [MLContext] handle.
enum RustnnStatus rustnn_graph_builder_reduce_product(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce product operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_equal(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the equal operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_reduce_sum_square(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce sum square operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_operand_shape(struct RustnnGraphBuilder *builder, const struct RustnnOperand *operand, uint64_t *dimensions, uintptr_t dimensions_capacity, uintptr_t *dimensions_len)
Copy an [MLOperand] shape from [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_dequantize_linear(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, const struct RustnnOperand *scale, const struct RustnnOperand *zero_point, struct RustnnOperand **output)
Apply the dequantize linear operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_where(struct RustnnGraphBuilder *builder, const struct RustnnOperand *first, const struct RustnnOperand *second, const struct RustnnOperand *third, struct RustnnOperand **output)
Apply the where operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_tanh(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the tanh operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_gather(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the gather operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_linear(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the linear operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_lesser(struct RustnnGraphBuilder *builder, const struct RustnnOperand *lhs, const struct RustnnOperand *rhs, struct RustnnOperand **output)
Apply the lesser operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_reduce_log_sum_exp(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the reduce log sum exp operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_exp(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the exp operation using [MLGraphBuilder].
enum RustnnStatus rustnn_graph_builder_average_pool2d(struct RustnnGraphBuilder *builder, const struct RustnnOperand *input, struct RustnnOperand **output)
Apply the average pool2d operation using [MLGraphBuilder].
C representation of [BackendDevice].
Definition rustnn.h:279
C representation of [MLContextOptions].
Definition rustnn.h:332
C representation of [MLOperatorOptions] shared by the operations exposed by this ABI.
Definition rustnn.h:369
C representation of [RustNNOptions].
Definition rustnn.h:320
Explicit backend and device hint for context creation.
Definition rustnn.hpp:81
DeviceType device_type
Definition rustnn.hpp:83
std::size_t device_index
Definition rustnn.hpp:84
Backend selection and runtime configuration for MLContext.
Definition rustnn.hpp:101
std::optional< RustNNOptions > rustnn_options
Definition rustnn.hpp:106
std::optional< BackendDevice > device_hint
Definition rustnn.hpp:105
MLPowerPreference power_preference
Definition rustnn.hpp:102
Optional operator label used in diagnostics.
Definition rustnn.hpp:110
rustnn-specific backend configuration.
Definition rustnn.hpp:96
TrtxOptions trtx
Definition rustnn.hpp:97
TensorRT-RTX engine caching and execution options.
Definition rustnn.hpp:88