Skip to content

Commit 10966a1

Browse files
committed
[SPEC] Fix spec knobs.py
1 parent abb8a14 commit 10966a1

3 files changed

Lines changed: 110 additions & 657 deletions

File tree

python/triton/_internal_testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ def is_xpu():
110110
return False if target is None else target.backend == "xpu"
111111

112112

113-
# flagtree: mthreads
113+
# flagtree mthreads
114114
def is_musa():
115115
target = get_current_target()
116116
return False if target is None else target.backend == "musa"
117117

118118

119-
# flagtree: mthreads
119+
# flagtree mthreads
120120
def is_musa_ph1():
121121
return is_musa() and torch.musa.get_device_capability() == (3, 1)
122122

python/triton/knobs.py

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,71 @@ def transform(self, path: str) -> NvidiaTool:
217217
raise RuntimeError(f"Cannot find {self.binary}")
218218

219219

220+
# flagtree mthreads
221+
@dataclass
222+
class MUSATool:
223+
path: str
224+
version: str
225+
226+
@staticmethod
227+
@functools.lru_cache
228+
def from_path(path: str) -> Optional["MUSATool"]:
229+
import shutil
230+
if not path:
231+
return None
232+
resolved = pathlib.Path(path).expanduser()
233+
if not resolved.is_file():
234+
which = shutil.which(str(resolved))
235+
if which is None:
236+
return None
237+
resolved = pathlib.Path(which)
238+
try:
239+
result = subprocess.check_output([str(resolved), "--version"], stderr=subprocess.STDOUT)
240+
except (subprocess.CalledProcessError, FileNotFoundError, PermissionError, OSError):
241+
return None
242+
version_lines = result.decode("utf-8", errors="replace").splitlines()
243+
version = next((line.strip() for line in version_lines if line.strip()), "")
244+
return MUSATool(str(resolved), version)
245+
246+
247+
class env_musa_tool(env_base[str, MUSATool]):
248+
249+
def __init__(self, key: str, binary: str) -> None:
250+
self.binary = binary + sysconfig.get_config_var("EXE")
251+
super().__init__(key)
252+
253+
def _candidate_paths(self, path: Optional[str]) -> list[str]:
254+
candidates = []
255+
if path:
256+
candidates.append(path)
257+
258+
toolchain_path = getenv("TRITON_MUSA_TOOLCHAIN_PATH")
259+
if toolchain_path:
260+
candidates.append(os.path.join(toolchain_path, self.binary))
261+
262+
mtcc_bin_path = getenv("MTCC_BIN_PATH")
263+
if mtcc_bin_path:
264+
candidates.append(os.path.join(mtcc_bin_path, self.binary))
265+
266+
musa_home = getenv("MUSA_HOME") or getenv("MUSA_ROOT")
267+
if musa_home:
268+
candidates.append(os.path.join(musa_home, "bin", self.binary))
269+
270+
if which := shutil.which(self.binary):
271+
candidates.append(which)
272+
273+
return candidates
274+
275+
def get(self) -> MUSATool:
276+
return self.transform(getenv(self.key))
277+
278+
def transform(self, path: Optional[str]) -> MUSATool:
279+
for candidate in self._candidate_paths(path):
280+
if tool := MUSATool.from_path(candidate):
281+
return tool
282+
raise RuntimeError(f"Cannot find {self.binary}")
283+
284+
220285
# Separate classes so that types are correct
221286
class env_opt_str(env_base[Optional[str], Optional[str]]):
222287

@@ -552,12 +617,52 @@ class metax_knobs(base_knobs):
552617
mlir_opt_path = os.path.join(maca_path, "mxgpu_llvm", "bin", "mlir-opt") if use_maca else None
553618

554619

