xtc-tools 0.3.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 (173) hide show
  1. xtc/__init__.py +7 -0
  2. xtc/artifacts/__init__.py +25 -0
  3. xtc/artifacts/operations.py +71 -0
  4. xtc/artifacts/register_subgraph_operations.py +34 -0
  5. xtc/artifacts/register_ttile_operations.py +46 -0
  6. xtc/artifacts/subgraph_sizes.py +207 -0
  7. xtc/backends/jir/JIRBackend.py +105 -0
  8. xtc/backends/jir/JIRCompiler.py +375 -0
  9. xtc/backends/jir/JIROps.py +206 -0
  10. xtc/backends/jir/JIRScheduler.py +402 -0
  11. xtc/backends/jir/__init__.py +18 -0
  12. xtc/backends/mlir/MlirBackend.py +58 -0
  13. xtc/backends/mlir/MlirCompiler.py +248 -0
  14. xtc/backends/mlir/MlirCompilerPasses.py +800 -0
  15. xtc/backends/mlir/MlirConfig.py +46 -0
  16. xtc/backends/mlir/MlirGraphBackend.py +243 -0
  17. xtc/backends/mlir/MlirNodeBackend.py +75 -0
  18. xtc/backends/mlir/MlirNodeScheduler.py +118 -0
  19. xtc/backends/mlir/MlirOps.py +901 -0
  20. xtc/backends/mlir/MlirProgram.py +100 -0
  21. xtc/backends/mlir/MlirScheduler.py +253 -0
  22. xtc/backends/mlir/MlirTarget/MlirCTarget.py +118 -0
  23. xtc/backends/mlir/MlirTarget/MlirCpuTarget.py +214 -0
  24. xtc/backends/mlir/MlirTarget/MlirLLVMTarget.py +145 -0
  25. xtc/backends/mlir/MlirTarget/MlirMppaTarget.py +461 -0
  26. xtc/backends/mlir/MlirTarget/MlirNVGPUTarget.py +470 -0
  27. xtc/backends/mlir/MlirTarget/MlirTarget.py +83 -0
  28. xtc/backends/mlir/MlirTarget/__init__.py +32 -0
  29. xtc/backends/mlir/MlirTarget/cpu_lowering.py +43 -0
  30. xtc/backends/mlir/__init__.py +32 -0
  31. xtc/backends/tvm/TVMBackend.py +79 -0
  32. xtc/backends/tvm/TVMCompiler.py +580 -0
  33. xtc/backends/tvm/TVMOps.py +731 -0
  34. xtc/backends/tvm/TVMOpsCompiler.py +110 -0
  35. xtc/backends/tvm/TVMScheduler.py +409 -0
  36. xtc/backends/tvm/__init__.py +18 -0
  37. xtc/cli/display_results.py +199 -0
  38. xtc/cli/explore.py +359 -0
  39. xtc/cli/mlir_backend.py +98 -0
  40. xtc/cli/mlir_loop.py +343 -0
  41. xtc/cli/query_results.py +263 -0
  42. xtc/csrcs/runtimes/accelerator/gpu/perf_event_gpu.cpp +325 -0
  43. xtc/csrcs/runtimes/accelerator/gpu/perf_event_gpu.h +26 -0
  44. xtc/csrcs/runtimes/accelerator/mppa/host.c +130 -0
  45. xtc/csrcs/runtimes/accelerator/mppa/perf_event_mppa.h +31 -0
  46. xtc/csrcs/runtimes/accelerator/mppa/perf_events.c +112 -0
  47. xtc/csrcs/runtimes/host/alloc.c +38 -0
  48. xtc/csrcs/runtimes/host/alloc.h +13 -0
  49. xtc/csrcs/runtimes/host/cndarray.c +155 -0
  50. xtc/csrcs/runtimes/host/dlpack.h +229 -0
  51. xtc/csrcs/runtimes/host/evaluate_flops.c +495 -0
  52. xtc/csrcs/runtimes/host/evaluate_perf.c +253 -0
  53. xtc/csrcs/runtimes/host/fclock.c +11 -0
  54. xtc/csrcs/runtimes/host/kperf.h +954 -0
  55. xtc/csrcs/runtimes/host/perf_event.h +73 -0
  56. xtc/csrcs/runtimes/host/perf_event_darwin.c +170 -0
  57. xtc/csrcs/runtimes/host/perf_event_linux.c +258 -0
  58. xtc/csrcs/runtimes/host/runtime.h +20 -0
  59. xtc/csrcs/runtimes/host/simd.h +116 -0
  60. xtc/csrcs/runtimes/host/tvm_runtime_init.c +30 -0
  61. xtc/graphs/xtc/__init__.py +4 -0
  62. xtc/graphs/xtc/builder.py +87 -0
  63. xtc/graphs/xtc/context.py +135 -0
  64. xtc/graphs/xtc/data.py +236 -0
  65. xtc/graphs/xtc/expr.py +308 -0
  66. xtc/graphs/xtc/graph.py +205 -0
  67. xtc/graphs/xtc/node.py +167 -0
  68. xtc/graphs/xtc/op.py +6 -0
  69. xtc/graphs/xtc/op_factory.py +112 -0
  70. xtc/graphs/xtc/operation.py +99 -0
  71. xtc/graphs/xtc/operators.py +804 -0
  72. xtc/graphs/xtc/ty.py +6 -0
  73. xtc/graphs/xtc/utils.py +53 -0
  74. xtc/itf/__init__.py +13 -0
  75. xtc/itf/back/__init__.py +5 -0
  76. xtc/itf/back/backend.py +99 -0
  77. xtc/itf/comp/__init__.py +6 -0
  78. xtc/itf/comp/compiler.py +51 -0
  79. xtc/itf/comp/module.py +106 -0
  80. xtc/itf/data/__init__.py +13 -0
  81. xtc/itf/data/tensor.py +156 -0
  82. xtc/itf/exec/__init__.py +6 -0
  83. xtc/itf/exec/evaluator.py +42 -0
  84. xtc/itf/exec/executor.py +38 -0
  85. xtc/itf/graph/__init__.py +7 -0
  86. xtc/itf/graph/graph.py +171 -0
  87. xtc/itf/graph/node.py +167 -0
  88. xtc/itf/graph/operation.py +157 -0
  89. xtc/itf/operator/__init__.py +5 -0
  90. xtc/itf/operator/operator.py +54 -0
  91. xtc/itf/runtime/accelerator.py +135 -0
  92. xtc/itf/runtime/common.py +206 -0
  93. xtc/itf/runtime/embedded.py +25 -0
  94. xtc/itf/schd/__init__.py +6 -0
  95. xtc/itf/schd/schedule.py +35 -0
  96. xtc/itf/schd/scheduler.py +336 -0
  97. xtc/itf/search/__init__.py +8 -0
  98. xtc/itf/search/optimizer.py +49 -0
  99. xtc/itf/search/strategy.py +164 -0
  100. xtc/py.typed +0 -0
  101. xtc/runtimes/accelerator/gpu/GPUDevice.py +351 -0
  102. xtc/runtimes/accelerator/gpu/__init__.py +7 -0
  103. xtc/runtimes/accelerator/mppa/MppaDevice.py +773 -0
  104. xtc/runtimes/accelerator/mppa/__init__.py +8 -0
  105. xtc/runtimes/accelerator/mppa/config.py +161 -0
  106. xtc/runtimes/host/HostRuntime.py +200 -0
  107. xtc/runtimes/host/__init__.py +9 -0
  108. xtc/runtimes/host/runtime.py +275 -0
  109. xtc/runtimes/types/__init__.py +4 -0
  110. xtc/runtimes/types/dlpack.py +65 -0
  111. xtc/runtimes/types/ndarray.py +237 -0
  112. xtc/schedules/descript.py +542 -0
  113. xtc/schedules/exceptions.py +23 -0
  114. xtc/schedules/loop_names.py +34 -0
  115. xtc/schedules/loop_nest.py +468 -0
  116. xtc/schedules/loop_nest_builder.py +130 -0
  117. xtc/schedules/parameter_loop_nest.py +568 -0
  118. xtc/schedules/parsing.py +352 -0
  119. xtc/schedules/plain_schedule.py +276 -0
  120. xtc/schedules/ttile/archi.py +53 -0
  121. xtc/schedules/ttile/cache_model/full_assoc_model.py +828 -0
  122. xtc/schedules/ttile/cache_model/sarcasm_set_assoc_model.py +1798 -0
  123. xtc/schedules/ttile/computation.py +481 -0
  124. xtc/schedules/ttile/microkernel.py +644 -0
  125. xtc/schedules/ttile/prob_sizes.py +420 -0
  126. xtc/schedules/ttile/scheme.py +754 -0
  127. xtc/schedules/ttile/scheme_to_xtc.py +936 -0
  128. xtc/schedules/ttile/search_strat.py +1199 -0
  129. xtc/search/__init__.py +4 -0
  130. xtc/search/callback.py +172 -0
  131. xtc/search/explore.py +876 -0
  132. xtc/search/optimizers.py +236 -0
  133. xtc/search/pipeline.py +117 -0
  134. xtc/search/progress.py +226 -0
  135. xtc/search/strategies.py +1283 -0
  136. xtc/targets/accelerator/gpu/GPUEvaluator.py +138 -0
  137. xtc/targets/accelerator/gpu/GPUModule.py +92 -0
  138. xtc/targets/accelerator/gpu/__init__.py +8 -0
  139. xtc/targets/accelerator/mppa/MppaEvaluator.py +121 -0
  140. xtc/targets/accelerator/mppa/MppaModule.py +97 -0
  141. xtc/targets/accelerator/mppa/__init__.py +8 -0
  142. xtc/targets/host/HostAREvaluator.py +107 -0
  143. xtc/targets/host/HostCEvaluator.py +106 -0
  144. xtc/targets/host/HostEvaluator.py +120 -0
  145. xtc/targets/host/HostModule.py +135 -0
  146. xtc/targets/host/__init__.py +18 -0
  147. xtc/templates/tvm/packed_op_wrapper.c.jinja +95 -0
  148. xtc/templates/tvm/tvm_ffi_op_wrapper.c.jinja +23 -0
  149. xtc/templates/tvm/unpacked_op.h.jinja +11 -0
  150. xtc/utils/__init__.py +4 -0
  151. xtc/utils/algorithms.py +114 -0
  152. xtc/utils/cfunc.py +129 -0
  153. xtc/utils/cpu.py +99 -0
  154. xtc/utils/evaluation.py +199 -0
  155. xtc/utils/ext_tools.py +116 -0
  156. xtc/utils/files.py +15 -0
  157. xtc/utils/host_tools.py +156 -0
  158. xtc/utils/import.py +26 -0
  159. xtc/utils/loader.py +45 -0
  160. xtc/utils/math.py +157 -0
  161. xtc/utils/numpy.py +19 -0
  162. xtc/utils/tarfile.py +44 -0
  163. xtc/utils/text.py +65 -0
  164. xtc/utils/tools.py +182 -0
  165. xtc/utils/xdsl_aux.py +83 -0
  166. xtc/utils/xdsl_implicit_builder.py +115 -0
  167. xtc_tools-0.3.0.dist-info/METADATA +244 -0
  168. xtc_tools-0.3.0.dist-info/RECORD +173 -0
  169. xtc_tools-0.3.0.dist-info/WHEEL +5 -0
  170. xtc_tools-0.3.0.dist-info/entry_points.txt +6 -0
  171. xtc_tools-0.3.0.dist-info/licenses/LICENSE +28 -0
  172. xtc_tools-0.3.0.dist-info/licenses/LICENSE_HEADER +2 -0
  173. xtc_tools-0.3.0.dist-info/top_level.txt +1 -0
