TACHY-Compiler 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. tachy_compiler/__init__.py +10 -0
  2. tachy_compiler/compiler/__init__.py +8 -0
  3. tachy_compiler/compiler/constraint.py +65 -0
  4. tachy_compiler/compiler/convert_tachy2tachyrt.py +168 -0
  5. tachy_compiler/compiler/editor.py +1821 -0
  6. tachy_compiler/compiler/extract.py +172 -0
  7. tachy_compiler/compiler/format_prototxt.py +365 -0
  8. tachy_compiler/compiler/functions.py +868 -0
  9. tachy_compiler/compiler/graph.py +720 -0
  10. tachy_compiler/compiler/map_address.py +44 -0
  11. tachy_compiler/compiler/tachy_format.py +61 -0
  12. tachy_compiler/compiler/tachy_layers.py +1163 -0
  13. tachy_compiler/compiler/utils/__init__.py +8 -0
  14. tachy_compiler/compiler/utils/compile_runtime.py +84 -0
  15. tachy_compiler/compiler/utils/convert_layer2block.py +588 -0
  16. tachy_compiler/compiler/utils/convert_onnx2tachy.py +405 -0
  17. tachy_compiler/compiler/utils/tachy_block.py +686 -0
  18. tachy_compiler/compiler/utils/tachy_inference.py +150 -0
  19. tachy_compiler/compiler/utils/tachy_model.py +319 -0
  20. tachy_compiler/compiler/utils/tachy_prototxt.py +290 -0
  21. tachy_compiler/compiler/utils/tachy_viewer.py +25 -0
  22. tachy_compiler/compiler/utils/tachyrt_model.py +280 -0
  23. tachy_compiler/compiler/verify.py +15 -0
  24. tachy_compiler/platform_converter/__init__.py +8 -0
  25. tachy_compiler/platform_converter/utils/__init__.py +19 -0
  26. tachy_compiler/platform_converter/utils/yolov9/__init__.py +33 -0
  27. tachy_compiler/platform_converter/utils/yolov9/convert_pt2onnx.py +91 -0
  28. tachy_compiler/platform_converter/utils/yolov9/deploy_pt_yolov9.py +128 -0
  29. tachy_compiler/platform_converter/utils/yolov9/utils/__init__.py +46 -0
  30. tachy_compiler-0.1.0.dist-info/METADATA +33 -0
  31. tachy_compiler-0.1.0.dist-info/RECORD +33 -0
  32. tachy_compiler-0.1.0.dist-info/WHEEL +5 -0
  33. tachy_compiler-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,10 @@
