xref: /aosp_15_r20/external/executorch/backends/vulkan/serialization/schema.fbs (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1// Copyright (c) Meta Platforms, Inc. and affiliates.
2
3namespace vkgraph;
4
5// Update after any BC breaking changes.
6file_identifier "VK00";
7
8table OperatorCall {
9  node_id:uint;
10  name:string;
11  args:[int];
12}
13
14enum VkDataType : byte {
15  BOOL = 0,
16  UINT8 = 1,
17  INT8 = 2,
18  INT32 = 3,
19  FLOAT16 = 4,
20  FLOAT32 = 5,
21}
22
23// Describes what kind of GPU resource should be used to represent a tensor. The
24// int values assigned to each entry must match the corresponding entry in
25// api::StorageType.
26enum VkStorageType : ubyte {
27  BUFFER = 0,
28  TEXTURE_3D = 1,
29  TEXTURE_2D = 2,
30  DEFAULT_STORAGE = 255,
31}
32
33// Describes how memory should be laid out in GPU memory. See the GPUMemoryLayout
34// enum class in PyTorch Vulkan for more details. The int values assigned to each
35// entry must match the corresponding entry in utils::GPUMemoryLayout.
36enum VkMemoryLayout : ubyte {
37  TENSOR_WIDTH_PACKED = 0,
38  TENSOR_HEIGHT_PACKED = 1,
39  TENSOR_CHANNELS_PACKED = 2,
40  DEFAULT_LAYOUT = 255,
41}
42
43table VkTensor {
44  // Type of the tensor elements.
45  datatype:VkDataType;
46  // Shape dimensions.
47  dims:[uint];
48  // Index to the program's constant data. Negative indicates tensor is non-constant.
49  constant_id:int;
50  // Index to the shared memory object. Negative indicates the tensor doesn't share memory.
51  mem_obj_id:int;
52  // Storage type that should be used to represent this tensor
53  storage_type:VkStorageType = DEFAULT_STORAGE;
54  // Memory layout that should be used to represent this tensor
55  memory_layout:VkMemoryLayout = DEFAULT_LAYOUT;
56}
57
58table Null {}
59
60table Int {
61  int_val:long;
62}
63
64table Bool {
65  bool_val:bool;
66}
67
68table Double {
69  double_val:double;
70}
71
72table String {
73  string_val:string;
74}
75
76table IntList {
77  items:[long];
78}
79
80table DoubleList {
81  items:[double];
82}
83
84table BoolList {
85  items:[bool];
86}
87
88table ValueList {
89  items:[int];
90}
91
92table SymInt {
93  value:int;
94}
95
96union GraphTypes {
97  Null,
98  Int,
99  Double,
100  Bool,
101  VkTensor,
102  IntList,
103  DoubleList,
104  BoolList,
105  ValueList,
106  String,
107  SymInt,
108}
109
110table VkValue {
111  value:GraphTypes;
112}
113
114// Abstraction to represent a region of bytes in a raw data buffer. Useful for referencing raw data
115// serialized outside of the flatbuffer.
116table VkBytes {
117  offset:ulong;
118  length:ulong;
119}
120
121table VkGraph {
122  // Schema version.
123  version:string;
124
125  // Objects
126  chain:[OperatorCall];
127  values:[VkValue];
128
129  // Indices
130  input_ids:[uint];
131  output_ids:[uint];
132
133  // Raw Objects (e.g. weight tensors and custom shaders)
134  constants:[VkBytes];
135  shaders:[VkBytes];
136
137  // Graph configuration
138  // As per flatbuffer BC/FC policy, new fields can be freely added to this
139  // section. It is recommended to provide default values, since older blobs
140  // without the field will be deserialized with the default value.
141
142  // Sets an override for the storage type and memory layout that will be used
143  // to represent a VkTensor if the VkTensor is not serialized with a particular
144  // storage type or memory layout setting
145  storage_type_override:VkStorageType = DEFAULT_STORAGE;
146  memory_layout_override:VkMemoryLayout = DEFAULT_LAYOUT;
147}
148
149root_type VkGraph;
150