xtc/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ #
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+ # Copyright (c) 2024-2026 The XTC Project Authors
4
+ #
5
+ import importlib.metadata
6
+
7
+ __version__ = importlib.metadata.version("xtc-tools")
@@ -0,0 +1,25 @@
1
+ #
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+ # Copyright (c) 2024-2026 The XTC Project Authors
4
+ #
5
+ from .operations import (
6
+ register_operation,
7
+ get_operation,
8
+ list_operations,
9
+ has_operation,
10
+ )
11
+
12
+ from .register_ttile_operations import _register_operations
13
+ from .register_subgraph_operations import (
14
+ _register_operations as _register_subgraph_operations,
15
+ )
16
+
17
+ _register_operations()
18
+ _register_subgraph_operations()
19
+
20
+ __all__ = [
21
+ "register_operation",
22
+ "get_operation",
23
+ "list_operations",
24
+ "has_operation",
25
+ ]
@@ -0,0 +1,71 @@
1
+ #
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+ # Copyright (c) 2024-2026 The XTC Project Authors
4
+ #
5
+ import itertools
6
+ import logging
7
+
8
+ _OPERATION_REGISTRY: dict[str, dict[str, dict]] = {}
9
+
10
+ __all__ = [
11
+ "register_operation",
12
+ "get_operation",
13
+ "has_operation",
14
+ "list_operations",
15
+ ]
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+
20
+ def register_operation(
21
+ operator: str, name: str, dims: dict[str, int], params: dict[str, int] | None = None
22
+ ):
23
+ if operator not in _OPERATION_REGISTRY:
24
+ _OPERATION_REGISTRY[operator] = {}
25
+ if params is None:
26
+ params = {}
27
+ operations = _OPERATION_REGISTRY[operator]
28
+ canonical = name.lower()
29
+ if canonical in operations:
30
+ logger.warning(f"operation {operator}/{canonical} is already registered")
31
+ _OPERATION_REGISTRY[operator][canonical] = dict(
32
+ name=name,
33
+ dims=dims,
34
+ params=params,
35
+ )
36
+
37
+
38
+ def get_operation(operator: str, name: str) -> dict:
39
+ if operator not in _OPERATION_REGISTRY:
40
+ raise ValueError(f"operator {operator} not registered in operation registry")
41
+ operations = _OPERATION_REGISTRY[operator]
42
+ canonical = name.lower()
43
+ if canonical not in operations:
44
+ raise ValueError(
45
+ f"operation name {name} for operator {operator} not registered in operation registry"
46
+ )
47
+ return operations[canonical]
48
+
49
+
50
+ def has_operation(operator: str, name: str) -> bool:
51
+ try:
52
+ get_operation(operator, name)
53
+ except ValueError:
54
+ return False
55
+ return True
56
+
57
+
58
+ def list_operations(operator: str = "") -> list[tuple[str, str]]:
59
+ if operator == "":
60
+ operations = list(
61
+ itertools.chain(
62
+ *[list_operations(operator) for operator in _OPERATION_REGISTRY.keys()]
63
+ )
64
+ )
65
+ return operations
66
+ if operator not in _OPERATION_REGISTRY:
67
+ raise ValueError(f"operator {operator} not registered in operation registry")
68
+ operations = [
69
+ (operator, op["name"]) for op in _OPERATION_REGISTRY[operator].values()
70
+ ]
71
+ return operations
@@ -0,0 +1,34 @@
1
+ #
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+ # Copyright (c) 2024-2026 The XTC Project Authors
4
+ #
5
+ from .operations import register_operation
6
+ from .subgraph_sizes import *
7
+
8
+ __all__: list[str] = []
9
+
10
+
11
+ def _register_conv2d_ops():
12
+ for group in [squeezenet_convs, alexnet_convs]:
13
+ for name, params in group.items():
14
+ register_operation(
15
+ "conv2d",
16
+ name,
17
+ {k: params[k] for k in ["n", "h", "w", "f", "r", "s", "c"]},
18
+ {"SH": params["stry"], "SW": params["strx"]},
19
+ )
20
+
21
+
22
+ def _register_matmul_ops():
23
+ for group in [alexnet_matmuls]:
24
+ for name, params in group.items():
25
+ register_operation(
26
+ "matmul",
27
+ name,
28
+ {k: params[k] for k in ["i", "j", "k"]},
29
+ )
30
+
31
+
32
+ def _register_operations():
33
+ _register_conv2d_ops()
34
+ _register_matmul_ops()
@@ -0,0 +1,46 @@
1
+ #
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+ # Copyright (c) 2024-2026 The XTC Project Authors
4
+ #
5
+ from xtc.schedules.ttile.prob_sizes import (
6
+ ddsizes_Yolo,
7
+ ddsizes_MobilNet,
8
+ ddsizes_RN18,
9
+ ddsizes_matmul,
10
+ )
11
+
12
+ from .operations import register_operation
13
+
14
+ __all__: list[str] = []
15
+
16
+
17
+ def _register_conv2d_ops():
18
+ map = dict(
19
+ h="y",
20
+ w="x",
21
+ r="h",
22
+ s="w",
23
+ )
24
+ for group in [ddsizes_Yolo, ddsizes_MobilNet, ddsizes_RN18]:
25
+ for name, params in group.items():
26
+ register_operation(
27
+ "conv2d",
28
+ name,
29
+ {k: params[map.get(k, k)] for k in ["n", "h", "w", "f", "r", "s", "c"]},
30
+ {"SH": params["stry"], "SW": params["strx"]},
31
+ )
32
+
33
+
34
+ def _register_matmul_ops():
35
+ for group in [ddsizes_matmul]:
36
+ for name, params in group.items():
37
+ register_operation(
38
+ "matmul",
39
+ name,
40
+ {k: params[k] for k in ["i", "j", "k"]},
41
+ )
42
+
43
+
44
+ def _register_operations():
45
+ _register_conv2d_ops()
46
+ _register_matmul_ops()
@@ -0,0 +1,207 @@
1
+ #
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+ # Copyright (c) 2024-2026 The XTC Project Authors
4
+ #
5
+ __all__ = [
6
+ "squeezenet_convs",
7
+ "alexnet_convs",
8
+ "alexnet_matmuls",
9
+ ]
10
+
11
+ squeezenet_convs = {
12
+ "SqueezeNet_00": {
13
+ "n": 1,
14
+ "h": 224,
15
+ "w": 224,
16
+ "c": 3,
17
+ "r": 7,
18
+ "s": 7,
19
+ "f": 96,
20
+ "strx": 2,
21
+ "stry": 2,
22
+ },
23
+ "SqueezeNet_01": {
24
+ "n": 1,
25
+ "h": 54,
26
+ "w": 54,
27
+ "c": 96,
28
+ "r": 1,
29
+ "s": 1,
30
+ "f": 16,
31
+ "strx": 1,
32
+ "stry": 1,
33
+ },
34
+ "SqueezeNet_03": {
35
+ "n": 1,
36
+ "h": 56,
37
+ "w": 56,
38
+ "c": 16,
39
+ "r": 3,
40
+ "s": 3,
41
+ "f": 64,
42
+ "strx": 1,
43
+ "stry": 1,
44
+ },
45
+ "SqueezeNet_04": {
46
+ "n": 1,
47
+ "h": 54,
48
+ "w": 54,
49
+ "c": 128,
50
+ "r": 1,
51
+ "s": 1,
52
+ "f": 16,
53
+ "strx": 1,
54
+ "stry": 1,
55
+ },
56
+ "SqueezeNet_05": {
57
+ "n": 1,
58
+ "h": 54,
59
+ "w": 54,
60
+ "c": 128,
61
+ "r": 1,
62
+ "s": 1,
63
+ "f": 32,
64
+ "strx": 1,
65
+ "stry": 1,
66
+ },
67
+ "SqueezeNet_07": {
68
+ "n": 1,
69
+ "h": 54,
70
+ "w": 54,
71
+ "c": 32,
72
+ "r": 3,
73
+ "s": 3,
74
+ "f": 128,
75
+ "strx": 1,
76
+ "stry": 1,
77
+ },
78
+ "SqueezeNet_08": {
79
+ "n": 1,
80
+ "h": 27,
81
+ "w": 27,
82
+ "c": 256,
83
+ "r": 1,
84
+ "s": 1,
85
+ "f": 32,
86
+ "strx": 1,
87
+ "stry": 1,
88
+ },
89
+ "SqueezeNet_11": {
90
+ "n": 1,
91
+ "h": 27,
92
+ "w": 27,
93
+ "c": 256,
94
+ "r": 1,
95
+ "s": 1,
96
+ "f": 48,
97
+ "strx": 1,
98
+ "stry": 1,
99
+ },
100
+ "SqueezeNet_13": {
101
+ "n": 1,
102
+ "h": 27,
103
+ "w": 27,
104
+ "c": 48,
105
+ "r": 3,
106
+ "s": 3,
107
+ "f": 192,
108
+ "strx": 1,
109
+ "stry": 1,
110
+ },
111
+ "SqueezeNet_14": {
112
+ "n": 1,
113
+ "h": 27,
114
+ "w": 27,
115
+ "c": 384,
116
+ "r": 1,
117
+ "s": 1,
118
+ "f": 48,
119
+ "strx": 1,
120
+ "stry": 1,
121
+ },
122
+ "SqueezeNet_17": {
123
+ "n": 1,
124
+ "h": 27,
125
+ "w": 27,
126
+ "c": 64,
127
+ "r": 3,
128
+ "s": 3,
129
+ "f": 256,
130
+ "strx": 1,
131
+ "stry": 1,
132
+ },
133
+ "SqueezeNet_21": {
134
+ "n": 1,
135
+ "h": 15,
136
+ "w": 15,
137
+ "c": 512,
138
+ "r": 1,
139
+ "s": 1,
140
+ "f": 1000,
141
+ "strx": 1,
142
+ "stry": 1,
143
+ },
144
+ }
145
+
146
+ alexnet_convs = {
147
+ "AlexNet_00": {
148
+ "n": 1,
149
+ "h": 228,
150
+ "w": 228,
151
+ "c": 3,
152
+ "r": 11,
153
+ "s": 11,
154
+ "f": 64,
155
+ "strx": 4,
156
+ "stry": 4,
157
+ },
158
+ "AlexNet_01": {
159
+ "n": 1,
160
+ "h": 31,
161
+ "w": 31,
162
+ "c": 64,
163
+ "r": 5,
164
+ "s": 5,
165
+ "f": 192,
166
+ "strx": 1,
167
+ "stry": 1,
168
+ },
169
+ "AlexNet_02": {
170
+ "n": 1,
171
+ "h": 15,
172
+ "w": 15,
173
+ "c": 192,
174
+ "r": 3,
175
+ "s": 3,
176
+ "f": 384,
177
+ "strx": 1,
178
+ "stry": 1,
179
+ },
180
+ "AlexNet_03": {
181
+ "n": 1,
182
+ "h": 15,
183
+ "w": 15,
184
+ "c": 384,
185
+ "r": 3,
186
+ "s": 3,
187
+ "f": 256,
188
+ "strx": 1,
189
+ "stry": 1,
190
+ },
191
+ "AlexNet_04": {
192
+ "n": 1,
193
+ "h": 15,
194
+ "w": 15,
195
+ "c": 256,
196
+ "r": 3,
197
+ "s": 3,
198
+ "f": 256,
199
+ "strx": 1,
200
+ "stry": 1,
201
+ },
202
+ }
203
+ alexnet_matmuls = {
204
+ "AlexNet_FC6": {"i": 1, "j": 4096, "k": 9216},
205
+ "AlexNet_FC7": {"i": 1, "j": 4096, "k": 4096},
206
+ "AlexNet_FC8": {"i": 1, "j": 1000, "k": 4096},
207
+ }
@@ -0,0 +1,105 @@
1
+ #
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+ # Copyright (c) 2024-2026 The XTC Project Authors
4
+ #
5
+ from typing_extensions import override
6
+ from typing import Any
7
+
8
+ from jir.node import JIRFunction
9
+ from jir.backend.util.annotate_fastmath import annotate_fastmath
10
+ from jir.parser import JIRParser
11
+ from jir.backend.xdsl.compiler import PolygeistCompiler
12
+
13
+ from xtc.utils.tools import (
14
+ get_geist_prefix,
15
+ )
16
+
17
+ import xtc.itf as itf
18
+ from xtc.itf.graph import Graph
19
+ from xtc.graphs.xtc.graph import XTCGraph
20
+
21
+ from .JIROps import JIROperation
22
+ from .JIRScheduler import JIRScheduler
23
+ from .JIRCompiler import JIRCompiler
24
+
25
+ __all__ = [
26
+ "JIRBackend",
27
+ ]
28
+
29
+
30
+ class JIRBackend(itf.back.Backend):
31
+ def __init__(
32
+ self,
33
+ source_op: JIROperation | Graph,
34
+ dims: dict[str, int] | None = None,
35
+ parallel_dims: list[str] | None = None,
36
+ reduction_dims: list[str] | None = None,
37
+ **kwargs: Any,
38
+ ) -> None:
39
+ self._graph: Graph | None = None
40
+ if isinstance(source_op, XTCGraph):
41
+ graph = source_op
42
+ self._graph = graph
43
+ self.ops = [
44
+ JIROperation.from_operation(node.operation, name=node.name)
45
+ for node in graph.nodes.values()
46
+ ]
47
+ self.dims = self.ops[-1].operator.dims_sizes()
48
+ self._payload_name = self._graph.name
49
+ else:
50
+ assert isinstance(source_op, JIROperation)
51
+ assert dims is not None
52
+ self.dims = dims
53
+ self.ops = [source_op]
54
+ self._payload_name = source_op.name
55
+
56
+ self.op = self.ops[-1]
57
+
58
+ assert tuple(self.dims.keys()) == self.op.operator.dims(), (
59
+ f"incompatible dims names: {tuple(self.dims.keys())} != "
60
+ f"{self.op.operator.dims()}"
61
+ )
62
+ self.parallel_dims = self.op.operator.dims("P")
63
+ self.reduction_dims = self.op.operator.dims("R")
64
+ if parallel_dims is not None:
65
+ assert tuple(parallel_dims) == self.parallel_dims, (
66
+ f"incompatible parallel dims names: {tuple(parallel_dims)} != "
67
+ f"{self.parallel_dims}"
68
+ )
69
+ if reduction_dims is not None:
70
+ assert tuple(reduction_dims) == self.reduction_dims, (
71
+ f"incompatible reduction dims names: {tuple(reduction_dims)} != "
72
+ f"{self.reduction_dims}"
73
+ )
74
+ self._geist_install_dir = get_geist_prefix()
75
+ self._op_function_str, self._jir_function_str = self.op.generate(
76
+ self._payload_name
77
+ )
78
+ self._jir_function_op = self._parse_function(self._jir_function_str)
79
+ self._op_function_mlir = self._parse_primitives(self._op_function_str)
80
+
81
+ @override
82
+ def get_scheduler(self, **kwargs: Any) -> itf.schd.Scheduler:
83
+ return JIRScheduler(self, **kwargs)
84
+
85
+ @override
86
+ def get_compiler(self, **kwargs: Any) -> itf.comp.Compiler:
87
+ return JIRCompiler(self, **kwargs)
88
+
89
+ @property
90
+ @override
91
+ def payload_name(self) -> str:
92
+ return self._payload_name
93
+
94
+ @property
95
+ @override
96
+ def graph(self) -> itf.graph.Graph:
97
+ assert self._graph is not None
98
+ return self._graph
99
+
100
+ def _parse_function(self, jir_function: str) -> JIRFunction:
101
+ return JIRParser().parse_function(jir_function)
102
+
103
+ def _parse_primitives(self, op_function: str) -> str:
104
+ polygeist_compiler = PolygeistCompiler(f"{self._geist_install_dir}/bin/cgeist")
105
+ return annotate_fastmath(polygeist_compiler(op_function))