nvidia-cutlass-dsl-libs-base 4.9.0.dev1__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.
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/_mlir_libs/__init__.py +324 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/_mlir_libs/_cutlass_ir/_mlir/py.typed +0 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/_mlir_libs/_cutlass_ir/_mlirExecutionEngine.pyi +19 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_arith_enum_gen.py +293 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_arith_ops_gen.py +4031 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_builtin_ops_gen.py +199 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_cf_ops_gen.py +400 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_core_enum_gen.py +567 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_core_ops_gen.py +6378 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_cuda_enum_gen.py +900 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_cuda_ops_gen.py +16207 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_cute_enum_gen.py +143 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_cute_nvgpu_enum_gen.py +1536 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_cute_nvgpu_ops_gen.py +6865 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_cute_ops_gen.py +8755 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_func_ops_gen.py +600 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_gpu_enum_gen.py +440 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_gpu_ops_gen.py +7183 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_iket_enum_gen.py +8 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_iket_ops_gen.py +454 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_lir_enum_gen.py +96 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_lir_ops_gen.py +6817 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_llvm_enum_gen.py +1098 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_llvm_ops_gen.py +21996 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_math_ops_gen.py +3115 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_nvgpu_enum_gen.py +257 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_nvgpu_ops_gen.py +2914 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_nvvm_enum_gen.py +2828 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_nvvm_ops_gen.py +25559 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_ods_common.py +274 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_pyir_ops_gen.py +174 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_scf_ops_gen.py +1404 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_ts_enum_gen.py +257 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_ts_ops_gen.py +1650 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_ub_ops_gen.py +123 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_vector_enum_gen.py +119 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/_vector_ops_gen.py +4221 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/arith.py +88 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/builtin.py +46 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/cf.py +6 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/core.py +35 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/cuda.py +276 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/cute.py +16 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/cute_nvgpu.py +15 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/ext.py +961 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/func.py +321 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/gpu/__init__.py +337 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/gpu/passes/__init__.py +5 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/iket.py +13 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/lir.py +14 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/llvm.py +26 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/math.py +6 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/nvgpu.py +8 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/nvvm.py +7 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/pyir.py +17 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/scf.py +324 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/ts.py +64 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/ub.py +6 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/dialects/vector.py +7 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/execution_engine.py +41 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/extras/meta.py +81 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/extras/types.py +170 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/ir.py +386 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/passmanager.py +5 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/rewrite.py +5 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/runtime/__init__.py +1 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir/runtime/np_to_memref.py +181 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/__init__.py +29 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/arith.py +1221 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/cuda.py +99 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/dialect_proxy.py +121 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/dominance.py +75 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/gpu.py +63 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/lru_cache_ir.py +79 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/math.py +2514 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/nanobind_compat.py +71 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/op.py +810 -0
- nvidia_cutlass_dsl/dsl_packages/cutlass/_mlir_helpers/vector.py +1470 -0
- nvidia_cutlass_dsl_libs_base-4.9.0.dev1.dist-info/METADATA +46 -0
- nvidia_cutlass_dsl_libs_base-4.9.0.dev1.dist-info/RECORD +83 -0
- nvidia_cutlass_dsl_libs_base-4.9.0.dev1.dist-info/WHEEL +5 -0
- nvidia_cutlass_dsl_libs_base-4.9.0.dev1.dist-info/licenses/LICENSE +188 -0
- nvidia_cutlass_dsl_libs_base-4.9.0.dev1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
# Licensed under the Apache License v2.0 with LLVM Exceptions.
|
|
2
|
+
# See https://llvm.org/LICENSE.txt for license information.
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
|
|
5
|
+
from typing import Any, Mapping, Sequence
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
_this_dir = os.path.dirname(__file__)
|
|
10
|
+
|
|
11
|
+
def get_lib_dirs() -> Sequence[str]:
|
|
12
|
+
"""Gets the lib directory for linking to shared libraries.
|
|
13
|
+
|
|
14
|
+
On some platforms, the package may need to be built specially to export
|
|
15
|
+
development libraries.
|
|
16
|
+
"""
|
|
17
|
+
return [_this_dir]
|
|
18
|
+
|
|
19
|
+
def get_include_dirs() -> Sequence[str]:
|
|
20
|
+
"""Gets the include directory for compiling against exported C libraries.
|
|
21
|
+
|
|
22
|
+
Depending on how the package was build, development C libraries may or may
|
|
23
|
+
not be present.
|
|
24
|
+
"""
|
|
25
|
+
return [os.path.join(_this_dir, "include")]
|
|
26
|
+
|
|
27
|
+
_dialect_registry = None
|
|
28
|
+
_load_on_create_dialects = None
|
|
29
|
+
|
|
30
|
+
def get_dialect_registry():
|
|
31
|
+
global _dialect_registry
|
|
32
|
+
|
|
33
|
+
if _dialect_registry is None:
|
|
34
|
+
from ._cutlass_ir._mlir import ir
|
|
35
|
+
|
|
36
|
+
_dialect_registry = ir.DialectRegistry()
|
|
37
|
+
|
|
38
|
+
return _dialect_registry
|
|
39
|
+
|
|
40
|
+
def append_load_on_create_dialect(dialect: str):
|
|
41
|
+
global _load_on_create_dialects
|
|
42
|
+
if _load_on_create_dialects is None:
|
|
43
|
+
_load_on_create_dialects = [dialect]
|
|
44
|
+
else:
|
|
45
|
+
_load_on_create_dialects.append(dialect)
|
|
46
|
+
|
|
47
|
+
def get_load_on_create_dialects():
|
|
48
|
+
global _load_on_create_dialects
|
|
49
|
+
if _load_on_create_dialects is None:
|
|
50
|
+
_load_on_create_dialects = []
|
|
51
|
+
return _load_on_create_dialects
|
|
52
|
+
|
|
53
|
+
def _select_and_load_cutlass_ir_toolkit():
|
|
54
|
+
"""Pick a toolkit-flavored _cutlass_ir.so (cu{N} sibling of this file)
|
|
55
|
+
and bind it as the submodule. Runtime libs come from
|
|
56
|
+
<nvidia_cutlass_dsl>/cu{N}/lib/ (wheel) or $LD_LIBRARY_PATH (editable)."""
|
|
57
|
+
import ctypes
|
|
58
|
+
import importlib.util
|
|
59
|
+
import os
|
|
60
|
+
import re
|
|
61
|
+
import sys
|
|
62
|
+
from pathlib import Path
|
|
63
|
+
|
|
64
|
+
# MSVC drops the "lib" prefix.
|
|
65
|
+
_rt_libname = (
|
|
66
|
+
"cute_dsl_runtime.dll"
|
|
67
|
+
if sys.platform.startswith("win32")
|
|
68
|
+
else "libcute_dsl_runtime.so"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def _find_rt_lib(lib_dir):
|
|
72
|
+
"""The runtime library in lib_dir, or None if it is not there."""
|
|
73
|
+
candidate = lib_dir / _rt_libname
|
|
74
|
+
return candidate if candidate.exists() else None
|
|
75
|
+
|
|
76
|
+
_LEGACY_NAME = "cutlass._mlir._mlir_libs._cutlass_ir"
|
|
77
|
+
|
|
78
|
+
# Idempotent: if the module is already in sys.modules, nothing to do.
|
|
79
|
+
if _LEGACY_NAME in sys.modules:
|
|
80
|
+
return
|
|
81
|
+
|
|
82
|
+
# Use the unresolved parent so that an editable / symlinked install (where
|
|
83
|
+
# _mlir_libs/__init__.py is a symlink into the LLVM-prebuilt source tree)
|
|
84
|
+
# still scans the dir Python imported from — where the CTK-tagged .so
|
|
85
|
+
# siblings actually live — rather than the symlink target.
|
|
86
|
+
this_dir = Path(__file__).parent
|
|
87
|
+
|
|
88
|
+
# Match both the Linux (_cutlass_ir.cu{N}.cpython-….so) and Windows
|
|
89
|
+
# (_cutlass_ir.cu{N}.cp###-win_amd64.pyd) extension-module names; skip the
|
|
90
|
+
# .pyi stub and the Windows .lib import library.
|
|
91
|
+
flavor_re = re.compile(r"^_cutlass_ir\.cu(\d+)\..*\.(?:so|pyd)$")
|
|
92
|
+
# Walk up to <nvidia_cutlass_dsl>/ so we can locate each flavor's
|
|
93
|
+
# runtime-library sibling at <nvidia_cutlass_dsl>/cu{N}/lib/. Walk by
|
|
94
|
+
# name so wheel + editable installs (different parent-chain depths)
|
|
95
|
+
# resolve identically.
|
|
96
|
+
nvidia_root = None
|
|
97
|
+
for parent in this_dir.parents:
|
|
98
|
+
if parent.name == "nvidia_cutlass_dsl":
|
|
99
|
+
nvidia_root = parent
|
|
100
|
+
break
|
|
101
|
+
|
|
102
|
+
# available[ctk] -> (so_path, runtime_lib_dir_or_None)
|
|
103
|
+
available = {}
|
|
104
|
+
for entry in this_dir.iterdir():
|
|
105
|
+
m = flavor_re.match(entry.name)
|
|
106
|
+
if not m:
|
|
107
|
+
continue
|
|
108
|
+
toolkit_ver = int(m.group(1))
|
|
109
|
+
runtime_dir = None
|
|
110
|
+
if nvidia_root is not None:
|
|
111
|
+
runtime_lib = _find_rt_lib(nvidia_root / f"cu{toolkit_ver}" / "lib")
|
|
112
|
+
legacy_lib = _find_rt_lib(nvidia_root / "lib")
|
|
113
|
+
if runtime_lib is not None:
|
|
114
|
+
runtime_dir = runtime_lib.parent
|
|
115
|
+
elif legacy_lib is not None:
|
|
116
|
+
# Non-wheel builds (e.g. the Windows cutlass-dsl build) package the
|
|
117
|
+
# runtime under <root>/lib/ rather than cu{N}/lib/.
|
|
118
|
+
runtime_dir = legacy_lib.parent
|
|
119
|
+
elif (
|
|
120
|
+
nvidia_root / f"cu{toolkit_ver}" / "lib"
|
|
121
|
+
).exists() and not sys.platform.startswith("win32"):
|
|
122
|
+
# cu{N}/lib/ exists but the runtime library is missing -- incomplete
|
|
123
|
+
# install. Fail loudly. (Skipped on Windows, whose cutlass-dsl build
|
|
124
|
+
# artifact uses <root>/lib + CUTE_DSL_LIBS.)
|
|
125
|
+
raise RuntimeError(
|
|
126
|
+
f"cu{toolkit_ver} install is incomplete: "
|
|
127
|
+
f"{entry} present but {_rt_libname} is missing from "
|
|
128
|
+
f"cu{toolkit_ver}/lib under {nvidia_root}. "
|
|
129
|
+
f"Reinstall the cu{toolkit_ver} flavor."
|
|
130
|
+
)
|
|
131
|
+
# No cu{N}/ at all → editable install; runtime resolves via
|
|
132
|
+
# $LD_LIBRARY_PATH or build-tree RPATH.
|
|
133
|
+
available[toolkit_ver] = (entry, runtime_dir)
|
|
134
|
+
|
|
135
|
+
if not available:
|
|
136
|
+
raise RuntimeError(
|
|
137
|
+
"No CTK flavor installed: expected one or more of "
|
|
138
|
+
f"{this_dir}/_cutlass_ir.cu{{N}}.cpython-...so . "
|
|
139
|
+
"Try `pip install nvidia-cutlass-dsl` (cu12 default) or "
|
|
140
|
+
"`pip install 'nvidia-cutlass-dsl[cu13]'`."
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
# Probe driver. Failure is non-fatal (CPU-only / no-GPU containers).
|
|
144
|
+
driver_cuda_int = None
|
|
145
|
+
try:
|
|
146
|
+
libcuda = ctypes.CDLL(
|
|
147
|
+
"nvcuda.dll" if sys.platform.startswith("win32") else "libcuda.so.1"
|
|
148
|
+
)
|
|
149
|
+
version = ctypes.c_int(0)
|
|
150
|
+
if libcuda.cuDriverGetVersion(ctypes.byref(version)) == 0:
|
|
151
|
+
driver_cuda_int = version.value
|
|
152
|
+
except (OSError, AttributeError):
|
|
153
|
+
driver_cuda_int = None
|
|
154
|
+
|
|
155
|
+
if driver_cuda_int is not None:
|
|
156
|
+
# cuDriverGetVersion returns an int like 12090 = "CUDA 12.9", 13010 = "CUDA 13.1".
|
|
157
|
+
# Driver supports cuX if the reported runtime major >= X.
|
|
158
|
+
driver_major = driver_cuda_int // 1000
|
|
159
|
+
compatible = sorted(
|
|
160
|
+
(toolkit_ver for toolkit_ver in available if driver_major >= toolkit_ver), reverse=True
|
|
161
|
+
)
|
|
162
|
+
if not compatible:
|
|
163
|
+
installed = ", ".join(f"cu{c}" for c in sorted(available))
|
|
164
|
+
driver_str = f"{driver_major}.{(driver_cuda_int % 1000) // 10}"
|
|
165
|
+
raise RuntimeError(
|
|
166
|
+
f"None of the installed toolkit flavors ({installed}) are compatible "
|
|
167
|
+
f"with the CUDA driver (driver supports up to CUDA {driver_str}). "
|
|
168
|
+
"Install a compatible flavor (e.g. `pip install nvidia-cutlass-dsl` "
|
|
169
|
+
"for cu12) or update the driver."
|
|
170
|
+
)
|
|
171
|
+
else:
|
|
172
|
+
# Driver-absent fallback: pick newest installed.
|
|
173
|
+
compatible = sorted(available.keys(), reverse=True)
|
|
174
|
+
|
|
175
|
+
chosen_toolkit_ver = compatible[0]
|
|
176
|
+
chosen_so, chosen_runtime_dir = available[chosen_toolkit_ver]
|
|
177
|
+
|
|
178
|
+
spec = importlib.util.spec_from_file_location(_LEGACY_NAME, str(chosen_so))
|
|
179
|
+
if spec is None or spec.loader is None:
|
|
180
|
+
raise RuntimeError(
|
|
181
|
+
f"Failed to build import spec for the cu{chosen_toolkit_ver} pybind module at {chosen_so}"
|
|
182
|
+
)
|
|
183
|
+
module = importlib.util.module_from_spec(spec)
|
|
184
|
+
sys.modules[_LEGACY_NAME] = module
|
|
185
|
+
try:
|
|
186
|
+
spec.loader.exec_module(module)
|
|
187
|
+
except BaseException:
|
|
188
|
+
sys.modules.pop(_LEGACY_NAME, None)
|
|
189
|
+
raise
|
|
190
|
+
|
|
191
|
+
# Bind as an attribute of the parent package so attribute-style access
|
|
192
|
+
# (e.g. getattr(cutlass._mlir._mlir_libs, "_cutlass_ir"), which the DSL
|
|
193
|
+
# preprocessor's exec_imports relies on for `from cutlass._mlir._mlir_libs
|
|
194
|
+
# import _cutlass_ir`) resolves. Python's import statement sets this when
|
|
195
|
+
# loading a submodule, but our manual spec_from_file_location +
|
|
196
|
+
# exec_module path bypasses that step.
|
|
197
|
+
parent_pkg = sys.modules.get(__name__)
|
|
198
|
+
if parent_pkg is not None:
|
|
199
|
+
parent_pkg._cutlass_ir = module
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# Module-level: load the toolkit-flavored _cutlass_ir into sys.modules BEFORE any
|
|
203
|
+
# subsequent code (including get_dialect_registry() and _site_initialize())
|
|
204
|
+
# tries `from ._cutlass_ir._mlir import ir`. Without this, Python's normal
|
|
205
|
+
# import machinery cannot resolve `_cutlass_ir` because the file is named
|
|
206
|
+
# `_cutlass_ir.cu{N}.cpython-…so` (a stem the standard finder skips).
|
|
207
|
+
_select_and_load_cutlass_ir_toolkit()
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _site_initialize():
|
|
211
|
+
import importlib
|
|
212
|
+
import itertools
|
|
213
|
+
import logging
|
|
214
|
+
from ._cutlass_ir._mlir import ir
|
|
215
|
+
|
|
216
|
+
logger = logging.getLogger(__name__)
|
|
217
|
+
post_init_hooks = []
|
|
218
|
+
disable_multithreading = False
|
|
219
|
+
|
|
220
|
+
disable_load_all_available_dialects = False
|
|
221
|
+
|
|
222
|
+
def process_initializer_module(module_name):
|
|
223
|
+
nonlocal disable_multithreading
|
|
224
|
+
nonlocal disable_load_all_available_dialects
|
|
225
|
+
try:
|
|
226
|
+
m = importlib.import_module(f".{module_name}", __name__)
|
|
227
|
+
except ModuleNotFoundError:
|
|
228
|
+
return False
|
|
229
|
+
except ImportError:
|
|
230
|
+
message = (
|
|
231
|
+
f"Error importing mlir initializer {module_name}. This may "
|
|
232
|
+
"happen in unclean incremental builds but is likely a real bug if "
|
|
233
|
+
"encountered otherwise and the MLIR Python API may not function."
|
|
234
|
+
)
|
|
235
|
+
logger.warning(message, exc_info=True)
|
|
236
|
+
return False
|
|
237
|
+
|
|
238
|
+
logger.debug("Initializing MLIR with module: %s", module_name)
|
|
239
|
+
if hasattr(m, "register_dialects"):
|
|
240
|
+
logger.debug("Registering dialects from initializer %r", m)
|
|
241
|
+
m.register_dialects(get_dialect_registry())
|
|
242
|
+
if hasattr(m, "context_init_hook"):
|
|
243
|
+
logger.debug("Adding context init hook from %r", m)
|
|
244
|
+
post_init_hooks.append(m.context_init_hook)
|
|
245
|
+
if hasattr(m, "disable_multithreading"):
|
|
246
|
+
if bool(m.disable_multithreading):
|
|
247
|
+
logger.debug("Disabling multi-threading for context")
|
|
248
|
+
disable_multithreading = True
|
|
249
|
+
if hasattr(m, "disable_load_all_available_dialects"):
|
|
250
|
+
disable_load_all_available_dialects = True
|
|
251
|
+
return True
|
|
252
|
+
|
|
253
|
+
init_module = None
|
|
254
|
+
if process_initializer_module("_mlirRegisterEverything"):
|
|
255
|
+
init_module = importlib.import_module(f"._mlirRegisterEverything", __name__)
|
|
256
|
+
|
|
257
|
+
if not process_initializer_module("_cutlass_ir"):
|
|
258
|
+
raise RuntimeError("Could not successfully initialize _cutlass_ir module.")
|
|
259
|
+
|
|
260
|
+
ir._Context = ir.Context
|
|
261
|
+
|
|
262
|
+
class Context(ir._Context):
|
|
263
|
+
def __init__(
|
|
264
|
+
self, load_on_create_dialects=None, thread_pool=None, *args, **kwargs
|
|
265
|
+
):
|
|
266
|
+
super().__init__(*args, **kwargs)
|
|
267
|
+
self.append_dialect_registry(get_dialect_registry())
|
|
268
|
+
for hook in post_init_hooks:
|
|
269
|
+
hook(self)
|
|
270
|
+
if disable_multithreading and thread_pool is not None:
|
|
271
|
+
raise ValueError(
|
|
272
|
+
"Context constructor has given thread_pool argument, "
|
|
273
|
+
"but disable_multithreading flag is True. "
|
|
274
|
+
"Please, set thread_pool argument to None or "
|
|
275
|
+
"set disable_multithreading flag to False."
|
|
276
|
+
)
|
|
277
|
+
if not disable_multithreading:
|
|
278
|
+
if thread_pool is None:
|
|
279
|
+
self.enable_multithreading(True)
|
|
280
|
+
else:
|
|
281
|
+
self.set_thread_pool(thread_pool)
|
|
282
|
+
if load_on_create_dialects is not None:
|
|
283
|
+
logger.debug(
|
|
284
|
+
"Loading all dialects from load_on_create_dialects arg %r",
|
|
285
|
+
load_on_create_dialects,
|
|
286
|
+
)
|
|
287
|
+
for dialect in load_on_create_dialects:
|
|
288
|
+
|
|
289
|
+
_ = self.dialects[dialect]
|
|
290
|
+
else:
|
|
291
|
+
if disable_load_all_available_dialects:
|
|
292
|
+
dialects = get_load_on_create_dialects()
|
|
293
|
+
if dialects:
|
|
294
|
+
logger.debug(
|
|
295
|
+
"Loading all dialects from global load_on_create_dialects %r",
|
|
296
|
+
dialects,
|
|
297
|
+
)
|
|
298
|
+
for dialect in dialects:
|
|
299
|
+
|
|
300
|
+
_ = self.dialects[dialect]
|
|
301
|
+
else:
|
|
302
|
+
logger.debug("Loading all available dialects")
|
|
303
|
+
self.load_all_available_dialects()
|
|
304
|
+
if init_module:
|
|
305
|
+
logger.debug(
|
|
306
|
+
"Registering translations from initializer %r", init_module
|
|
307
|
+
)
|
|
308
|
+
init_module.register_llvm_translations(self)
|
|
309
|
+
|
|
310
|
+
ir.Context = Context
|
|
311
|
+
|
|
312
|
+
Sequence.register(ir.BlockArgumentList)
|
|
313
|
+
Sequence.register(ir.BlockList)
|
|
314
|
+
Sequence.register(ir.BlockSuccessors)
|
|
315
|
+
Sequence.register(ir.BlockPredecessors)
|
|
316
|
+
Sequence.register(ir.OperationList)
|
|
317
|
+
Sequence.register(ir.OpOperandList)
|
|
318
|
+
Sequence.register(ir.OpOperands)
|
|
319
|
+
Sequence.register(ir.OpResultList)
|
|
320
|
+
Sequence.register(ir.OpSuccessors)
|
|
321
|
+
Sequence.register(ir.RegionSequence)
|
|
322
|
+
Mapping.register(ir.OpAttributeMap)
|
|
323
|
+
|
|
324
|
+
_site_initialize()
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
from collections.abc import Sequence
|
|
3
|
+
|
|
4
|
+
from ._mlir import ir as _ir
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"ExecutionEngine",
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
class ExecutionEngine:
|
|
11
|
+
def __init__(self, module: _ir.Module, opt_level: int = 2, shared_libs: Sequence[str] = ...) -> None: ...
|
|
12
|
+
def _CAPICreate(self) -> object: ...
|
|
13
|
+
def _testing_release(self) -> None: ...
|
|
14
|
+
def dump_to_object_file(self, file_name: str) -> None: ...
|
|
15
|
+
def raw_lookup(self, func_name: str) -> int: ...
|
|
16
|
+
def raw_register_runtime(self, name: str, callback: object) -> None: ...
|
|
17
|
+
def init() -> None: ...
|
|
18
|
+
@property
|
|
19
|
+
def _CAPIPtr(self) -> object: ...
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
|
|
2
|
+
# Autogenerated by mlir-tblgen; don't manually edit.
|
|
3
|
+
|
|
4
|
+
from enum import IntEnum, auto, IntFlag
|
|
5
|
+
from functools import lru_cache as _lru_cache
|
|
6
|
+
from ._ods_common import _cext as _ods_cext
|
|
7
|
+
from ..ir import register_attribute_builder
|
|
8
|
+
_ods_ir = _ods_cext.ir
|
|
9
|
+
|
|
10
|
+
class CmpFPredicate(IntEnum):
|
|
11
|
+
"""allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15"""
|
|
12
|
+
|
|
13
|
+
AlwaysFalse = 0
|
|
14
|
+
OEQ = 1
|
|
15
|
+
OGT = 2
|
|
16
|
+
OGE = 3
|
|
17
|
+
OLT = 4
|
|
18
|
+
OLE = 5
|
|
19
|
+
ONE = 6
|
|
20
|
+
ORD = 7
|
|
21
|
+
UEQ = 8
|
|
22
|
+
UGT = 9
|
|
23
|
+
UGE = 10
|
|
24
|
+
ULT = 11
|
|
25
|
+
ULE = 12
|
|
26
|
+
UNE = 13
|
|
27
|
+
UNO = 14
|
|
28
|
+
AlwaysTrue = 15
|
|
29
|
+
|
|
30
|
+
def __str__(self):
|
|
31
|
+
if self is CmpFPredicate.AlwaysFalse:
|
|
32
|
+
return "false"
|
|
33
|
+
if self is CmpFPredicate.OEQ:
|
|
34
|
+
return "oeq"
|
|
35
|
+
if self is CmpFPredicate.OGT:
|
|
36
|
+
return "ogt"
|
|
37
|
+
if self is CmpFPredicate.OGE:
|
|
38
|
+
return "oge"
|
|
39
|
+
if self is CmpFPredicate.OLT:
|
|
40
|
+
return "olt"
|
|
41
|
+
if self is CmpFPredicate.OLE:
|
|
42
|
+
return "ole"
|
|
43
|
+
if self is CmpFPredicate.ONE:
|
|
44
|
+
return "one"
|
|
45
|
+
if self is CmpFPredicate.ORD:
|
|
46
|
+
return "ord"
|
|
47
|
+
if self is CmpFPredicate.UEQ:
|
|
48
|
+
return "ueq"
|
|
49
|
+
if self is CmpFPredicate.UGT:
|
|
50
|
+
return "ugt"
|
|
51
|
+
if self is CmpFPredicate.UGE:
|
|
52
|
+
return "uge"
|
|
53
|
+
if self is CmpFPredicate.ULT:
|
|
54
|
+
return "ult"
|
|
55
|
+
if self is CmpFPredicate.ULE:
|
|
56
|
+
return "ule"
|
|
57
|
+
if self is CmpFPredicate.UNE:
|
|
58
|
+
return "une"
|
|
59
|
+
if self is CmpFPredicate.UNO:
|
|
60
|
+
return "uno"
|
|
61
|
+
if self is CmpFPredicate.AlwaysTrue:
|
|
62
|
+
return "true"
|
|
63
|
+
raise ValueError("Unknown CmpFPredicate enum entry.")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@register_attribute_builder("Arith_CmpFPredicateAttr", allow_existing=True)
|
|
68
|
+
def _arith_cmpfpredicateattr(x, context):
|
|
69
|
+
return _ods_ir.IntegerAttr.get(_ods_ir.IntegerType.get_signless(64, context=context), int(x))
|
|
70
|
+
|
|
71
|
+
class CmpIPredicate(IntEnum):
|
|
72
|
+
"""allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9"""
|
|
73
|
+
|
|
74
|
+
eq = 0
|
|
75
|
+
ne = 1
|
|
76
|
+
slt = 2
|
|
77
|
+
sle = 3
|
|
78
|
+
sgt = 4
|
|
79
|
+
sge = 5
|
|
80
|
+
ult = 6
|
|
81
|
+
ule = 7
|
|
82
|
+
ugt = 8
|
|
83
|
+
uge = 9
|
|
84
|
+
|
|
85
|
+
def __str__(self):
|
|
86
|
+
if self is CmpIPredicate.eq:
|
|
87
|
+
return "eq"
|
|
88
|
+
if self is CmpIPredicate.ne:
|
|
89
|
+
return "ne"
|
|
90
|
+
if self is CmpIPredicate.slt:
|
|
91
|
+
return "slt"
|
|
92
|
+
if self is CmpIPredicate.sle:
|
|
93
|
+
return "sle"
|
|
94
|
+
if self is CmpIPredicate.sgt:
|
|
95
|
+
return "sgt"
|
|
96
|
+
if self is CmpIPredicate.sge:
|
|
97
|
+
return "sge"
|
|
98
|
+
if self is CmpIPredicate.ult:
|
|
99
|
+
return "ult"
|
|
100
|
+
if self is CmpIPredicate.ule:
|
|
101
|
+
return "ule"
|
|
102
|
+
if self is CmpIPredicate.ugt:
|
|
103
|
+
return "ugt"
|
|
104
|
+
if self is CmpIPredicate.uge:
|
|
105
|
+
return "uge"
|
|
106
|
+
raise ValueError("Unknown CmpIPredicate enum entry.")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@register_attribute_builder("Arith_CmpIPredicateAttr", allow_existing=True)
|
|
111
|
+
def _arith_cmpipredicateattr(x, context):
|
|
112
|
+
return _ods_ir.IntegerAttr.get(_ods_ir.IntegerType.get_signless(64, context=context), int(x))
|
|
113
|
+
|
|
114
|
+
class IntegerOverflowFlags(IntFlag):
|
|
115
|
+
"""Integer overflow arith flags"""
|
|
116
|
+
|
|
117
|
+
none = 0
|
|
118
|
+
nsw = 1
|
|
119
|
+
nuw = 2
|
|
120
|
+
|
|
121
|
+
def __iter__(self):
|
|
122
|
+
return iter([case for case in type(self) if (self & case) is case and self is not case])
|
|
123
|
+
def __len__(self):
|
|
124
|
+
return bin(self).count("1")
|
|
125
|
+
|
|
126
|
+
def __str__(self):
|
|
127
|
+
if len(self) > 1:
|
|
128
|
+
return ", ".join(map(str, self))
|
|
129
|
+
if self is IntegerOverflowFlags.none:
|
|
130
|
+
return "none"
|
|
131
|
+
if self is IntegerOverflowFlags.nsw:
|
|
132
|
+
return "nsw"
|
|
133
|
+
if self is IntegerOverflowFlags.nuw:
|
|
134
|
+
return "nuw"
|
|
135
|
+
raise ValueError("Unknown IntegerOverflowFlags enum entry.")
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@register_attribute_builder("Arith_IntegerOverflowFlags", allow_existing=True)
|
|
140
|
+
def _arith_integeroverflowflags(x, context):
|
|
141
|
+
return _ods_ir.IntegerAttr.get(_ods_ir.IntegerType.get_signless(32, context=context), int(x))
|
|
142
|
+
|
|
143
|
+
class RoundingMode(IntEnum):
|
|
144
|
+
"""Floating point rounding mode"""
|
|
145
|
+
|
|
146
|
+
to_nearest_even = 0
|
|
147
|
+
downward = 1
|
|
148
|
+
upward = 2
|
|
149
|
+
toward_zero = 3
|
|
150
|
+
to_nearest_away = 4
|
|
151
|
+
|
|
152
|
+
def __str__(self):
|
|
153
|
+
if self is RoundingMode.to_nearest_even:
|
|
154
|
+
return "to_nearest_even"
|
|
155
|
+
if self is RoundingMode.downward:
|
|
156
|
+
return "downward"
|
|
157
|
+
if self is RoundingMode.upward:
|
|
158
|
+
return "upward"
|
|
159
|
+
if self is RoundingMode.toward_zero:
|
|
160
|
+
return "toward_zero"
|
|
161
|
+
if self is RoundingMode.to_nearest_away:
|
|
162
|
+
return "to_nearest_away"
|
|
163
|
+
raise ValueError("Unknown RoundingMode enum entry.")
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@register_attribute_builder("Arith_RoundingModeAttr", allow_existing=True)
|
|
168
|
+
def _arith_roundingmodeattr(x, context):
|
|
169
|
+
return _ods_ir.IntegerAttr.get(_ods_ir.IntegerType.get_signless(32, context=context), int(x))
|
|
170
|
+
|
|
171
|
+
class AtomicRMWKind(IntEnum):
|
|
172
|
+
"""allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15"""
|
|
173
|
+
|
|
174
|
+
addf = 0
|
|
175
|
+
addi = 1
|
|
176
|
+
andi = 2
|
|
177
|
+
assign = 3
|
|
178
|
+
maximumf = 4
|
|
179
|
+
maxnumf = 5
|
|
180
|
+
maxs = 6
|
|
181
|
+
maxu = 7
|
|
182
|
+
minimumf = 8
|
|
183
|
+
minnumf = 9
|
|
184
|
+
mins = 10
|
|
185
|
+
minu = 11
|
|
186
|
+
mulf = 12
|
|
187
|
+
muli = 13
|
|
188
|
+
ori = 14
|
|
189
|
+
xori = 15
|
|
190
|
+
|
|
191
|
+
def __str__(self):
|
|
192
|
+
if self is AtomicRMWKind.addf:
|
|
193
|
+
return "addf"
|
|
194
|
+
if self is AtomicRMWKind.addi:
|
|
195
|
+
return "addi"
|
|
196
|
+
if self is AtomicRMWKind.andi:
|
|
197
|
+
return "andi"
|
|
198
|
+
if self is AtomicRMWKind.assign:
|
|
199
|
+
return "assign"
|
|
200
|
+
if self is AtomicRMWKind.maximumf:
|
|
201
|
+
return "maximumf"
|
|
202
|
+
if self is AtomicRMWKind.maxnumf:
|
|
203
|
+
return "maxnumf"
|
|
204
|
+
if self is AtomicRMWKind.maxs:
|
|
205
|
+
return "maxs"
|
|
206
|
+
if self is AtomicRMWKind.maxu:
|
|
207
|
+
return "maxu"
|
|
208
|
+
if self is AtomicRMWKind.minimumf:
|
|
209
|
+
return "minimumf"
|
|
210
|
+
if self is AtomicRMWKind.minnumf:
|
|
211
|
+
return "minnumf"
|
|
212
|
+
if self is AtomicRMWKind.mins:
|
|
213
|
+
return "mins"
|
|
214
|
+
if self is AtomicRMWKind.minu:
|
|
215
|
+
return "minu"
|
|
216
|
+
if self is AtomicRMWKind.mulf:
|
|
217
|
+
return "mulf"
|
|
218
|
+
if self is AtomicRMWKind.muli:
|
|
219
|
+
return "muli"
|
|
220
|
+
if self is AtomicRMWKind.ori:
|
|
221
|
+
return "ori"
|
|
222
|
+
if self is AtomicRMWKind.xori:
|
|
223
|
+
return "xori"
|
|
224
|
+
raise ValueError("Unknown AtomicRMWKind enum entry.")
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
@register_attribute_builder("AtomicRMWKindAttr", allow_existing=True)
|
|
229
|
+
def _atomicrmwkindattr(x, context):
|
|
230
|
+
return _ods_ir.IntegerAttr.get(_ods_ir.IntegerType.get_signless(64, context=context), int(x))
|
|
231
|
+
|
|
232
|
+
class FastMathFlags(IntFlag):
|
|
233
|
+
"""Floating point fast math flags"""
|
|
234
|
+
|
|
235
|
+
none = 0
|
|
236
|
+
reassoc = 1
|
|
237
|
+
nnan = 2
|
|
238
|
+
ninf = 4
|
|
239
|
+
nsz = 8
|
|
240
|
+
arcp = 16
|
|
241
|
+
contract = 32
|
|
242
|
+
afn = 64
|
|
243
|
+
fast = 127
|
|
244
|
+
|
|
245
|
+
def __iter__(self):
|
|
246
|
+
return iter([case for case in type(self) if (self & case) is case and self is not case])
|
|
247
|
+
def __len__(self):
|
|
248
|
+
return bin(self).count("1")
|
|
249
|
+
|
|
250
|
+
def __str__(self):
|
|
251
|
+
if len(self) > 1:
|
|
252
|
+
return ",".join(map(str, self))
|
|
253
|
+
if self is FastMathFlags.none:
|
|
254
|
+
return "none"
|
|
255
|
+
if self is FastMathFlags.reassoc:
|
|
256
|
+
return "reassoc"
|
|
257
|
+
if self is FastMathFlags.nnan:
|
|
258
|
+
return "nnan"
|
|
259
|
+
if self is FastMathFlags.ninf:
|
|
260
|
+
return "ninf"
|
|
261
|
+
if self is FastMathFlags.nsz:
|
|
262
|
+
return "nsz"
|
|
263
|
+
if self is FastMathFlags.arcp:
|
|
264
|
+
return "arcp"
|
|
265
|
+
if self is FastMathFlags.contract:
|
|
266
|
+
return "contract"
|
|
267
|
+
if self is FastMathFlags.afn:
|
|
268
|
+
return "afn"
|
|
269
|
+
if self is FastMathFlags.fast:
|
|
270
|
+
return "fast"
|
|
271
|
+
raise ValueError("Unknown FastMathFlags enum entry.")
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
# Cache only immutable spellings, never context-owned IR. The 128 entries
|
|
275
|
+
# cover all combinations of the seven fast-math bits.
|
|
276
|
+
FastMathFlags.__str__ = _lru_cache(maxsize=128, typed=True)(
|
|
277
|
+
FastMathFlags.__str__
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@register_attribute_builder("FastMathFlags", allow_existing=True)
|
|
283
|
+
def _fastmathflags(x, context):
|
|
284
|
+
return _ods_ir.IntegerAttr.get(_ods_ir.IntegerType.get_signless(32, context=context), int(x))
|
|
285
|
+
|
|
286
|
+
@register_attribute_builder("arith.Arith_FastMathAttr")
|
|
287
|
+
def _arith_fastmathattr(x, context):
|
|
288
|
+
return _ods_ir.Attribute.parse(f'#arith.fastmath<{str(x)}>', context=context)
|
|
289
|
+
|
|
290
|
+
@register_attribute_builder("arith.Arith_IntegerOverflowAttr")
|
|
291
|
+
def _arith_integeroverflowattr(x, context):
|
|
292
|
+
return _ods_ir.Attribute.parse(f'#arith.overflow<{str(x)}>', context=context)
|
|
293
|
+
|