Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion python/triton/runtime/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import functools
import hashlib
import importlib.util
import locale
import logging
import os
import shutil
import subprocess
import sys
import sysconfig
import tempfile
import re
Expand All @@ -16,6 +18,9 @@
from .cache import get_cache_manager
from .. import knobs

_IS_WINDOWS = sys.platform == "win32"
SUBPROCESS_DECODE_ARGS = (locale.getpreferredencoding(), ) if _IS_WINDOWS else ()


def is_xpu():
import torch
Expand Down Expand Up @@ -106,7 +111,11 @@ def _build(name: str, src: str, srcdir: str, library_dirs: list[str], include_di
if os.getenv("VERBOSE"):
print(" ".join(cc_cmd))

subprocess.check_call(cc_cmd, stdout=subprocess.DEVNULL)
try:
subprocess.run(cc_cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
output = e.stdout.decode(*SUBPROCESS_DECODE_ARGS)
raise RuntimeError(output)
Comment on lines +114 to +118
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @xuhancn. Thanks for your contribution!

Let's try simplifying the code. Does this work for you?

Suggested change
try:
subprocess.run(cc_cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
output = e.stdout.decode(*SUBPROCESS_DECODE_ARGS)
raise RuntimeError(output)
subprocess.check_output(cc_cmd, stderr=subprocess.STDOUT, encoding=locale.getpreferredencoding())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @anmyachev I think my code is better, we'd better keep try-except block. It is working well in PyTorch for a long time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have one more criterion: how much the code deviates from the upstream. I use this as a guide when trying to modify your code. The smaller it is, the easier it is to support for us and potentially upstream it.

Several things from docs: https://docs.python.org/3.10/library/subprocess.html#subprocess.check_output

The main reason why you use try-except is to decode the output (at least I see it like this). However, if immediately pass encoding to the call command, then this is not necessary.

return so


Expand Down
Loading