1
+ """
2
+ TACHY compiler core package.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ __all__ = ["__version__"]
8
+
9
+ __version__ = "0.1.0"
10
+
@@ -0,0 +1,8 @@
1
+ """
2
+ Compiler core subpackage.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ __all__ = []
8
+
@@ -0,0 +1,65 @@
1
+ import numpy as np
2
+
3
+ def align_odd_width(block_config):
4
+ _, in_w, _ = block_config["input_shape"]
5
+ ker_h, ker_w, _, _ = block_config["kernel_shape"]
6
+ str_h, str_w = block_config["stride_shape"]
7
+ p_t, p_l, p_b, p_r, _ = block_config["padding_shape"]
8
+
9
+ is_odd = (in_w % 2 == 1)
10
+ is_ker_1x1 = (ker_h == 1 and ker_w == 1)
11
+ is_str_2x2 = (str_h == 2 and str_w == 2)
12
+ is_no_pad = ((p_t == 0) and (p_l == 0) and (p_b == 0) and (p_r == 0))
13
+
14
+ if is_odd and is_ker_1x1 and is_str_2x2 and is_no_pad:
15
+ block_config["padding_shape"][2] += 1 # add bottom padding
16
+ block_config["padding_shape"][3] += 1 # add right padding
17
+
18
+ return block_config
19
+
20
+ def add_dummy_padding(block_config):
21
+ in_h, in_w, _ = block_config["input_shape"]
22
+ out_h, out_w, _ = block_config["output_shape"]
23
+ ker_h, ker_w, _, __ = block_config["kernel_shape"]
24
+ str_h, str_w = block_config["stride_shape"]
25
+ p_t, p_l, p_b, p_r, p_s = block_config["padding_shape"]
26
+
27
+ op = block_config["operation"]
28
+ if op == "Conv":
29
+ if out_w < 7:
30
+ for i in range(8):
31
+ if (1 + (in_w - 1 + p_l + p_r + i - (ker_w - 1)) / str_w >= 7):
32
+ p_s = i
33
+ break
34
+ p_r += p_s
35
+ else:
36
+ if op == "MaxPool": # Warning: Only for synergy ai
37
+ if ker_w+1 > in_w:
38
+ add_pad = max((ker_w + 1 - in_w), 0)
39
+ p_r += add_pad
40
+ p_s += ((in_w + p_r) - ker_w)
41
+
42
+ block_config["padding_shape"] = [p_t, p_l, p_b, p_r, p_s]
43
+ return block_config
44
+
45
+ # def add_dummy_padding(block_config):
46
+ # in_h, in_w, _ = block_config["input_shape"]
47
+ # ker_h, ker_w, _, __ = block_config["kernel_shape"]
48
+ #
49
+ # p_t, p_l, p_b, p_r, p_s = block_config["padding_shape"]
50
+ #
51
+ # op = block_config["operation"]
52
+ # if op == "Conv":
53
+ # if in_w < 7:
54
+ # add_pad = (7 - in_w)
55
+ # p_r += add_pad
56
+ # p_s += add_pad
57
+ # else:
58
+ # if op == "MaxPool": # Warning: Only for synergy ai
59
+ # if ker_w+1 > in_w:
60
+ # add_pad = max((ker_w + 1 - in_w), 0)
61
+ # p_r += add_pad
62
+ # p_s += ((in_w + p_r) - ker_w)
63
+ #
64
+ # block_config["padding_shape"] = [p_t, p_l, p_b, p_r, p_s]
65
+ # return block_config
@@ -0,0 +1,168 @@
1
+ import os, sys
2
+ import math
3
+ import numpy as np
4
+
5
+ def set_index(blocks_config:dict, inst:np.ndarray, idx:int):
6
+ idx = blocks_config["blocks"][idx]["index"]
7
+
8
+ inst[0] &= 0x00FFFFFF
9
+ inst[0] |= ((idx & 0xFF) << 24)
10
+
11
+ def set_mode(blocks_config:dict, inst:np.ndarray, idx:int):
12
+ mode = blocks_config["blocks"][idx]["operation"]
13
+
14
+ inst[0] &= 0xFFFEFFFC
15
+ if "Conv" == mode:
16
+ inst[0] |= 0x00000000
17
+ elif "TransposeConv" == mode:
18
+ inst[0] |= 0x00010002
19
+ elif "MaxPool" == mode:
20
+ inst[0] |= 0x00010000
21
+ elif "Gemm" == mode:
22
+ inst[0] |= 0x00000001
23
+ elif "Scaler" == mode:
24
+ inst[0] |= 0x00000003
25
+ else:
26
+ raise Exception("Unknown mode : {}".format(mode))
27
+
28
+ def set_xwn(blocks_config:dict, inst:np.ndarray, idx:int):
29
+ xwn_bit = 1 if (blocks_config["blocks"][idx]["xwn_bit"] == 4) else 0
30
+ xwn_scale = int(math.log2(blocks_config["blocks"][idx]["xwn_scale"])) if xwn_bit == 1 else 0
31
+
32
+ inst[0] &= 0xFFFF9FFF
33
+ inst[0] |= (
34
+ (xwn_scale << 9) |
35
+ (xwn_bit << 14)
36
+ )
37
+
38
+ def set_input_shape(blocks_config:dict, inst:np.ndarray, idx:int):
39
+ shape = blocks_config["blocks"][idx]["input_shape"]
40
+ channel_idx = blocks_config["blocks"][idx]["channel_idx"]
41
+ if channel_idx is not None:
42
+ shape[2] = (channel_idx[1] - channel_idx[0])
43
+
44
+ inst[1] = (
45
+ ((shape[2] & 0xFFF) << 20) |
46
+ ((shape[0] & 0x3FF) << 10) |
47
+ ((shape[1] & 0x3FF))
48
+ )
49
+
50
+ def set_output_shape(blocks_config:dict, inst:np.ndarray, idx:int):
51
+ shape = blocks_config["blocks"][idx]["output_shape"]
52
+
53
+ inst[3] &= 0xF000FFFF
54
+ inst[3] |= ((shape[2] & 0xFFF) << 16)
55
+
56
+ def set_kernel_shape(blocks_config:dict, inst:np.ndarray, idx:int):
57
+ ker_h, ker_w, _, __= blocks_config["blocks"][idx]["kernel_shape"]
58
+ is_diff = (ker_h != ker_w)
59
+
60
+ inst[3] &= 0x0FFFFFF8
61
+ inst[3] |= (
62
+ (is_diff << 31) |
63
+ ((ker_h & 0x7) << 28) |
64
+ ((ker_w & 0x7) << 0)
65
+ )
66
+
67
+ def set_stride(blocks_config:dict, inst:np.ndarray, idx:int):
68
+ mode = blocks_config["blocks"][idx]["operation"]
69
+ str_h, str_w = blocks_config["blocks"][idx]["stride_shape"]
70
+
71
+ if mode == "TransposeConv":
72
+ str_h, str_w = [1, 1]
73
+
74
+ is_diff = (str_h != str_w)
75
+
76
+ inst[2] &= 0x7FFFF0FF
77
+ inst[2] |= (
78
+ ((str_w & 0x3) << 8) |
79
+ ((str_h & 0x3) << 10) |
80
+ (is_diff << 31)
81
+ )
82
+
83
+ def set_padding(blocks_config:dict, inst:np.ndarray, idx:int):
84
+ pad_t, pad_l, pad_b, pad_r, pad_s = blocks_config["blocks"][idx]["padding_shape"]
85
+ is_diff = ((pad_t + pad_b) != (pad_l + pad_r))
86
+ # is_diff = 0
87
+
88
+ inst[2] &= 0xFFFF8F88
89
+ inst[3] &= 0xFFFF08FF
90
+
91
+ inst[2] |= (
92
+ (((pad_r) & 0x7) << 0) |
93
+ ((pad_l & 0x7) << 4) |
94
+ ((pad_s & 0x7) << 12)
95
+ )
96
+ inst[3] |= (
97
+ ((pad_b & 0x7) << 8) |
98
+ ((pad_t & 0x7) << 12) |
99
+ (is_diff << 15)
100
+ )
101
+
102
+ def set_depth_separate_index(blocks_config:dict, inst:np.ndarray, idx:int):
103
+ channel_index = blocks_config["blocks"][idx]["channel_idx"]
104
+ channel_residual = blocks_config["blocks"][idx]["channel_residual"]
105
+
106
+ start_depth = channel_index[0]
107
+ end_depth = channel_index[1]
108
+ full_depth = channel_index[2]
109
+
110
+ if (end_depth - start_depth) == full_depth:
111
+ return
112
+ if (end_depth - start_depth) == (full_depth - channel_residual[1]):
113
+ return
114
+ if full_depth > 0xFFF:
115
+ return
116
+
117
+ inst[0] &= 0xFFFF7FFF
118
+ inst[2] &= 0xF000FFFF
119
+
120
+ inst[0] |= 0x00008000
121
+ inst[2] |= ((full_depth & 0xFFF) << 16)
122
+
123
+ # batch normalization is always performed
124
+ def set_batch_noralization(blocks_config:dict, inst:np.ndarray, idx:int):
125
+ return
126
+
127
+ def set_residual(blocks_config:dict, inst:np.ndarray, idx:int):
128
+ residual_with = blocks_config["blocks"][idx]["residual_with"]
129
+ if residual_with is not None:
130
+ inst[0] &= 0xFFFFFEFF
131
+ inst[0] |= (1 << 8)
132
+
133
+ def set_activate_function(blocks_config:dict, inst:np.ndarray, idx:int):
134
+ inst[0] &= 0xFFFFFF0F
135
+ relu = blocks_config["blocks"][idx]["activation"]
136
+
137
+ if relu is not None:
138
+ name = relu['name']
139
+ if name == "Relu":
140
+ inst[0] |= (1 << 4)
141
+ elif name == "LeakyRelu":
142
+ inst[0] |= (4 << 4)
143
+ else:
144
+ raise Exception("Unknown activate function name : {}".format(name))
145
+
146
+ def set_scaler(blocks_config:dict, inst:np.ndarray, idx:int):
147
+ mode = blocks_config["blocks"][idx]["operation"]
148
+ input_shape = blocks_config["blocks"][idx]["input_shape"]
149
+ if mode == "Scaler":
150
+ inst[2] &= 0xF000F0FF
151
+ inst[3] &= 0xF000001F
152
+ inst[7] &= 0x0
153
+
154
+ inst[2] |= (
155
+ (1 << 8) |
156
+ (1 << 10) |
157
+ (input_shape[1] << 16)
158
+ )
159
+
160
+ inst[3] |= (
161
+ (input_shape[1] << 5) |
162
+ (input_shape[2] << 16)
163
+ )
164
+
165
+ inst[6] |= (
166
+ (1024 << 0) |
167
+ (1024 << 16)
168
+ )