Repository navigation
Expand file tree
/
Copy pathonnxifi.h
More file actions
2003 lines (1925 loc) · 93 KB
/
Copy pathonnxifi.h
File metadata and controls
2003 lines (1925 loc) · 93 KB
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
#ifndef ONNXIFI_H
#define ONNXIFI_H 1
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_WIN32) && defined(_M_IX86)
/* Windows x86 */
#define ONNXIFI_ABI __stdcall
#elif defined(__i386__)
/* Linux x86 */
#define ONNXIFI_ABI __attribute__((__cdecl__))
#else
#define ONNXIFI_ABI
#endif
#ifndef ONNXIFI_PUBLIC
#if defined(__ELF__)
#define ONNXIFI_PUBLIC __attribute__((__visibility__("default")))
#elif defined(__MACH__)
#define ONNXIFI_PUBLIC __attribute__((__visibility__("default")))
#elif defined(_WIN32) && defined(__GNUC__)
#ifdef ONNXIFI_BUILD_LIBRARY
#define ONNXIFI_PUBLIC __attribute__((__dllexport__))
#else
#define ONNXIFI_PUBLIC __attribute__((__dllimport__))
#endif
#elif defined(_WIN32)
#ifdef ONNXIFI_BUILD_LIBRARY
#define ONNXIFI_PUBLIC __declspec(dllexport)
#else
#define ONNXIFI_PUBLIC __declspec(dllimport)
#endif
#else
#define ONNXIFI_PUBLIC
#endif
#endif
#ifndef ONNXIFI_CHECK_RESULT
#if defined(__GNUC__) && (__GNUC__ >= 4)
#define ONNXIFI_CHECK_RESULT __attribute__((__warn_unused_result__))
#elif defined(_MSC_VER) && (_MSC_VER >= 1700)
#define ONNXIFI_CHECK_RESULT _Check_return_
#else
#define ONNXIFI_CHECK_RESULT
#endif
#endif
#include <stddef.h>
#if !defined(ONNXIFI_NO_STDINT_H)
#if defined(_MSC_VER) && (_MSC_VER < 1600)
typedef signed __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef signed __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef signed __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif
#endif /* !defined(ONNXIFI_NO_STDINT_H) */
/**
* Opaque ONNXIFI backend ID.
*
* ONNXIFI backend is a combination of software layer and hardware device used
* to run an ONNX graph. Backend ID uniquely identifies a backend for the life-
* time of the process (i.e. no two hardware devices, software layers, or
* combinations of both can have the same backend ID). Backend ID stays valid
* even if the hardware device used by the backend disconnects from the system.
*/
typedef void* onnxBackendID;
/**
* Opaque ONNXIFI backend handle.
* ONNXIFI backend is a combination of software layer and hardware device used
* to run an ONNX graph.
*/
typedef void* onnxBackend;
/** Opaque ONNXIFI graph handle. */
typedef void* onnxGraph;
/** Opaque ONNXIFI even handle. */
typedef void* onnxEvent;
/** Return code for ONNXIFI functions */
typedef int32_t onnxStatus;
/**
* Type for enumeration values.
*
* The low 32 bits are reserved for standardized ONNXIFI values.
* The high 32 bits are reserved for vendor-specific extensions. Applications
* must check for specific vendor extensions before interpreting these bits.
*/
typedef uint64_t onnxEnum;
/**
* Type for bit fields.
*
* The low 32 bits are reserved for standardized ONNXIFI values.
* The high 32 bits are reserved for vendor-specific extensions. Applications
* must check for specific vendor extensions before interpreting these bits.
*/
typedef uint64_t onnxBitfield;
/**
* Type for pointers or handles for memory buffers.
* This type is intended to work not only for CPU-addressable memory, but also
* for device memory. uint64_t ensures the API can accomodate Vulkan buffers.
*/
typedef uint64_t onnxPointer;
#define ONNXIFI_STATUS_SUCCESS 0x0000
#define ONNXIFI_STATUS_FALLBACK 0x0001
#define ONNXIFI_STATUS_INVALID_ID 0x0101
#define ONNXIFI_STATUS_INVALID_SIZE 0x0102
#define ONNXIFI_STATUS_INVALID_POINTER 0x0103
#define ONNXIFI_STATUS_INVALID_PROTOBUF 0x0104
#define ONNXIFI_STATUS_INVALID_MODEL 0x0105
#define ONNXIFI_STATUS_INVALID_BACKEND 0x0106
#define ONNXIFI_STATUS_INVALID_GRAPH 0x0107
#define ONNXIFI_STATUS_INVALID_EVENT 0x0108
#define ONNXIFI_STATUS_INVALID_STATE 0x0109
#define ONNXIFI_STATUS_INVALID_NAME 0x010A
#define ONNXIFI_STATUS_INVALID_SHAPE 0x010B
#define ONNXIFI_STATUS_INVALID_DATATYPE 0x010C
#define ONNXIFI_STATUS_INVALID_MEMORY_TYPE 0x010D
#define ONNXIFI_STATUS_INVALID_MEMORY_LOCATION 0x010E
#define ONNXIFI_STATUS_INVALID_FENCE_TYPE 0x010F
#define ONNXIFI_STATUS_INVALID_PROPERTY 0x0110
#define ONNXIFI_STATUS_UNSUPPORTED_TAG 0x0201
#define ONNXIFI_STATUS_UNSUPPORTED_VERSION 0x0202
#define ONNXIFI_STATUS_UNSUPPORTED_OPERATOR 0x0203
#define ONNXIFI_STATUS_UNSUPPORTED_ATTRIBUTE 0x0204
#define ONNXIFI_STATUS_UNSUPPORTED_SHAPE 0x0205
#define ONNXIFI_STATUS_UNSUPPORTED_DATATYPE 0x0206
#define ONNXIFI_STATUS_UNSUPPORTED_MEMORY_TYPE 0x0207
#define ONNXIFI_STATUS_UNSUPPORTED_FENCE_TYPE 0x0208
#define ONNXIFI_STATUS_UNSUPPORTED_PROPERTY 0x0209
#define ONNXIFI_STATUS_UNIDENTIFIED_NAME 0x0301
#define ONNXIFI_STATUS_MISMATCHING_SHAPE 0x0302
#define ONNXIFI_STATUS_MISMATCHING_DATATYPE 0x0303
#define ONNXIFI_STATUS_NO_SYSTEM_MEMORY 0x0401
#define ONNXIFI_STATUS_NO_DEVICE_MEMORY 0x0402
#define ONNXIFI_STATUS_NO_SYSTEM_RESOURCES 0x0403
#define ONNXIFI_STATUS_NO_DEVICE_RESOURCES 0x0404
#define ONNXIFI_STATUS_BACKEND_UNAVAILABLE 0x0405
#define ONNXIFI_STATUS_INTERNAL_ERROR 0x0406
/**
* State of an ONNXIFI event object.
*
* Possible values:
* ONNXIFI_EVENT_STATE_INVALID
* ONNXIFI_EVENT_STATE_NONSIGNALLED
* ONNXIFI_EVENT_STATE_SIGNALLED
*/
typedef int32_t onnxEventState;
/**
* State for an invalid onnxEvent.
*/
#define ONNXIFI_EVENT_STATE_INVALID 0
/**
* Non-signalled onnxEvent state.
* onnxInitEvent creates events in non-signalled state.
*/
#define ONNXIFI_EVENT_STATE_NONSIGNALLED 0x16BD
/**
* Signalled onnxEvent state.
* onnxSignalEvent changes event state to signalled.
*/
#define ONNXIFI_EVENT_STATE_SIGNALLED 0x3395
/** Special-purpose accelerator for neural network */
#define ONNXIFI_DEVICE_TYPE_NPU 0x01
/** Digital signal processor */
#define ONNXIFI_DEVICE_TYPE_DSP 0x02
/** Graphics accelerator */
#define ONNXIFI_DEVICE_TYPE_GPU 0x04
/** General-purpose central processor */
#define ONNXIFI_DEVICE_TYPE_CPU 0x08
/** Field-programmable gate array */
#define ONNXIFI_DEVICE_TYPE_FPGA 0x10
/**
* Heterogeneous backend whichinternally arbitrates or distributes work between
* multiple device types.
*/
#define ONNXIFI_DEVICE_TYPE_HETEROGENEOUS 0x20
/**
* The backend supports multi-threaded access to ONNXIFI backend, graph, and
* event objects. E.g. onnxInitGraph can be called on a different thread than
* onnxInitBackend.
*
* If this capability it not indicated, ONNXIFI backend, graph, and event
* objects that relate to the backend must always be used on the same thread
* where the backend object was initialized.
*/
#define ONNXIFI_CAPABILITY_THREAD_SAFE 0x01
/**
* The backend supports ONNX graphs with symbolic variables in the outer
* shape dimension (batch size), using TensorShapeProto.dim_param for
* ModelProto.graph.input.type.shape or ModelProto.graph.output.type.shape.
*
* The exact numerical value of the of all input and output tensors must be specified
* in the onnxSetGraphIO call(s).
*/
#define ONNXIFI_CAPABILITY_SYMBOLIC_BATCH_SIZE 0x02
/**
* The backend supports ONNX graphs with symbolic variables in the all
* shape dimensions, using TensorShapeProto.dim_param for
* ModelProto.graph.input.type.shape or ModelProto.graph.output.type.shape.
*
* Backends with this capability also MUST support
* ONNXIFI_CAPABILITY_SYMBOLIC_BATCH_SIZE capability.
*
* The exact numerical shape of all input and output tensors must be specified
* in the onnxSetGraphIO call(s).
*/
#define ONNXIFI_CAPABILITY_SYMBOLIC_SIZE_TENSORS 0x04
/**
* The backend supports ONNX graphs with data-dependent outer shape dimension
* (batch size) of graph outputs. The ONNX graph would specify unknown outer
* shape dimension (batch size) using symbolic variables, so this capability
* requires ONNXIFI_CAPABILITY_SYMBOLIC_BATCH_SIZE support.
*
* For outputs with data-dependent outer shape dimension (batch size) the value
* specified in onnxSetGraphIO call is interpreted as the upper limit. The exact
* numerical batch size of the output can be retrieved by attaching a Shape
* operator to the tensor with data-dependent shape and reading its output
* through ONNXIFI.
*/
#define ONNXIFI_CAPABILITY_VARIABLE_BATCH_SIZE 0x08
/**
* The backend supports ONNX graphs with data-dependent output shapes.
* The ONNX graph would specify unknown output shapes using symbolic variables,
* so this capability requires ONNXIFI_CAPABILITY_SYMBOLIC_SIZE_TENSORS support.
*
* Backends with this capability also MUST support
* ONNXIFI_CAPABILITY_VARIABLE_BATCH_SIZE capability.
*
* For outputs with data-dependent shapes the shape specified in onnxSetGraphIO
* call is interpreted as the upper limit. The exact numerical shape of the
* output can be retrieved by attaching a Shape operator to the tensor with
* data-dependent shape and reading its output through ONNXIFI.
*/
#define ONNXIFI_CAPABILITY_VARIABLE_SIZE_OUTPUTS 0x10
/**
* The backend uses a hot-pluggable device, and can be disconnected at any time.
*
* If the underlying device disconnects from the system, subsequent operations
* with the backend, or objects created on the backend, will fail with
* ONNXIFI_STATUS_BACKEND_UNAVAILABLE status code.
*/
#define ONNXIFI_CAPABILITY_HOT_PLUGGABLE 0x20
/**
* Type of the backend information.
*
* Possible values:
* ONNXIFI_BACKEND_ONNXIFI_VERSION
* ONNXIFI_BACKEND_NAME
* ONNXIFI_BACKEND_VENDOR
* ONNXIFI_BACKEND_VERSION
* ONNXIFI_BACKEND_EXTENSIONS
* ONNXIFI_BACKEND_DEVICE
* ONNXIFI_BACKEND_DEVICE_TYPE
* ONNXIFI_BACKEND_ONNX_IR_VERSION
* ONNXIFI_BACKEND_OPSET_VERSION
* ONNXIFI_BACKEND_CAPABILITIES
* ONNXIFI_BACKEND_INIT_PROPERTIES
* ONNXIFI_BACKEND_MEMORY_TYPES
* ONNXIFI_BACKEND_GRAPH_INIT_PROPERTIES
* ONNXIFI_BACKEND_SYNCHRONIZATION_TYPES
* ONNXIFI_BACKEND_MEMORY_SIZE
* ONNXIFI_BACKEND_MAX_GRAPH_SIZE
* ONNXIFI_BACKEND_MAX_GRAPH_COUNT
* ONNXIFI_BACKEND_MACS_FP32
* ONNXIFI_BACKEND_MACS_FP16
* ONNXIFI_BACKEND_MEMORY_BANDWIDTH
* ONNXIFI_BACKEND_CPU_MEMORY_READ_BANDWIDTH
* ONNXIFI_BACKEND_CPU_MEMORY_WRITE_BANDWIDTH
* ONNXIFI_BACKEND_PCI_BUS_ID
* ONNXIFI_BACKEND_PCI_DEVICE_ID
* ONNXIFI_BACKEND_PCI_DOMAIN_ID
* ONNXIFI_BACKEND_DIRECTX_ID
* ONNXIFI_BACKEND_CUDA_INDEX
* ONNXIFI_BACKEND_OPENCL_PLATFORM_ID
* ONNXIFI_BACKEND_OPENCL_DEVICE_ID
*/
typedef int32_t onnxBackendInfo;
/**
* Major and minor version of ONNXIFI specification implemented by the backend.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: uint64_t.
* The high 32 bits specify the major version.
* The low 32 bits specify the minor version.
*
* Possible values:
* UINT64_C(0x0000000100000000) for ONNXIFI 1.0
*/
#define ONNXIFI_BACKEND_ONNXIFI_VERSION 0
/**
* Marketing name of the backend (excluding the vendor name).
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* This string MUST be in UTF-8 encoding and NOT locale-sensitive.
*
* Value type: char[], e.g.:
* "Caffe2"
* "Glow"
*/
#define ONNXIFI_BACKEND_NAME 1
/**
* Name of the backend vendor.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* This string MUST be in UTF-8 encoding and NOT locale-sensitive.
*
* Value type: char[], e.g.:
* "Facebook"
* "Marat Dukhan"
*/
#define ONNXIFI_BACKEND_VENDOR 2
/**
* Version of the backend software. Exact format is vendor-specific, but MUST be
* unique for the software release.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* This string MUST be in US-ASCII encoding and NOT locale-sensitive.
*
* Value type: char[], e.g.:
* "1.2.3"
* "1.2.3.0"
* "1.2.3-db3a4439d233276e25681fb4735b7f8e674dda65"
*/
#define ONNXIFI_BACKEND_VERSION 3
/**
* Space-separated list of vendor- or device-specific extensions supported on
* this backend.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* This string MUST be in US-ASCII encoding and NOT locale-sensitive.
*
* Value type: char[], e.g.:
* ""
* "onnx_clone_graph"
* "onnx_clone_graph fb_maskrcnn"
*/
#define ONNXIFI_BACKEND_EXTENSIONS 4
/**
* Descriptive name of the device (i.e. CPU, GPU, DSP, or NPU model).
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* This string MUST be in UTF-8 encoding and NOT locale-sensitive.
*
* Value type: char[], e.g.:
* "nnDuino 123"
*/
#define ONNXIFI_BACKEND_DEVICE 5
/**
* Type of the device.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: onnxEnum.
* Possible values:
* ONNXIFI_DEVICE_TYPE_NPU
* ONNXIFI_DEVICE_TYPE_DSP
* ONNXIFI_DEVICE_TYPE_GPU
* ONNXIFI_DEVICE_TYPE_CPU
* ONNXIFI_DEVICE_TYPE_FPGA
* ONNXIFI_DEVICE_TYPE_HETEROGENEOUS
*/
#define ONNXIFI_BACKEND_DEVICE_TYPE 6
/**
* List of supported ONNX IR versions.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: char[], e.g.:
* "3" (IR version in ONNX 1.0)
*
* Possible values: space-separated list of supported ONNX IR versions,
* represented as decimal integers. ONNX IR versions must match values
* in ONNX Version enum.
*/
#define ONNXIFI_BACKEND_ONNX_IR_VERSION 7
/**
* List of supported operator set domains and maximum supported operator set
* version for each domain.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: char[], e.g.:
* "ai.onnx:1" (only operators in version 1 of default ONNX operator set)
* "ai.onnx:7" (operators up to version 7 of default ONNX operator set)
* "org.pytorch:2 ai.onnx:6 ai.facebook:1"
*
* Possible values: space-separated list of domain:max_version pairs where
* domain corresponds to OperatorSetIdProto.domain and max_version
* corresponds to the maximum value of OperatorSetIdProto.version supported
* by the backend for this domain. The backend MUST support all previous
* operator set versions as well.
*/
#define ONNXIFI_BACKEND_OPSET_VERSION 8
/**
* Optional features supported by the backend.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: onnxBitfield.
* Possible values: any combination of the following flags:
* ONNXIFI_CAPABILITY_THREAD_SAFE
* ONNXIFI_CAPABILITY_SYMBOLIC_BATCH_SIZE
* ONNXIFI_CAPABILITY_SYMBOLIC_SIZE_TENSORS
* ONNXIFI_CAPABILITY_VARIABLE_BATCH_SIZE
* ONNXIFI_CAPABILITY_VARIABLE_SIZE_OUTPUTS
* ONNXIFI_CAPABILITY_HOT_PLUGGABLE
* or any vendor-specific flags in the high 32 bits of the bit field.
*/
#define ONNXIFI_BACKEND_CAPABILITIES 10
/**
* Auxiliary initialization properties supported by the backend.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: onnxBitfield.
* Possible values: any combination of vendor-specific flags in high 32 bits of
* the bit field.
*/
#define ONNXIFI_BACKEND_INIT_PROPERTIES 11
/**
* Memory types supported for graph inputs and outputs.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: onnxBitfield.
* Possible values are any combination of the following flags:
* ONNXIFI_MEMORY_TYPE_CPU (always supported)
* ONNXIFI_MEMORY_TYPE_CUDA_BUFFER
* ONNXIFI_MEMORY_TYPE_OPENCL_BUFFER
* ONNXIFI_MEMORY_TYPE_OPENGLES_TEXTURE_2D
* ONNXIFI_MEMORY_TYPE_D3D_RESOURCE
* or any vendor-specific flags in the high 32 bits of the bit field.
*/
#define ONNXIFI_BACKEND_MEMORY_TYPES 12
/**
* Auxiliary initialization properties supported by graphs on the backend.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: onnxBitfield.
* Possible values: any combination of vendor-specific flags in high 32 bits of
* the bit field.
*/
#define ONNXIFI_BACKEND_GRAPH_INIT_PROPERTIES 13
/**
* Memory synchronization primitives supported for graph inputs and outputs.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Possible values are any combination of the following flags:
* ONNXIFI_SYNCHRONIZATION_EVENT (onnxEvent, always supported)
* ONNXIFI_SYNCHRONIZATION_IMPLICIT
* or any vendor-specific flags in the high 32 bits of the bit field.
*/
#define ONNXIFI_BACKEND_SYNCHRONIZATION_TYPES 14
/**
* Maximum amount of memory, in bytes, available to the use by the backend.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_MEMORY_SIZE 20
/**
* Maximum size of network parameters, in bytes.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_MAX_GRAPH_SIZE 21
/**
* Maximum number of independent network graphs supported by the backend.
*
* Since ONNXIFI 1.0, backends MUST support this information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_MAX_GRAPH_COUNT 22
/**
* Number of FP32 multiply-accumulate operations per second delivered by the
* backend.
*
* Since ONNXIFI 1.0, backends are recommended, but not required to support this
* information query.
*
* Value type: uint64_t.
* If the backend does not support FP32 computation, the value MUST be 0.
*/
#define ONNXIFI_BACKEND_MACS_FP32 30
/**
* Number of FP16 multiply-accumulate operations per second delivered by the
* backend.
*
* Since ONNXIFI 1.0, backends are recommended, but not required to support this
* information query.
*
* Value type: uint64_t.
* If the backend does not support FP16 computation, the value MUST be 0.
*/
#define ONNXIFI_BACKEND_MACS_FP16 31
/**
* Bandwidth, in bytes per second, of the global memory specific to the backend
* device.
*
* Since ONNXIFI 1.0, backends are recommended, but not required to support this
* information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_MEMORY_BANDWIDTH 35
/**
* Bandwidth, in bytes per second, of transferring data from cacheable
* CPU-allocated memory to the backend device.
*
* Since ONNXIFI 1.0, backends are recommended, but not required to support this
* information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_CPU_MEMORY_READ_BANDWIDTH 36
/**
* Bandwidth, in bytes per second, of transferring data to cacheable
* CPU-allocated memory from the backend device.
*
* Since ONNXIFI 1.0, backends are recommended, but not required to support this
* information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_CPU_MEMORY_WRITE_BANDWIDTH 37
/**
* PCI bus ID of the backend device.
*
* Since ONNXIFI 1.0, backends are recommended, but not required to support this
* information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_PCI_BUS_ID 40
/**
* PCI device ID of the backend device.
*
* Since ONNXIFI 1.0, backends are recommended, but not required to support this
* information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_PCI_DEVICE_ID 41
/**
* PCI domain/function ID of the backend device.
*
* Since ONNXIFI 1.0, backends are recommended, but not required to support this
* information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_PCI_DOMAIN_ID 42
/**
* DirectX ID of the backend device.
*
* This is the value that would be returned by ID3D12Device::GetAdapterLuid()
* for the hardware device used by the backend.
*
* Since ONNXIFI 1.0, DXGI-based backends are recommended, but not required to
* support this information query.
*
* Value type: LUID (8 bytes).
*/
#define ONNXIFI_BACKEND_DIRECTX_ID 43
/**
* CUDA index of the backend device.
*
* Since ONNXIFI 1.0, CUDA-based backends are recommended, but not required to
* support this information query.
*
* Value type: uint64_t.
*/
#define ONNXIFI_BACKEND_CUDA_INDEX 44
/**
* OpenCL platform ID for the backend device.
* This platform ID is guaranteed to remain valid for the lifetime of ONNXIFI
* objects related to the same ONNXIFI backend (backend ID, backend, graph,
* event).
*
* Since ONNXIFI 1.0, OpenCL-based backends are recommended, but not required to
* support this information query.
*
* Value type: cl_platform_id.
*/
#define ONNXIFI_BACKEND_OPENCL_PLATFORM_ID 45
/**
* OpenCL device ID for the backend device.
* This device ID is guaranteed to remain valid for the lifetime of ONNXIFI
* objects related to the same ONNXIFI backend (backend ID, backend, graph,
* event).
*
* Since ONNXIFI 1.0, OpenCL-based backends are recommended, but not required to
* support this information query.
*
* Value type: cl_device_id.
*/
#define ONNXIFI_BACKEND_OPENCL_DEVICE_ID 46
/* Note: the data type values match ONNX TensorProto.DataType enum */
#define ONNXIFI_DATATYPE_UNDEFINED 0
#define ONNXIFI_DATATYPE_FLOAT16 10
#define ONNXIFI_DATATYPE_FLOAT32 1
#define ONNXIFI_DATATYPE_FLOAT64 11
#define ONNXIFI_DATATYPE_INT8 3
#define ONNXIFI_DATATYPE_INT16 5
#define ONNXIFI_DATATYPE_INT32 6
#define ONNXIFI_DATATYPE_INT64 7
#define ONNXIFI_DATATYPE_UINT8 2
#define ONNXIFI_DATATYPE_UINT16 4
#define ONNXIFI_DATATYPE_UINT32 12
#define ONNXIFI_DATATYPE_UINT64 13
#define ONNXIFI_DATATYPE_COMPLEX64 14
#define ONNXIFI_DATATYPE_COMPLEX128 15
#define ONNXIFI_DATATYPE_BFLOAT16 16
/** Cacheable CPU memory */
#define ONNXIFI_MEMORY_TYPE_CPU 0
/** CUDA memory buffer (allocated via cudaMalloc/cuMalloc). */
#define ONNXIFI_MEMORY_TYPE_CUDA_BUFFER 1
/** OpenCL cl_mem object for a buffer or sub-buffer. */
#define ONNXIFI_MEMORY_TYPE_OPENCL_BUFFER 2
/** OpenGL ES 2.0+ 2D Texture. */
#define ONNXIFI_MEMORY_TYPE_OPENGLES_TEXTURE_2D 4
/** Direct3D resource. */
#define ONNXIFI_MEMORY_TYPE_D3D_RESOURCE 8
/**
* Terminates the list of auxiliary backend initialization properties passed to
* onnxInitBackend.
*/
#define ONNXIFI_BACKEND_PROPERTY_NONE 0
/**
* Optimization target for graphs initialized on the backend.
*
* Possible values:
* ONNXIFI_OPTIMIZATION_HIGH_THROUGHPUT
* ONNXIFI_OPTIMIZATION_LOW_LATENCY
* ONNXIFI_OPTIMIZATION_LOW_POWER
* ONNXIFI_OPTIMIZATION_LOW_DELAY
*/
#define ONNXIFI_BACKEND_PROPERTY_OPTIMIZATION 1
/**
* Logging verbosity level for the backend.
*
* If this property is not specified during initialization, the backend should
* assume ONNXIFI_LOG_LEVEL_WARNING logging verbosity level.
*
* Possible values:
* ONNXIFI_LOG_LEVEL_ERROR
* ONNXIFI_LOG_LEVEL_WARNING
* ONNXIFI_LOG_LEVEL_INFO
* ONNXIFI_LOG_LEVEL_DEBUG
*/
#define ONNXIFI_BACKEND_PROPERTY_LOG_LEVEL 2
/**
* CUDA stream to be used by the backend.
* CUDA stream must be created on the CUDA device used by the ONNXIFI backend.
* Users can query which CUDA device is used by the ONNXIFI backend by calling
* onnxGetBackendInfo with ONNXIFI_BACKEND_CUDA_INDEX info type.
*
* If this property is not specified during initialization, the backend can
* create a new CUDA stream for the device, or use a default CUDA stream.
*
* Possible values: cudaStream_t or CUstream object, cast to uint64_t.
*/
#define ONNXIFI_BACKEND_CUDA_STREAM 4
/**
* OpenCL context to be used by the backend.
* The context must be created with the OpenCL device ID and the OpenCL platform
* ID used by the ONNXIFI backend. Users can query which OpenCL device ID and
* OpenCL platform ID are used by the ONNXIFI backend by calling
* onnxGetBackendInfo with ONNXIFI_BACKEND_OPENCL_PLATFORM_ID
* and ONNXIFI_BACKEND_OPENCL_DEVICE_ID info types.
*
* If this property is not specified during initialization, the backend will
* create a new OpenCL context for the device.
*
* Possible values: cl_context object, cast to uint64_t.
*/
#define ONNXIFI_BACKEND_OPENCL_CONTEXT 8
/**
* Terminates the list of auxiliary graph initialization properties passed to
* onnxInitGraph.
*/
#define ONNXIFI_GRAPH_PROPERTY_NONE 0
/**
* Optimize graph representation and compilation for highest throughput.
*/
#define ONNXIFI_OPTIMIZATION_HIGH_THROUGHPUT 0
/**
* Optimize graph representation and compilation for lowest latency.
*/
#define ONNXIFI_OPTIMIZATION_LOW_LATENCY 1
/**
* Optimize graph representation and compilation for lowest power consumption.
*/
#define ONNXIFI_OPTIMIZATION_LOW_POWER 2
/**
* Optimize graph representation and compilation for lowest delay until first
* result.
*/
#define ONNXIFI_OPTIMIZATION_LOW_DELAY 3
/**
* Log events which caused a failure in an ONNXIFI function call.
*/
#define ONNXIFI_LOG_LEVEL_ERROR 4
/**
* Log events in ONNXIFI_LOG_LEVEL_ERROR and events which caused
* a performance, accuracy, or quality of service degradation in a backend.
* Enabling this logging level SHOULD NOT have a measurable effect on
* performance.
*/
#define ONNXIFI_LOG_LEVEL_WARNING 3
/**
* Log events in ONNXIFI_LOG_LEVEL_WARNING and high-level status information
* about operation of a backend. Enabling this logging level MAY cause a small
* degradation in performance.
*/
#define ONNXIFI_LOG_LEVEL_INFO 2
/**
* Log events in ONNXIFI_LOG_LEVEL_INFO and detailed status information about
* operations of a backend. Enabling this logging level MAY cause a serious
* degradation in performance.
*/
#define ONNXIFI_LOG_LEVEL_DEBUG 1
/**
* Tag for version 1 of tensor descriptor structure (onnxTensorDescriptorV1).
*
* The tag is unique for this version. If ONNXIFI introduce a new version of
* the tensor descriptor structure in the future, it will get a new tag value.
*/
#define ONNXIFI_TAG_TENSOR_DESCRIPTOR_V1 0x43DFBF69
typedef struct onnxTensorDescriptorV1 {
/**
* 32-bit tag needed to distinguish different versions of a tensor descriptor
* structure. In the onnxTensorDescriptorV1 structure, the tag MUST be set to
* ONNXIFI_TAG_TENSOR_DESCRIPTOR_V1. If ONNXIFI introduce a new version of the
* tensor descriptor structure in the future, it WILL have 32-bit tag with a
* different value as the first member of the structure.
*
* ONNXIFI implementations MUST validate tag before accessing any other
* members of the structure.
*/
int32_t tag;
/**
* Name of the blob corresponding to this tensor in the ONNX model. The name
* must exactly match the ValueInfoProto.name of one of the
* ModelProto.graph.input or ModelProto.graph.output
*/
const char* name;
/**
* Data type of the elements in the tensor.
*
* Possible values:
* ONNXIFI_DATATYPE_FLOAT16
* ONNXIFI_DATATYPE_FLOAT32
* ONNXIFI_DATATYPE_FLOAT64
* ONNXIFI_DATATYPE_INT8
* ONNXIFI_DATATYPE_INT16
* ONNXIFI_DATATYPE_INT32
* ONNXIFI_DATATYPE_INT64
* ONNXIFI_DATATYPE_UINT8
* ONNXIFI_DATATYPE_UINT16
* ONNXIFI_DATATYPE_UINT32
* ONNXIFI_DATATYPE_UINT64
* ONNXIFI_DATATYPE_COMPLEX64
* ONNXIFI_DATATYPE_COMPLEX128
*/
onnxEnum dataType;
/**
* Type of memory that stores the tensor.
*
* ONNXIFI_MEMORY_TYPE_CPU memory type is always supported by the backend, but
* other memory types are optional. The use MUST call onnxGetBackendInfo with
* ONNXIFI_BACKEND_MEMORY_TYPES to check if a particular memory type is
* supported before using it.
*
* If the memory type is different than ONNXIFI_MEMORY_TYPE_CPU, it must be
* allocated on the same device as the backend.
*
* Possible values:
* ONNXIFI_MEMORY_TYPE_CPU (always supported)
* ONNXIFI_MEMORY_TYPE_CUDA_BUFFER (support is optional)
* ONNXIFI_MEMORY_TYPE_OPENCL_BUFFER (support is optional)
* ONNXIFI_MEMORY_TYPE_OPENGLES_TEXTURE_2D (support is optional)
* ONNXIFI_MEMORY_TYPE_D3D_RESOURCE (support is optional)
*/
onnxEnum memoryType;
/**
* Number of dimensions in the tensor.
* For a scalar, the number of dimensions is 0.
*/
uint32_t dimensions;
/**
* Dimensions of the tensor.
* For a scalar, this pointer can be NULL.
*/
const uint64_t* shape;
/**
* Pointers to tensor data.
*
* Interpretation depends on memoryType:
* - ONNXIFI_MEMORY_TYPE_CPU: buffer is a valid pointer to CPU memory.
* - ONNXIFI_MEMORY_TYPE_CUDA_BUFFER: buffer is a valid pointer to CUDA
* device memory, allocated via cudaMalloc or cuMalloc. CUDA device memory
* must be allocated on the same device as the backend.
* - ONNXIFI_MEMORY_TYPE_OPENCL_BUFFER: buffer is a cl_mem handle for an
* OpenCL buffer or a sub-buffer. cl_mem object must be allocated on the
* same OpenCL context as the backend. The context must be specified via
* ONNXIFI_BACKEND_OPENCL_CONTEXT initialization property to
* onnxInitBackend.
* - ONNXIFI_MEMORY_TYPE_OPENGLES_TEXTURE_2D: buffer is a name of a 2D
* texture created by glGenTextures. The texture must be allocated on the
* same device as the backend.
* - ONNXIFI_MEMORY_TYPE_D3D_RESOURCE: TBD
*/
onnxPointer buffer;
} onnxTensorDescriptorV1;
/**
* Synchronization using ONNXIFI event object (onnxEvent).
*/
#define ONNXIFI_SYNCHRONIZATION_EVENT 0
/**
* Implicit synchronization of inputs and outputs access with the caller.
* The details are backend-specific, and may involve extra parameters passed
* during backend initialization.
*
* Examples:
* - CUDA-based backends could implicitly synchronize with the caller through
* the use of the same CUDA stream.
* - OpenCL-based backends could implicitly synchronize with the caller through
* the use of the same in-order OpenCL command queue.
*/
#define ONNXIFI_SYNCHRONIZATION_IMPLICIT 2
/**
* Tag for version 1 of memory fence structure (onnxMemoryFenceV1).
*
* The tag is unique for this version. If ONNXIFI introduce a new version of
* the memory fence structure in the future, it will get a new tag value.
*/
#define ONNXIFI_TAG_MEMORY_FENCE_V1 0x23E08AAB
typedef struct onnxMemoryFenceV1 {
/**
* 32-bit tag needed to distinguish different versions of a memory fence
* structure. In the onnxMemoryFenceV1 structure, the tag MUST be set to
* ONNXIFI_TAG_MEMORY_FENCE_V1. If ONNXIFI introduce a new version of the
* memory fence structure in the future, it WILL have 32-bit tag with a
* different value as the first member of the structure.
*
* ONNXIFI implementations MUST validate tag before accessing any other
* members of the structure.
*/
int32_t tag;
/**
* Type of memory synchronization primitive.
*
* Possible values:
* ONNXIFI_SYNCHRONIZATION_EVENT (onnxEvent, always supported)
* ONNXIFI_SYNCHRONIZATION_IMPLICIT
*/
onnxEnum type;
union {
/**
* Handle for a single-shot ONNXIFI event used as a synchronization
* primitive. Event for the input fence must be created by the caller to
* onnxRunGraph. Event for the output fence is created by implementation of
* onnxRunGraph, and stored into the output memory fence structure before
* onnxRunGraph returns.
*/
onnxEvent event;
};
} onnxMemoryFenceV1;
/* Function pointer declarations for dynamic loading */
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxGetBackendIDsFunction)(
onnxBackendID* backendIDs,
size_t* numBackends);
typedef onnxStatus
(ONNXIFI_ABI* onnxReleaseBackendIDFunction)(
onnxBackendID backendID);
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxGetBackendInfoFunction)(
onnxBackendID backendID,
onnxBackendInfo infoType,
void* infoValue,
size_t* infoValueSize);
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxGetBackendCompatibilityFunction)(
onnxBackendID backendID,
size_t onnxModelSize,
5581
div>
const void* onnxModel);
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxInitBackendFunction)(
onnxBackendID backendID,
const uint64_t* auxPropertiesList,
onnxBackend* backend);
typedef onnxStatus
(ONNXIFI_ABI* onnxReleaseBackendFunction)(
onnxBackend backend);
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxInitEventFunction)(
onnxBackend backend,
onnxEvent* event);
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxSignalEventFunction)(
onnxEvent event);
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxGetEventStateFunction)(
onnxEvent event,
onnxEventState* state);
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxWaitEventFunction)(
onnxEvent event);
typedef onnxStatus
(ONNXIFI_ABI* onnxReleaseEventFunction)(
onnxEvent event);
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxInitGraphFunction)(
onnxBackend backend,
const uint64_t* auxPropertiesList,
size_t onnxModelSize,
const void* onnxModel,
uint32_t weightsCount,
const onnxTensorDescriptorV1* weightDescriptors,
onnxGraph* graph);
typedef ONNXIFI_CHECK_RESULT onnxStatus
(ONNXIFI_ABI* onnxSetGraphIOFunction)(
onnxGraph graph,
uint32_t inputsCount,