Skip to content

Commit 64c2287

Browse files
committed
[SPEC] Fix spec __init__.py, _filecheck.py, _internal_testing.py in triton dir
1 parent 63e6f97 commit 64c2287

7 files changed

Lines changed: 31 additions & 463 deletions

File tree

python/triton/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
# ---------------------------------------
55
# Note: import order is significant here.
66

7-
# flagtree backend path specialization
8-
from .flagtree_spec import spec_path
9-
10-
spec_path(__path__)
11-
127
# submodules
138
from .runtime import (
149
autotune,

python/triton/_filecheck.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,13 @@
1717
# ===-----------------------------------------------------------------------===#
1818

1919
# Stub target for testing the frontend.
20-
stub_target = GPUTarget("cuda", 100, 32)
20+
# flagtree backend path specialization
21+
from triton.flagtree_spec import spec
22+
if not spec("spec_get_stub_target"):
23+
stub_target = GPUTarget("cuda", 100, 32)
2124

2225
triton_dir = os.path.dirname(__file__)
23-
_filecheck_local = os.path.join(triton_dir, "FileCheck")
24-
_filecheck_system = shutil.which("FileCheck")
25-
_filecheck_path = _filecheck_local if os.path.isfile(_filecheck_local) else _filecheck_system
26-
27-
_MISSING_FILECHECK_MSG = ("FileCheck binary not found. Install it with your package manager\n"
28-
" (e.g. apt-get install llvm-15-tools) or place it next to this module:\n"
29-
f" {_filecheck_local}")
30-
31-
32-
def _get_filecheck_path():
33-
"""Return the path to the FileCheck binary, or raise FileNotFoundError."""
34-
if _filecheck_path is None:
35-
raise FileNotFoundError(_MISSING_FILECHECK_MSG)
36-
return _filecheck_path
26+
filecheck_path = os.path.join(triton_dir, "FileCheck")
3727

3828

3929
class MatchError(ValueError):

python/triton/_internal_testing.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ def is_ampere_or_newer():
4343

4444

4545
def is_blackwell():
46-
return is_cuda() and torch.cuda.get_device_capability()[0] == 10
46+
return is_cuda() and torch.cuda.get_device_capability()[0] in [10, 11] # Triton 3.7
47+
48+
49+
def is_blackwell_ultra():
50+
return is_cuda() and torch.cuda.get_device_capability()[0:2] == (10, 3) # Triton 3.7
4751

4852

4953
def is_hopper_or_newer():
@@ -106,6 +110,17 @@ def is_xpu():
106110
return False if target is None else target.backend == "xpu"
107111

108112

113+
# flagtree: mthreads
114+
def is_musa():
115+
target = get_current_target()
116+
return False if target is None else target.backend == "musa"
117+
118+
119+
# flagtree: mthreads
120+
def is_musa_ph1():
121+
return is_musa() and torch.musa.get_device_capability() == (3, 1)
122+
123+
109124
def get_arch():
110125
target = get_current_target()
111126
return "" if target is None else str(target.arch)
@@ -156,6 +171,8 @@ def to_triton(x: np.ndarray, device, dst_type=None) -> Union[TensorWrapper, torc
156171
if dst_type and 'float8' in dst_type:
157172
return reinterpret(torch.tensor(x, device=device), getattr(tl, dst_type))
158173
if t == 'float32' and dst_type == 'bfloat16':
174+
if is_musa(): # flagtree mthreads
175+
return torch.tensor(x, device='cpu').bfloat16().to(device)
159176
return torch.tensor(x, device=device).bfloat16()
160177
return torch.tensor(x, device=device)
161178

python/triton/flagtree_spec.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@ def _triton_root() -> str | None:
1616
def _get_spec_module():
1717
global _spec_module
1818
from ._flagtree_backend import FLAGTREE_BACKEND
19-
if not FLAGTREE_BACKEND:
20-
return None
21-
triton_root = _triton_root()
22-
if triton_root is None:
23-
return None
24-
spec_dir = os.path.join(triton_root, "backends", FLAGTREE_BACKEND, "spec")
25-
if not os.path.isdir(spec_dir):
26-
return None
2719
if _spec_module is not None:
2820
return _spec_module
21+
if not FLAGTREE_BACKEND:
22+
return None
2923
try:
30-
_spec_module = importlib.import_module(f"triton.backends.{FLAGTREE_BACKEND}.spec")
24+
_spec_module = importlib.import_module(f"triton.backends.{FLAGTREE_BACKEND}.spec.triton")
3125
except ImportError:
3226
return None
3327
return _spec_module

third_party/mthreads/backend/spec/__init__.py renamed to third_party/mthreads/backend/spec/triton/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ def _experimental_descriptor_store(desc_pointer, value, offsets, _semantic=None)
8282
_ext._experimental_descriptor_store = _experimental_descriptor_store
8383

8484
bind_language_extension_symbols_to_tl(_ext)
85+
86+
87+
def spec_get_stub_target() -> GPUTarget:
88+
arch = os.environ.get("TRITON_OVERRIDE_ARCH") or os.environ.get("TRITON_MUSA_ARCH") or "ph1"
89+
return GPUTarget("musa", arch, 32)

third_party/mthreads/backend/spec/triton/_filecheck.py

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)