-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathvulkan_graph_schema.py
More file actions
162 lines (115 loc) · 2.48 KB
/
vulkan_graph_schema.py
File metadata and controls
162 lines (115 loc) · 2.48 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
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# pyre-strict
"""
Please refer to fbcode/caffe2/executorch/backends/vulkan/serialization/schema/schema.fbs for the schema definitions
"""
from dataclasses import dataclass
from enum import IntEnum
from typing import List, Union
@dataclass
class OperatorCall:
node_id: int
name: str
args: List[int]
class VkDataType(IntEnum):
BOOL = 0
UINT8 = 1
INT8 = 2
INT32 = 3
FLOAT16 = 4
FLOAT32 = 5
FLOAT64 = 6
INT64 = 7
UNSET = 127
class VkStorageType(IntEnum):
BUFFER = 0
TEXTURE_3D = 1
TEXTURE_2D = 2
DEFAULT_STORAGE = 255
def __str__(self) -> str:
return self.name
class VkMemoryLayout(IntEnum):
TENSOR_WIDTH_PACKED = 0
TENSOR_HEIGHT_PACKED = 1
TENSOR_CHANNELS_PACKED = 2
PACKED_INT8_4W4C = 3
PACKED_INT8_4H4W = 4
PACKED_INT8_4C1W = 8
DEFAULT_LAYOUT = 255
def __str__(self) -> str:
return self.name
@dataclass
class VkTensor:
datatype: VkDataType
dims: List[int]
constant_id: int
mem_obj_id: int
storage_type: VkStorageType = VkStorageType.DEFAULT_STORAGE
memory_layout: VkMemoryLayout = VkMemoryLayout.DEFAULT_LAYOUT
staging_datatype: VkDataType = VkDataType.UNSET
@dataclass
class Null:
pass
@dataclass
class Int:
int_val: int
@dataclass
class Bool:
bool_val: bool
@dataclass
class Double:
double_val: float
@dataclass
class IntList:
items: List[int]
@dataclass
class DoubleList:
items: List[float]
@dataclass
class BoolList:
items: List[bool]
@dataclass
class ValueList:
items: List[int]
@dataclass
class String:
string_val: str
@dataclass
class SymInt:
value: int
GraphTypes = Union[
Null,
Int,
Double,
Bool,
VkTensor,
IntList,
BoolList,
DoubleList,
ValueList,
String,
SymInt,
]
@dataclass
class VkValue:
value: "GraphTypes"
@dataclass
class VkBytes:
offset: int
length: int
named_key: str = ""
@dataclass
class VkGraph:
version: str
chain: List[OperatorCall]
values: List[VkValue]
input_ids: List[int]
output_ids: List[int]
constants: List[VkBytes]
shaders: List[VkBytes]
storage_type_override: VkStorageType = VkStorageType.DEFAULT_STORAGE
memory_layout_override: VkMemoryLayout = VkMemoryLayout.DEFAULT_LAYOUT