mirror of
https://github.com/ROCm/ROCm.git
synced 2026-04-05 03:01:17 -04:00
Reformat Python code with yapf. (#2589)
I've add an option to yapf to do what we want for long lines, see https://github.com/google/yapf/pull/1177. We can now have a real Python formatter, yay! To make this PR, I ran my modified yapf over the repository, then looked over the full diff. Where yapf was mangling the param list of long function decls/calls (mostly kernels), I manually added `#` to put linebreaks where we want. I fixed up other formatting too -- mostly adding or removing a trailing comma from lists. Overall, trailing `#` was sufficient to get formatting similar to our current code. I didn't have to disable yapf anywhere. --------- Co-authored-by: Phil Tillet <phil@openai.com>
This commit is contained in:
@@ -55,6 +55,7 @@ class Package(NamedTuple):
|
||||
lib_flag: str
|
||||
syspath_var_name: str
|
||||
|
||||
|
||||
# pybind11
|
||||
|
||||
|
||||
@@ -63,6 +64,7 @@ def get_pybind11_package_info():
|
||||
url = "https://github.com/pybind/pybind11/archive/refs/tags/v2.11.1.tar.gz"
|
||||
return Package("pybind11", name, url, "PYBIND11_INCLUDE_DIR", "", "PYBIND11_SYSPATH")
|
||||
|
||||
|
||||
# llvm
|
||||
|
||||
|
||||
@@ -121,6 +123,7 @@ def get_thirdparty_packages(triton_cache_path):
|
||||
thirdparty_cmake_args.append(f"-D{p.lib_flag}={package_dir}/lib")
|
||||
return thirdparty_cmake_args
|
||||
|
||||
|
||||
# ---- package data ---
|
||||
|
||||
|
||||
@@ -153,6 +156,7 @@ def download_and_copy(src_path, variable, version, url_func):
|
||||
os.makedirs(os.path.split(dst_path)[0], exist_ok=True)
|
||||
shutil.copy(src_path, dst_path)
|
||||
|
||||
|
||||
# ---- cmake extension ----
|
||||
|
||||
|
||||
@@ -170,18 +174,21 @@ def get_cmake_dir():
|
||||
|
||||
|
||||
class CMakeClean(clean):
|
||||
|
||||
def initialize_options(self):
|
||||
clean.initialize_options(self)
|
||||
self.build_temp = get_cmake_dir()
|
||||
|
||||
|
||||
class CMakeBuildPy(build_py):
|
||||
|
||||
def run(self) -> None:
|
||||
self.run_command('build_ext')
|
||||
return super().run()
|
||||
|
||||
|
||||
class CMakeExtension(Extension):
|
||||
|
||||
def __init__(self, name, path, sourcedir=""):
|
||||
Extension.__init__(self, name, sources=[])
|
||||
self.sourcedir = os.path.abspath(sourcedir)
|
||||
@@ -204,7 +211,8 @@ class CMakeBuild(build_ext):
|
||||
try:
|
||||
out = subprocess.check_output(["cmake", "--version"])
|
||||
except OSError:
|
||||
raise RuntimeError("CMake must be installed to build the following extensions: " + ", ".join(e.name for e in self.extensions))
|
||||
raise RuntimeError("CMake must be installed to build the following extensions: " +
|
||||
", ".join(e.name for e in self.extensions))
|
||||
|
||||
match = re.search(r"version\s*(?P<major>\d+)\.(?P<minor>\d+)([\d.]+)?", out.decode())
|
||||
cmake_major, cmake_minor = int(match.group("major")), int(match.group("minor"))
|
||||
@@ -231,8 +239,10 @@ class CMakeBuild(build_ext):
|
||||
# python directories
|
||||
python_include_dir = sysconfig.get_path("platinclude")
|
||||
cmake_args = [
|
||||
"-G", "Ninja", # Ninja is much faster than make
|
||||
"-DCMAKE_MAKE_PROGRAM=" + ninja_dir, # Pass explicit path to ninja otherwise cmake may cache a temporary path
|
||||
"-G",
|
||||
"Ninja", # Ninja is much faster than make
|
||||
"-DCMAKE_MAKE_PROGRAM=" +
|
||||
ninja_dir, # Pass explicit path to ninja otherwise cmake may cache a temporary path
|
||||
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
|
||||
"-DLLVM_ENABLE_WERROR=ON",
|
||||
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
|
||||
@@ -266,12 +276,14 @@ class CMakeBuild(build_ext):
|
||||
build_args += ['-j' + max_jobs]
|
||||
|
||||
if check_env_flag("TRITON_BUILD_WITH_CLANG_LLD"):
|
||||
cmake_args += ["-DCMAKE_C_COMPILER=clang",
|
||||
"-DCMAKE_CXX_COMPILER=clang++",
|
||||
"-DCMAKE_LINKER=lld",
|
||||
"-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld",
|
||||
"-DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld",
|
||||
"-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld"]
|
||||
cmake_args += [
|
||||
"-DCMAKE_C_COMPILER=clang",
|
||||
"-DCMAKE_CXX_COMPILER=clang++",
|
||||
"-DCMAKE_LINKER=lld",
|
||||
"-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld",
|
||||
"-DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld",
|
||||
"-DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld",
|
||||
]
|
||||
|
||||
# Note that asan doesn't work with binaries that use the GPU, so this is
|
||||
# only useful for tools like triton-opt that don't run code on the GPU.
|
||||
@@ -303,19 +315,22 @@ download_and_copy(
|
||||
src_path="bin/ptxas",
|
||||
variable="TRITON_PTXAS_PATH",
|
||||
version="12.1.105",
|
||||
url_func=lambda arch, version: f"https://conda.anaconda.org/nvidia/label/cuda-12.1.1/linux-{arch}/cuda-nvcc-{version}-0.tar.bz2",
|
||||
url_func=lambda arch, version:
|
||||
f"https://conda.anaconda.org/nvidia/label/cuda-12.1.1/linux-{arch}/cuda-nvcc-{version}-0.tar.bz2",
|
||||
)
|
||||
download_and_copy(
|
||||
src_path="bin/cuobjdump",
|
||||
variable="TRITON_CUOBJDUMP_PATH",
|
||||
version="12.1.111",
|
||||
url_func=lambda arch, version: f"https://conda.anaconda.org/nvidia/label/cuda-12.1.1/linux-{arch}/cuda-cuobjdump-{version}-0.tar.bz2",
|
||||
url_func=lambda arch, version:
|
||||
f"https://conda.anaconda.org/nvidia/label/cuda-12.1.1/linux-{arch}/cuda-cuobjdump-{version}-0.tar.bz2",
|
||||
)
|
||||
download_and_copy(
|
||||
src_path="bin/nvdisasm",
|
||||
variable="TRITON_NVDISASM_PATH",
|
||||
version="12.1.105",
|
||||
url_func=lambda arch, version: f"https://conda.anaconda.org/nvidia/label/cuda-12.1.1/linux-{arch}/cuda-nvdisasm-{version}-0.tar.bz2",
|
||||
url_func=lambda arch, version:
|
||||
f"https://conda.anaconda.org/nvidia/label/cuda-12.1.1/linux-{arch}/cuda-nvdisasm-{version}-0.tar.bz2",
|
||||
)
|
||||
|
||||
setup(
|
||||
@@ -339,9 +354,7 @@ setup(
|
||||
"triton/third_party",
|
||||
"triton/tools",
|
||||
],
|
||||
install_requires=[
|
||||
"filelock"
|
||||
],
|
||||
install_requires=["filelock"],
|
||||
include_package_data=True,
|
||||
ext_modules=[CMakeExtension("triton", "triton/_C/")],
|
||||
cmdclass={"build_ext": CMakeBuild, "build_py": CMakeBuildPy, "clean": CMakeClean},
|
||||
|
||||
Reference in New Issue
Block a user