-
Notifications
You must be signed in to change notification settings - Fork 375
/
xnnpack.h
4819 lines (4391 loc) · 195 KB
/
xnnpack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Facebook, Inc. and its affiliates.
// All rights reserved.
//
// Copyright 2019 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "pthreadpool.h"
#ifdef __cplusplus
extern "C" {
#endif
/// The number of bytes XNNPACK may read beyond array bounds.
/// The caller must allocate at least this many extra bytes after the tensor data passed to XNNPACK.
///
/// Note: XNNPACK reads, but never writes beyond array bounds.
#if XNN_ARCH_HEXAGON
#define XNN_EXTRA_BYTES 128
#else
#define XNN_EXTRA_BYTES 16
#endif // XNN_ARCH_HEXAGON
/// Maximum number of dimensions in tensor shape.
#define XNN_MAX_TENSOR_DIMS 6
/// A value ID that cannot be valid.
#define XNN_INVALID_VALUE_ID UINT32_MAX
/// Allow sparse inference in a Runtime.
///
/// Note: this flag is a hint to XNNPACK that it should consider sparse inference, but does not guarantee it.
#define XNN_FLAG_HINT_SPARSE_INFERENCE 0x00000001
/// Allow IEEE FP16 inference in a Runtime.
///
/// Note: this flag hints XNNPACK to consider IEEE FP16 inference, but does not guarantee it.
#define XNN_FLAG_HINT_FP16_INFERENCE 0x00000002
/// Force IEEE FP16 inference in a Runtime, and fail if FP16 inference is not possible.
///
/// Note: this flag guarantees that XNNPACK will use IEEE FP16 inference, or fail to create the Runtime object.
/// Warning: on x86 systems FP16 computations will be emulated at a substantial performance cost.
#define XNN_FLAG_FORCE_FP16_INFERENCE 0x00000004
/// Enable timing of each operator's runtime.
#define XNN_FLAG_BASIC_PROFILING 0x00000008
/// Enable the just-in-time compiler.
#define XNN_FLAG_JIT 0x00000010
/// The convolution operator represents a depthwise convolution, and use HWGo layout for filters.
#define XNN_FLAG_DEPTHWISE_CONVOLUTION 0x00000001
/// Assume transposed weights in a fully connected operator.
#define XNN_FLAG_TRANSPOSE_WEIGHTS 0x00000001
/// The operator assumes NHWC layout for the input, regardless of the output layout.
#define XNN_FLAG_INPUT_NHWC 0x00000002
/// Match "SAME" padding in TensorFlow. Exact padding values are computed dynamically depending on input size.
#define XNN_FLAG_TENSORFLOW_SAME_PADDING 0x00000004
/// Assume transposed weights in a batch matrix multiply operator.
#define XNN_FLAG_TRANSPOSE_B XNN_FLAG_TRANSPOSE_WEIGHTS
/// Assume transposed input in a batch matrix multiply operator.
#define XNN_FLAG_TRANSPOSE_A 0x00000002
/// Implicitly flatten and reshape input of a Fully Connected operator into a 2D tensor.
#define XNN_FLAG_TENSORFLOW_RESHAPE_2D 0x00000004
/// Match behaviour of TensorFlow 1.x.
#define XNN_FLAG_TENSORFLOW_LEGACY_MODE 0x00000004
/// Static weights of the FP16 operator are in FP32 format.
#define XNN_FLAG_FP32_STATIC_WEIGHTS 0x00000008
/// Static biases of the FP16 operator are in FP32 format.
#define XNN_FLAG_FP32_STATIC_BIASES 0x00000080
/// Align corners of input and output images in resize operations.
#define XNN_FLAG_ALIGN_CORNERS 0x00000008
/// Yield worker threads of the thread pool to the system scheduler after the inference.
#define XNN_FLAG_YIELD_WORKERS 0x00000010
/// Use transient indirection buffer to reduce memory footprint
#define XNN_FLAG_TRANSIENT_INDIRECTION_BUFFER 0x00000020
/// Retain reduced dimensions with length 1.
#define XNN_FLAG_KEEP_DIMS 0x00000040
// Next unused flag value: 0x00000100.
/// The number of entries in an array of xnn_quantization_params that XNNPACK may read beyond array bounds.
/// The caller must allocate at least this many extra xnn_quantization_params before passing the array to XNNPACK.
///
/// Note: XNNPACK reads, but never writes beyond array bounds.
#define XNN_EXTRA_QUANTIZATION_PARAMS 15
/// The minimum blocksize for blockwise quantized operators.
#define XNN_MIN_BLOCKSIZE 32
#ifdef __GNUC__
#define XNN_DEPRECATED __attribute__((deprecated))
#else
#define XNN_DEPRECATED
#endif
struct xnn_quantization_params {
int32_t zero_point;
float scale;
};
/// Status code for any XNNPACK function call.
enum xnn_status {
/// The call succeeded, and all output arguments now contain valid data.
xnn_status_success = 0,
xnn_status_uninitialized = 1,
xnn_status_invalid_parameter = 2,
xnn_status_invalid_state = 3,
xnn_status_unsupported_parameter = 4,
xnn_status_unsupported_hardware = 5,
xnn_status_out_of_memory = 6,
xnn_status_reallocation_required = 7,
xnn_status_deprecated = 8,
};
struct xnn_allocator {
/// User-specified pointer that will be passed as-is to all functions in this structure.
void* context;
/// Pointer to a function to be called for general memory allocation.
///
/// @param context - The user-specified pointer from xnn_allocator structure.
/// @param size - The size of the memory block to allocate, in bytes.
///
/// @returns Pointer to the allocated memory block of at least @ref size bytes.
/// If allocation fails, the function must return NULL.
void* (*allocate)(void* context, size_t size);
/// Pointer to a function to be called for general memory re-allocation, i.e. to increase or shrink a previously
/// allocated memory block. The content of the old memory block is copied to the new memory block.
///
/// @param context - The user-specified pointer from xnn_allocator structure.
/// @param pointer - Pointer to a memory block allocated by @ref allocate or @ref reallocate functions. Can be NULL.
/// If the pointer is NULL, the @ref reallocate call is equivalent to an @ref allocate call.
/// @param size - The new size of the memory block to allocate, in bytes.
///
/// @returns Pointer to the newly allocated memory block of at least @ref size bytes with the content of the previous
/// memory block.
/// If allocation fails, the function must return NULL, but must not release the previous memory block.
void* (*reallocate)(void* context, void* pointer, size_t size);
/// Pointer to a function to be called for general memory de-allocation.
///
/// @param context - The user-specified pointer from xnn_allocator structure.
/// @param pointer - Pointer to a memory block allocated by @ref allocate or @ref reallocate functions. Can be NULL.
/// If the pointer is NULL, the @ref deallocate call is a no-op.
void (*deallocate)(void* context, void* pointer);
/// Pointer to a function to be called for aligned memory allocation.
///
/// @param context - The user-specified pointer from xnn_allocator structure.
/// @param alignment - The alignment of the memory block to allocate, in bytes. Alignment is always a power-of-2.
/// @param size - The size of the memory block to allocate, in bytes.
///
/// @returns Pointer to the allocated memory block of at least @ref size bytes.
/// If allocation fails, the function must return NULL.
void* (*aligned_allocate)(void* context, size_t alignment, size_t size);
/// Pointer to a function to be called for aligned memory deallocation.
///
/// @param context - The user-specified pointer from xnn_allocator structure.
/// @param pointer - Pointer to a memory block allocated by @ref aligned_allocate function. Can be NULL.
/// If the pointer is NULL, the @ref aligned_deallocate call is a no-op.
void (*aligned_deallocate)(void* context, void* pointer);
};
/// Initialize XNNPACK library.
///
/// XNNPACK must be successfully initialized before use. During initialization, XNNPACK populates internal structures
/// depending on the host processor. Initialization can be time-consuming.
///
/// @param[in] allocator - structure with function pointers to be use for memory allocation and de-allocation.
/// If this argument is NULL, system-provided memory management functions (e.g. malloc/free)
/// will be used.
///
/// @retval xnn_status_success - XNNPACK is successfully initialized and ready to use.
/// @retval xnn_status_out_of_memory - initialization failed due to out-of-memory condition.
/// @retval xnn_status_unsupported_hardware - initialization failed because the host processor does not satisfy the
/// minimum hardware requirements for XNNPACK. E.g. this may happen on x86
/// processors without SSE2 extension, or on 32-bit ARM processors without
/// the NEON SIMD extension.
enum xnn_status xnn_initialize(const struct xnn_allocator* allocator);
/// Deinitialize XNNPACK library.
///
/// To avoid memory and resource leaks, users must call xnn_deinitialize once for each successful xnn_initialize call.
///
/// @retval xnn_status_success - deinitialization call succeeded.
enum xnn_status xnn_deinitialize(void);
/// Get the microkernel implementation build identifier's data.
///
/// That identifier will be unique for the current set of microkernels implementations.
///
/// @returns A pointer to the current identifier's data.
const void* xnn_experimental_get_build_identifier_data();
/// Get the microkernel implementation build identifier's data size.
///
/// @returns The size in bytes of the identifier's data.
size_t xnn_experimental_get_build_identifier_size();
/// Check whether the given data matches this version's identifier.
///
/// @returns The size in bytes of the identifier's data.
bool xnn_experimental_check_build_identifier(const void* data, size_t size);
/// Subgraph is an abstract representation of a neural network model.
/// Subgraph objects are used to define Values (tensors) and Nodes (operators) comprising the model.
typedef struct xnn_subgraph* xnn_subgraph_t;
/// Create a empty Subgraph object.
///
/// @param external_value_ids - number of Value IDs to reserve for communication with external graph representation.
/// The Subgraph object would avoid creating internal Value IDs in the
/// [0, reserved_value_ids-1] range.
/// @param flags - binary features of the subgraph. No supported flags are currently defined.
/// @param subgraph_out - pointer to the variable that will be initialized with a handle to the Subgraph object upon
/// successful return.
enum xnn_status xnn_create_subgraph(
uint32_t external_value_ids,
uint32_t flags,
xnn_subgraph_t* subgraph_out);
/// Destroy a Subgraph object, as well as Values, and Nodes associated with the subgraph.
///
/// @param subgraph - the Subgraph object to destroy.
enum xnn_status xnn_delete_subgraph(
xnn_subgraph_t subgraph);
#define XNN_VALUE_FLAG_EXTERNAL_INPUT 0x00000001
#define XNN_VALUE_FLAG_EXTERNAL_OUTPUT 0x00000002
#define XNN_VALUE_FLAG_PERSISTENT 0x00000004
#define XNN_INVALID_VALUE_ID UINT32_MAX
/// Type of elements in a Value object.
enum xnn_datatype {
/// Invalid data type. Valid Values never have this datatype.
xnn_datatype_invalid = 0,
/// IEEE754 single-precision floating-point.
xnn_datatype_fp32 = 1,
/// IEEE754 half-precision floating-point.
xnn_datatype_fp16 = 2,
/// Quantized 8-bit signed integer with shared per-Value quantization
/// parameters.
xnn_datatype_qint8 = 3,
/// Quantized 8-bit unsigned integer with shared per-Value quantization
/// parameters.
xnn_datatype_quint8 = 4,
/// Quantized 32-bit signed integer with shared per-Value quantization
/// parameters.
xnn_datatype_qint32 = 5,
/// Quantized 8-bit signed integer with shared per-channel quantization
/// parameters.
xnn_datatype_qcint8 = 6,
/// Quantized 32-bit signed integer with shared per-channel quantization
/// parameters.
xnn_datatype_qcint32 = 7,
/// Quantized 4-bit signed integer with shared per-channel quantization
/// parameters.
xnn_datatype_qcint4 = 8,
/// Dynamically quantized 8-bit signed integer with per-batch quantization
/// parameters.
xnn_datatype_qdint8 = 9,
/// Dynamically quantized 8-bit signed integers packed with their per-row
/// quantization parameters.
xnn_datatype_qpint8 = 10,
/// 32-bit signed integers.
xnn_datatype_int32 = 11,
/// Quantized 4-bit signed integer with shared per-channel-block quantization
/// parameters.
xnn_datatype_qbint4 = 12,
/// IEEE754 single-precision packed floating-point.
xnn_datatype_pfp32 = 13,
/// BFloat16, i.e. the upper 16 bits of a float32.
xnn_datatype_bf16 = 14,
/// Dynamically quantized 8-bit unsigned integer with per-batch quantization
/// parameters.
xnn_datatype_qduint8 = 15,
};
/// Define a tensor-type Value and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Value.
/// @param datatype - type of the tensor elements.
/// @param num_dims - number of dimensions in the shape.
/// @param dims - pointer to an array of @a num_dims shape dimensions. If num_dims is 0, this pointer can be NULL.
/// XNNPACK does not keep any pointers to this array after the function returns.
/// @param data - pointer to static data used for tensor initialization. If the tensor is not statically initialized,
/// this pointer must be is NULL. If non-NULL, the life-time of the static data must exceed the life-time
/// of the Subgraph object, and of any Runtime objects created from the Subgraph.
/// @param external_id - external ID for the Value. The ID must be within the range of reversed Value IDs specified on
/// the Subgraph creation. If the external ID is XNN_INVALID_VALUE_ID, an internal ID will be
/// created for the Value.
/// @param flags - binary features of the Value. Supported values are any combination of XNN_VALUE_FLAG_EXTERNAL_INPUT
/// and XNN_VALUE_FLAG_EXTERNAL_OUTPUT.
/// @param id_out - pointer to the variable that will be initialized with the Value ID upon successful return. If a
/// valid @a external_id was provided, the variable will be initialized with the @a external_id value.
enum xnn_status xnn_define_tensor_value(
xnn_subgraph_t subgraph,
enum xnn_datatype datatype,
size_t num_dims,
const size_t* dims,
const void* data,
uint32_t external_id,
uint32_t flags,
uint32_t* id_out);
/// Define a quantized tensor-type Value and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Value.
/// @param datatype - type of the tensor elements.
/// @param zero_point - offset from zero to subtract from the quantized elements in the Value.
/// @param scale - multiplication factor to convert quantized elements to real representation.
/// @param num_dims - number of dimensions in the shape.
/// @param dims - pointer to an array of @a num_dims shape dimensions. If num_dims is 0, this pointer can be NULL.
/// XNNPACK does not keep any pointers to this array after the function returns.
/// @param data - pointer to static data used for tensor initialization. If the tensor is not statically initialized,
/// this pointer must be is NULL. If non-NULL, the life-time of the static data must exceed the life-time
/// of the Subgraph object, and of any Runtime objects created from the Subgraph.
/// @param external_id - external ID for the Value. The ID must be within the range of reversed Value IDs specified on
/// the Subgraph creation. If the external ID is XNN_INVALID_VALUE_ID, an internal ID will be
/// created for the Value.
/// @param flags - binary features of the Value. Supported values are any combination of XNN_VALUE_FLAG_EXTERNAL_INPUT
/// and XNN_VALUE_FLAG_EXTERNAL_OUTPUT.
/// @param id_out - pointer to the variable that will be initialized with the Value ID upon successful return. If a
/// valid @a external_id was provided, the variable will be initialized with the @a external_id value.
enum xnn_status xnn_define_quantized_tensor_value(
xnn_subgraph_t subgraph,
enum xnn_datatype datatype,
int32_t zero_point,
float scale,
size_t num_dims,
const size_t* dims,
const void* data,
uint32_t external_id,
uint32_t flags,
uint32_t* id_out);
enum xnn_status xnn_define_channelwise_quantized_tensor_value(
xnn_subgraph_t subgraph,
enum xnn_datatype datatype,
const float* scale,
size_t num_dims,
size_t channel_dim,
const size_t* dims,
const void* data,
uint32_t external_id,
uint32_t flags,
uint32_t* id_out);
/// Validate the dimensions, channel_dim, zero point, datatype, and scale of a quantized tensor-type.
///
/// @param datatype - type of the tensor elements.
/// @param zero_point - offset from zero to subtract from the quantized elements in the Value.
/// @param scale - multiplication factor to convert quantized elements to real representation.
/// @param num_dims - number of dimensions in the shape.
/// @param dims - pointer to an array of @a num_dims shape dimensions. If num_dims is 0, this pointer can be NULL.
/// XNNPACK does not keep any pointers to this array after the function returns.
enum xnn_status xnn_validate_quantized_tensor(
enum xnn_datatype datatype,
int32_t zero_point,
float scale,
size_t num_dims,
const size_t* dims);
/// Validate the dimensions, channel_dim, zero point, datatype, and scales of a channelwise quantized tensor-type.
///
/// @param datatype - type of the tensor elements.
/// @param zero_point - offset from zero to subtract from the quantized elements in the Value.
/// @param scale - per-channel multiplication factors to convert quantized elements to real representation.
/// @param num_dims - number of dimensions in the shape.
/// @param channel_dim - index of the channel dimension in the tensor with per-channel quantization parameters.
/// Typically this is the first dimension (dimension #0) of the filter tensors in the Convolution,
/// Deconvolution, and Fully Connected operators and the last dimension of the filter tensors in
/// the Depthwise Convolution operators.
/// @param dims - pointer to an array of @a num_dims shape dimensions. If num_dims is 0, this pointer can be NULL.
/// XNNPACK does not keep any pointers to this array after the function returns.
enum xnn_status xnn_validate_channelwise_quantized_tensor(
enum xnn_datatype datatype,
int32_t zero_point,
const float* scale,
size_t num_dims,
size_t channel_dim,
const size_t* dims);
/// Define a channelwise quantized tensor-type Value and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Value.
/// @param datatype - type of the tensor elements.
/// @param zero_point - offset from zero to subtract from the quantized elements in the Value.
/// @param scale - per-channel multiplication factors to convert quantized elements to real representation.
/// @param num_dims - number of dimensions in the shape.
/// @param channel_dim - index of the channel dimension in the tensor with per-channel quantization parameters.
/// Typically this is the first dimension (dimension #0) of the filter tensors in the Convolution,
/// Deconvolution, and Fully Connected operators and the last dimension of the filter tensors in
/// the Depthwise Convolution operators.
/// @param dims - pointer to an array of @a num_dims shape dimensions. If num_dims is 0, this pointer can be NULL.
/// XNNPACK does not keep any pointers to this array after the function returns.
/// @param data - pointer to static data used for tensor initialization. If the tensor is not statically initialized,
/// this pointer must be is NULL. If non-NULL, the life-time of the static data must exceed the life-time
/// of the Subgraph object, and of any Runtime objects created from the Subgraph.
/// @param external_id - external ID for the Value. The ID must be within the range of reversed Value IDs specified on
/// the Subgraph creation. If the external ID is XNN_INVALID_VALUE_ID, an internal ID will be
/// created for the Value.
/// @param flags - binary features of the Value. Supported values are any combination of XNN_VALUE_FLAG_EXTERNAL_INPUT
/// and XNN_VALUE_FLAG_EXTERNAL_OUTPUT.
/// @param id_out - pointer to the variable that will be initialized with the Value ID upon successful return. If a
/// valid @a external_id was provided, the variable will be initialized with the @a external_id value.
enum xnn_status xnn_define_channelwise_quantized_tensor_value_v2(
xnn_subgraph_t subgraph,
enum xnn_datatype datatype,
int32_t zero_point,
const float* scale,
size_t num_dims,
size_t channel_dim,
const size_t* dims,
const void* data,
uint32_t external_id,
uint32_t flags,
uint32_t* id_out);
/// Define a blockwise quantized tensor-type Value and add it to a Subgraph.
/// @param block_size - size of a block in the tensor with blockwise quantization parameters. Block is defined as
/// number of input channel element per output channel.
/// For Fully connected operators with 2d filters of size [output_channels, input_channels],
/// expecting number of scale values to be = output_channels * (input_channels / block_size).
enum xnn_status xnn_define_blockwise_quantized_tensor_value(
xnn_subgraph_t subgraph,
enum xnn_datatype datatype,
int32_t zero_point,
const uint16_t* scale,
size_t num_dims,
size_t channel_dim,
size_t block_size,
const size_t* dims,
const void* data,
uint32_t external_id,
uint32_t flags,
uint32_t* id_out);
/// Define a dynamically quantized tensor-type Value and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Value.
/// @param datatype - type of the tensor elements.
/// @param num_dims - number of dimensions in the shape.
/// @param num_non_batch_dims - number of non-batch dimensions in the shape. The leading (num_dims - num_non_batch_dims)
/// dimensions will be flattened and treated as batch size. A set of quantization parameters
/// will be calculated for each batch element.
/// @param dims - pointer to an array of @a num_dims shape dimensions. If num_dims is 0, this pointer can be NULL.
/// XNNPACK does not keep any pointers to this array after the function returns.
/// @param external_id - external ID for the Value. The ID must be within the range of reversed Value IDs specified on
/// the Subgraph creation. If the external ID is XNN_INVALID_VALUE_ID, an internal ID will be
/// created for the Value.
/// @param flags - binary features of the Value. No supported flags are currently defined.
/// @param id_out - pointer to the variable that will be initialized with the Value ID upon successful return. If a
/// valid @a external_id was provided, the variable will be initialized with the @a external_id value.
enum xnn_status xnn_define_dynamically_quantized_tensor_value(
xnn_subgraph_t subgraph,
enum xnn_datatype datatype,
size_t num_dims,
size_t num_nonbatch_dims,
const size_t* dims,
uint32_t external_id,
uint32_t flags,
uint32_t* id_out);
/// Type of unary operation
enum xnn_unary_operator {
xnn_unary_invalid = -1,
xnn_unary_convert,
xnn_unary_clamp,
xnn_unary_abs,
xnn_unary_bankers_rounding,
xnn_unary_ceiling,
xnn_unary_elu,
xnn_unary_exp,
xnn_unary_floor,
xnn_unary_gelu,
xnn_unary_hardswish,
xnn_unary_leaky_relu,
xnn_unary_log,
xnn_unary_negate,
xnn_unary_sigmoid,
xnn_unary_square,
xnn_unary_square_root,
xnn_unary_reciprocal_square_root,
xnn_unary_tanh,
// The following operators are experimental and may be removed.
xnn_unary_cube_root,
xnn_unary_cosine,
xnn_unary_sine,
xnn_unary_count_leading_zeros,
xnn_unary_bitwise_not,
xnn_unary_popcount,
xnn_unary_sign,
};
/// Parameters for xnn_define_unary
union xnn_unary_params {
struct {
/// lower bound for clipping output values.
float min;
/// upper bound for clipping output values.
float max;
} clamp;
struct {
/// scale factor for negative input elements.
float alpha;
} elu;
struct {
/// scale factor for negative input elements.
float negative_slope;
} leaky_relu;
};
/// Define a unary operator Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param operator - type of unary operator to define.
/// @param input_id - Value ID for the input tensor. The input tensor must be defined in the @a subgraph.
/// @param output_id - Value ID for the output tensor. The output tensor must be defined in the @a subgraph, and its
/// shape must match the shape of the input tensor.
/// @param params - parameters to be interpreted by the specific operator type.
/// @param flags - binary features of the Node. No supported flags are currently defined.
enum xnn_status xnn_define_unary(
xnn_subgraph_t subgraph,
enum xnn_unary_operator type,
const union xnn_unary_params* params,
uint32_t input_id,
uint32_t output_id,
uint32_t flags);
/// Define a Convert Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param input_id - Value ID for the input tensor. The input tensor must be defined in the @a subgraph.
/// @param output_id - Value ID for the output tensor. The output tensor must be defined in the @a subgraph, and its
/// shape must match the shape of the input tensor.
/// @param flags - binary features of the Convert Node. No supported flags are currently defined.
XNN_DEPRECATED enum xnn_status xnn_define_convert(
xnn_subgraph_t subgraph,
uint32_t input_id,
uint32_t output_id,
uint32_t flags);
/// Define a 2D Convolution Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param input_padding_top - implicit zero-padding above 2D input data. Must be 0 if XNN_FLAG_TENSORFLOW_SAME_PADDING
/// flag is specified.
/// @param input_padding_right - implicit zero-padding to the right of 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param input_padding_bottom - implicit zero-padding below 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param input_padding_left - implicit zero-padding to the left of 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param kernel_height - kernel (filter) height.
/// @param kernel_width - kernel (filter) width.
/// @param subsampling_height - height of subsampling region for convolution output (convolution height stride).
/// @param subsampling_width - width of subsampling region for convolution output (convolution width stride).
/// @param dilation_height - dilation of kernel elements along the height dimension.
/// @param dilation_width - dilation of kernel elements along the width dimension.
/// @param groups - number of convolution groups.
/// @param group_input_channels - number of input channels per group.
/// @param group_output_channels - number of output channels per group.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be a 4D tensor defined in the @a subgraph
/// with [N, IH, IW, groups * group_input_channels] dimensions
/// @param filter_id - Value ID for the filter tensor. The filter tensor must ge a 4D tensor defined in the @a subgraph
/// with [groups * group_output_channels, kernel_height, kernel_width, group_input_channels]
/// dimensions.
/// @param bias_id - Value ID for the bias tensor, or XNN_INVALID_VALUE_ID for a 2D Convolution Node without a bias. If
/// present, the bias tensor must be a 1D tensor defined in the @a subgraph with [groups *
/// group_output_channels] dimensions.
/// @param output_id - Value ID for the output tensor. The output tensor must be a 4D tensor defined in the @a subgraph
/// with [N, OH, OW, groups * group_output_channels] dimensions.
/// @param flags - binary features of the 2D Convolution Node. The only currently supported values is
/// XNN_FLAG_TENSORFLOW_SAME_PADDING.
enum xnn_status xnn_define_convolution_2d(
xnn_subgraph_t subgraph,
uint32_t input_padding_top,
uint32_t input_padding_right,
uint32_t input_padding_bottom,
uint32_t input_padding_left,
uint32_t kernel_height,
uint32_t kernel_width,
uint32_t subsampling_height,
uint32_t subsampling_width,
uint32_t dilation_height,
uint32_t dilation_width,
uint32_t groups,
size_t group_input_channels,
size_t group_output_channels,
float output_min,
float output_max,
uint32_t input_id,
uint32_t filter_id,
uint32_t bias_id,
uint32_t output_id,
uint32_t flags);
/// Define a 2D Deconvolution (Transposed Convolution) Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param padding_top - implicit padding above 2D output data.
/// @param padding_right - implicit padding to the right of 2D output data.
/// @param padding_bottom - implicit padding below 2D output data.
/// @param padding_left - implicit padding to the left of 2D output data.
/// @param adjustment_height - additional elements in the bottom of the 2D output data.
/// @param adjustment_width - additional elements to the right of the 2D output data.
/// @param kernel_height - kernel (filter) height.
/// @param kernel_width - kernel (filter) width.
/// @param upsampling_height - height of upsampling region for deconvolution input (deconvolution height stride).
/// @param upsampling_width - width of upsampling region for deconvolution input (deconvolution width stride).
/// @param dilation_height - dilation of kernel elements along the height dimension.
/// @param dilation_width - dilation of kernel elements along the width dimension.
/// @param groups - number of convolution groups.
/// @param group_input_channels - number of input channels per group.
/// @param group_output_channels - number of output channels per group.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be a 4D tensor defined in the @a subgraph
/// with [N, IH, IW, groups * group_input_channels] dimensions
/// @param filter_id - Value ID for the filter tensor. The filter tensor must ge a 4D tensor defined in the @a subgraph
/// with [groups * group_output_channels, kernel_height, kernel_width, group_input_channels]
/// dimensions.
/// @param bias_id - Value ID for the bias tensor, or XNN_INVALID_VALUE_ID for a 2D Convolution Node without a bias. If
/// present, the bias tensor must be a 1D tensor defined in the @a subgraph with
/// [groups * group_output_channels] dimensions.
/// @param output_id - Value ID for the output tensor. The output tensor must be a 4D tensor defined in the @a subgraph
/// with [N, OH, OW, groups * group_output_channels] dimensions.
/// @param flags - binary features of the 2D Deconvolution Node. No supported flags are currently defined.
enum xnn_status xnn_define_deconvolution_2d(
xnn_subgraph_t subgraph,
uint32_t padding_top,
uint32_t padding_right,
uint32_t padding_bottom,
uint32_t padding_left,
uint32_t adjustment_height,
uint32_t adjustment_width,
uint32_t kernel_height,
uint32_t kernel_width,
uint32_t upsampling_height,
uint32_t upsampling_width,
uint32_t dilation_height,
uint32_t dilation_width,
uint32_t groups,
size_t group_input_channels,
size_t group_output_channels,
float output_min,
float output_max,
uint32_t input_id,
uint32_t filter_id,
uint32_t bias_id,
uint32_t output_id,
uint32_t flags);
/// Define a 2D Depthwise Convolution Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param input_padding_top - implicit zero-padding above 2D input data. Must be 0 if XNN_FLAG_TENSORFLOW_SAME_PADDING
/// flag is specified.
/// @param input_padding_right - implicit zero-padding to the right of 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param input_padding_bottom - implicit zero-padding below 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param input_padding_left - implicit zero-padding to the left of 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param kernel_height - kernel (filter) height.
/// @param kernel_width - kernel (filter) width.
/// @param subsampling_height - height of subsampling region for convolution output (convolution height stride).
/// @param subsampling_width - width of subsampling region for convolution output (convolution width stride).
/// @param dilation_height - dilation of kernel elements along the height dimension.
/// @param dilation_width - dilation of kernel elements along the width dimension.
/// @param depth_multiplier - ratio of output channels to input channels.
/// @param input_channels - number of input channels.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be a 4D tensor defined in the @a subgraph
/// with [N, IH, IW, input_channels] dimensions
/// @param filter_id - Value ID for the filter tensor. The filter tensor must ge a 4D tensor defined in the @a subgraph
/// with [1, kernel_height, kernel_width, input_channels * depth_multiplier] dimensions.
/// @param bias_id - Value ID for the bias tensor, or XNN_INVALID_VALUE_ID for a 2D Depthwise Convolution Node without
/// a bias. If present, the bias tensor must be a 1D tensor defined in the @a subgraph with
/// [input_channels * depth_multiplier] dimensions.
/// @param output_id - Value ID for the output tensor. The output tensor must be a 4D tensor defined in the @a subgraph
/// with [N, OH, OW, input_channels * depth_multiplier] dimensions.
/// @param flags - binary features of the 2D Depthwise Convolution Node. The only currently supported values is
/// XNN_FLAG_TENSORFLOW_SAME_PADDING.
enum xnn_status xnn_define_depthwise_convolution_2d(
xnn_subgraph_t subgraph,
uint32_t input_padding_top,
uint32_t input_padding_right,
uint32_t input_padding_bottom,
uint32_t input_padding_left,
uint32_t kernel_height,
uint32_t kernel_width,
uint32_t subsampling_height,
uint32_t subsampling_width,
uint32_t dilation_height,
uint32_t dilation_width,
uint32_t depth_multiplier,
size_t input_channels,
float output_min,
float output_max,
uint32_t input_id,
uint32_t filter_id,
uint32_t bias_id,
uint32_t output_id,
uint32_t flags);
/// Define a Depth To Space Node 2D and add it to a Subgraph.
///
/// The Depth To Space 2D Node rearranges data from depth into blocks of spatial data (a reverse transform to
/// Space To Depth). For a given input pixel, an output square of pixels with side @a block_size is formed from values
/// in the corresponding number of its channels. The output depth is therefore @a block_size x @a block_size times
/// smaller than that of the input.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param block_size - the size of the spatial block.
/// @param input_id - Value ID for the input tensor. The input tensor must be a 4D tensor defined in the @a subgraph
/// with [N, IH, IW, OC * block_size * block_size] dimensions.
/// @param output_id - Value ID for the output tensor. The output tensor must be a 4D tensor defined in the @a subgraph
/// with [N, IH * block_size, IW * block_size, OC] dimensions.
/// @param flags - binary features of the input_channels Node. No supported flags are currently defined.
enum xnn_status xnn_define_depth_to_space_2d(
xnn_subgraph_t subgraph,
uint32_t block_size,
uint32_t input_id,
uint32_t output_id,
uint32_t flags);
enum xnn_status xnn_define_depth_to_space(
xnn_subgraph_t subgraph,
uint32_t input_id,
uint32_t output_id,
uint32_t block_size,
uint32_t flags);
/// Define a 1D Global Average Pooling Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be a dense tensor with 2 or more dimensions
/// defined in the @a subgraph. Averaging is performed across the second-innermost dimension.
/// @param output_id - Value ID for the output tensor. The output tensor must be a dense tensor with 2 or more
/// dimensions defined in the @a subgraph.
/// @param flags - binary features of the 1D Global Average Pooling Node. The only currently supported value is
/// XNN_FLAG_KEEP_DIMS.
XNN_DEPRECATED enum xnn_status xnn_define_global_average_pooling_1d(
xnn_subgraph_t subgraph,
float output_min,
float output_max,
uint32_t input_id,
uint32_t output_id,
uint32_t flags);
/// Define a 2D Global Average Pooling Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be a dense tensor with 3 or more dimensions
/// defined in the @a subgraph. Averaging is performed across the second- and third-innermost
/// dimensions.
/// @param output_id - Value ID for the output tensor. The output tensor must be a dense tensor with 3 or more
/// dimensions defined in the @a subgraph.
/// @param flags - binary features of the 2D Global Average Pooling Node. The only currently supported value is
/// XNN_FLAG_KEEP_DIMS.
XNN_DEPRECATED enum xnn_status xnn_define_global_average_pooling_2d(
xnn_subgraph_t subgraph,
float output_min,
float output_max,
uint32_t input_id,
uint32_t output_id,
uint32_t flags);
/// Define a 1D Global Sum Pooling Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be a dense tensor with 2 or more dimensions
/// defined in the @a subgraph. Averaging is performed across the second-innermost dimension.
/// @param output_id - Value ID for the output tensor. The output tensor must be a dense tensor with 2 or more
/// dimensions defined in the @a subgraph.
/// @param flags - binary features of the 1D Global Sum Pooling Node. The only currently supported value is
/// XNN_FLAG_KEEP_DIMS.
XNN_DEPRECATED enum xnn_status xnn_define_global_sum_pooling_1d(
xnn_subgraph_t subgraph,
float output_min,
float output_max,
uint32_t input_id,
uint32_t output_id,
uint32_t flags);
/// Define a 2D Global Sum Pooling Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be a dense tensor with 3 or more dimensions
/// defined in the @a subgraph. Averaging is performed across the second- and third-innermost
/// dimensions.
/// @param output_id - Value ID for the output tensor. The output tensor must be a dense tensor with 3 or more
/// dimensions defined in the @a subgraph.
/// @param flags - binary features of the 2D Global Sum Pooling Node. The only currently supported value is
/// XNN_FLAG_KEEP_DIMS.
XNN_DEPRECATED enum xnn_status xnn_define_global_sum_pooling_2d(
xnn_subgraph_t subgraph,
float output_min,
float output_max,
uint32_t input_id,
uint32_t output_id,
uint32_t flags);
/// Define a 2D Average Pooling Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param input_padding_top - implicit zero-padding above 2D input data. Must be 0 if XNN_FLAG_TENSORFLOW_SAME_PADDING
/// flag is specified.
/// @param input_padding_right - implicit zero-padding to the right of 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param input_padding_bottom - implicit zero-padding below 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param input_padding_left - implicit zero-padding to the left of 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param pooling_height - pooling (kernel) height.
/// @param pooling_width - pooling (kernel) width.
/// @param stride_height - displacing of the pooling window in the vertical dimension of the input pixels corresponding
/// to vertically adjacent output pixels.
/// @param stride_width - displacing of the pooling window in the horizontal dimension of the input pixels corresponding
/// to horizontally adjacent output pixels.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be a 4D tensor defined in the @a subgraph
/// with [N, IH, IW, channels] dimensions
/// @param output_id - Value ID for the output tensor. The output tensor must be a 4D tensor defined in the @a subgraph
/// with [N, OH, OW, channels] dimensions.
/// @param flags - binary features of the 2D Average Pooling Node. The only currently supported values is
/// XNN_FLAG_TENSORFLOW_SAME_PADDING.
enum xnn_status xnn_define_average_pooling_2d(
xnn_subgraph_t subgraph,
uint32_t input_padding_top,
uint32_t input_padding_right,
uint32_t input_padding_bottom,
uint32_t input_padding_left,
uint32_t pooling_height,
uint32_t pooling_width,
uint32_t stride_height,
uint32_t stride_width,
float output_min,
float output_max,
uint32_t input_id,
uint32_t output_id,
uint32_t flags);
/// Define a Fully Connected Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be an N-dimensional tensor defined in the
/// @a subgraph. If XNN_FLAG_TENSORFLOW_RESHAPE_2D is not specified, the input tensor must be at least
/// 1D and its last dimension must match the last dimension of the filter tensor. In particular, if
/// input is a 2D tensor, it must have [batch_size, input_channels] dimensions.
/// If XNN_FLAG_TENSORFLOW_RESHAPE_2D is specified, the number of elements in the input tensor must be
/// divisible by the input_channels. The tensor will be first flattened into a 1D tensor of
/// [num_input_elements] dimensions, then reshaped into a 2D tensor of
/// [num_input_elements / input_channels, input_channels] dimensions where num_input_elements is the
/// total number of elements in the input tensor.
/// @param filter_id - Value ID for the filter tensor. The filter tensor must a 2D tensor defined in the @a subgraph.
/// If the XNN_FLAG_TRANSPOSE_WEIGHTS flag is not specified, the filter tensor must have
/// [output_channels, input_channels] dimensions. If the XNN_FLAG_TRANSPOSE_WEIGHTS flag is
/// specified, the filter tensor must have [input_channels, output_channels] dimensions.
/// @param bias_id - Value ID for the bias tensor, or XNN_INVALID_VALUE_ID for a Fully Connected Node without a bias.
/// If present, the bias tensor must be a 1D tensor defined in the @a subgraph with [output_channels]
/// dimensions.
/// @param output_id - Value ID for the output tensor. The output tensor must be defined in the @a subgraph.
/// If XNN_FLAG_TENSORFLOW_RESHAPE_2D is not specified, the output tensor must have the same
/// dimensionality as the input tensor, all its dimensions but the last one must match the
/// corresponding dimensions of the input tensor, and the last dimensions of the output tensor must
/// match the first dimension of the filter tensor. In particular, if input is a 2D tensor, output
/// must be a 2D tensor of [batch_size, output_channels] dimensions.
/// If XNN_FLAG_TENSORFLOW_RESHAPE_2D is specified, output must be a 2D tensor of
/// [num_input_elements / input_channels, output_channels] dimensions where num_input_elements is the
/// total number of elements in the input tensor.
/// @param flags - binary features of the Fully Connected Node. The only currently supported values are
/// XNN_FLAG_TENSORFLOW_RESHAPE_2D and XNN_FLAG_TRANSPOSE_WEIGHTS.
enum xnn_status xnn_define_fully_connected(
xnn_subgraph_t subgraph,
float output_min,
float output_max,
uint32_t input_id,
uint32_t filter_id,
uint32_t bias_id,
uint32_t output_id,
uint32_t flags);
/// Define a Sparse Fully Connected Node and add it to a Subgraph.
///
/// This operator is experimental, and will be removed in the future.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be an N-dimensional tensor defined in the
/// @a subgraph. If XNN_FLAG_TENSORFLOW_RESHAPE_2D is not specified, the input tensor must be at least
/// 1D and its last dimension must match the last dimension of the filter tensor. In particular, if
/// input is a 2D tensor, it must have [batch_size, input_channels] dimensions.
/// If XNN_FLAG_TENSORFLOW_RESHAPE_2D is specified, the number of elements in the input tensor must be
/// divisible by the input_channels. The tensor will be first flattened into a 1D tensor of
/// [num_input_elements] dimensions, then reshaped into a 2D tensor of
/// [num_input_elements / input_channels, input_channels] dimensions where num_input_elements is the
/// total number of elements in the input tensor.
/// @param filter_id - Value ID for the filter tensor. The filter tensor must a 2D tensor defined in the @a subgraph.
/// If the XNN_FLAG_TRANSPOSE_WEIGHTS flag is not specified, the filter tensor must have
/// [output_channels, input_channels] dimensions. If the XNN_FLAG_TRANSPOSE_WEIGHTS flag is
/// specified, the filter tensor must have [input_channels, output_channels] dimensions.
/// @param bias_id - Value ID for the bias tensor, or XNN_INVALID_VALUE_ID for a Fully Connected Node without a bias.
/// If present, the bias tensor must be a 1D tensor defined in the @a subgraph with [output_channels]
/// dimensions.
/// @param output_id - Value ID for the output tensor. The output tensor must be defined in the @a subgraph.
/// If XNN_FLAG_TENSORFLOW_RESHAPE_2D is not specified, the output tensor must have the same
/// dimensionality as the input tensor, all its dimensions but the last one must match the
/// corresponding dimensions of the input tensor, and the last dimensions of the output tensor must
/// match the first dimension of the filter tensor. In particular, if input is a 2D tensor, output
/// must be a 2D tensor of [batch_size, output_channels] dimensions.
/// If XNN_FLAG_TENSORFLOW_RESHAPE_2D is specified, output must be a 2D tensor of
/// [num_input_elements / input_channels, output_channels] dimensions where num_input_elements is the
/// total number of elements in the input tensor.
/// @param flags - binary features of the Fully Connected Node. The only currently supported values are
/// XNN_FLAG_TENSORFLOW_RESHAPE_2D and XNN_FLAG_TRANSPOSE_WEIGHTS.
enum xnn_status xnn_define_fully_connected_sparse(
xnn_subgraph_t subgraph,
float output_min,
float output_max,
uint32_t input_id,
uint32_t filter_id,
uint32_t bias_id,
uint32_t output_id,
uint32_t flags);
/// Define a 2D Max Pooling Node and add it to a Subgraph.
///
/// @param subgraph - a Subgraph object that will own the created Node.
/// @param input_padding_top - implicit zero-padding above 2D input data. Must be 0 if XNN_FLAG_TENSORFLOW_SAME_PADDING
/// flag is specified.
/// @param input_padding_right - implicit zero-padding to the right of 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param input_padding_bottom - implicit zero-padding below 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param input_padding_left - implicit zero-padding to the left of 2D input data. Must be 0 if
/// XNN_FLAG_TENSORFLOW_SAME_PADDING flag is specified.
/// @param pooling_height - pooling (kernel) height.
/// @param pooling_width - pooling (kernel) width.
/// @param stride_height - displacing of the pooling window in the vertical dimension of the input pixels corresponding
/// to vertically adjacent output pixels.
/// @param stride_width - displacing of the pooling window in the horizontal dimension of the input pixels corresponding
/// to horizontally adjacent output pixels.
/// @param dilation_height - dilation of pooling elements along the height dimension.
/// @param dilation_width - dilation of pooling elements along the width dimension.
/// @param output_min - lower bound for clipping output values.
/// @param output_max - upper bound for clipping output values.
/// @param input_id - Value ID for the input tensor. The input tensor must be a 4D tensor defined in the @a subgraph
/// with [N, IH, IW, channels] dimensions
/// @param output_id - Value ID for the output tensor. The output tensor must be a 4D tensor defined in the @a subgraph
/// with [N, OH, OW, channels] dimensions.
/// @param flags - binary features of the 2D Max Pooling Node. The only currently supported values is
/// XNN_FLAG_TENSORFLOW_SAME_PADDING.
enum xnn_status xnn_define_max_pooling_2d(
xnn_subgraph_t subgraph,
uint32_t input_padding_top,
uint32_t input_padding_right,
uint32_t input_padding_bottom,
uint32_t input_padding_left,
uint32_t pooling_height,
uint32_t pooling_width,
uint32_t stride_height,
uint32_t stride_width,