620+
# flagtree mthreads
621+
class musa_knobs(base_knobs):
622+
toolchain_path: env_opt_str = env_opt_str("TRITON_MUSA_TOOLCHAIN_PATH")
623+
llc_path: env_opt_str = env_opt_str("TRITON_MUSA_LLC_PATH")
624+
lld_path: env_opt_str = env_opt_str("TRITON_MUSA_LLD_PATH")
625+
llc_asm_path: env_opt_str = env_opt_str("TRITON_MUSA_LLC_ASM_PATH")
626+
llc: env_musa_tool = env_musa_tool("TRITON_MUSA_LLC_PATH", "llc")
627+
lld: env_musa_tool = env_musa_tool("TRITON_MUSA_LLD_PATH", "ld.lld")
628+
llc_asm: env_musa_tool = env_musa_tool("TRITON_MUSA_LLC_ASM_PATH", "llc")
629+
llc_options: env_opt_str = env_opt_str("TRITON_MUSA_LLC_OPTIONS")
630+
enable_llc_opt: env_bool = env_bool("TRITON_MUSA_ENABLE_LLC_OPT")
631+
enable_fp8_burst2: env_bool = env_bool("TRITON_MUSA_ENABLE_FP8_BURST2")
632+
enable_llvm_compat: env_bool = env_bool("TRITON_MUSA_ENABLE_LLVM_COMPAT", True)
633+
dump_llir: env_bool = env_bool("TRITON_MUSA_DUMP_LLIR")
634+
dump_muasm: env_bool = env_bool("TRITON_MUSA_DUMP_MUASM")
635+
dump_toolchain_log: env_bool = env_bool("TRITON_MUSA_DUMP_TOOLCHAIN_LOG")
636+
replace_llir: env_opt_str = env_opt_str("TRITON_MUSA_REPLACE_LLIR")
637+
replace_mubin: env_opt_str = env_opt_str("TRITON_MUSA_REPLACE_MUBIN")
638+
libdevice_path: env_opt_str = env_opt_str("TRITON_MUSA_LIBDEVICE_PATH")
639+
640+
555641
class proton_knobs(base_knobs):
556642
disable: env_bool = env_bool("TRITON_PROTON_DISABLE", False)
557643
cupti_lib_dir: env_str = env_str(
558644
"TRITON_CUPTI_LIB_PATH",
559645
str(pathlib.Path(__file__).parent.absolute() / "backends" / "nvidia" / "lib" / "cupti"))
646+
profile_buffer_size: env_int = env_int("TRITON_PROFILE_BUFFER_SIZE", 64 * 1024 * 1024) # Triton 3.7
560647
enable_nvtx: env_bool = env_bool("TRITON_ENABLE_NVTX", True)
648+
# This knob is effective only on Blackwell+ GPUs.
649+
#
650+
# When enabled, the profiling session must start after CUDA driver
651+
# initialization but before the CUDA context is created.
652+
#
653+
# You can ensure this in one of the following ways:
654+
#
655+
# 1) Use the `proton` CLI tool to launch the Python script, e.g.:
656+
# `TRITON_ENABLE_HW_TRACE=1 proton python my_script.py`
657+
#
658+
# 2) Call `proton.start()` immediately after importing Proton, e.g.:
659+
# ```python
660+
# import triton
661+
# import triton.profiler as proton
662+
# triton.knobs.proton.enable_hw_trace = True
663+
# proton.start(hook="triton")
664+
# ```
665+
enable_hw_trace: env_bool = env_bool("TRITON_ENABLE_HW_TRACE", False) # Triton 3.7
561666

562667

563668
build = build_knobs()
@@ -569,8 +674,9 @@ class proton_knobs(base_knobs):
569674
language = language_knobs()
570675
nvidia = nvidia_knobs()
571676
amd = amd_knobs()
572-
hcu = hcu_knobs()
573-
metax = metax_knobs()
677+
hcu = hcu_knobs() # flagtree hcu
678+
metax = metax_knobs() # flagtree metax
679+
musa = musa_knobs() # flagtree mthreads
574680
proton = proton_knobs()
575681

576682

0 commit comments

Comments
 (0)