2021-07-27 12:38:38 -07:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import sysconfig
|
|
|
|
import platform
|
|
|
|
import subprocess
|
|
|
|
import distutils
|
|
|
|
import glob
|
|
|
|
from distutils.version import LooseVersion
|
|
|
|
from setuptools import setup, Extension, find_packages
|
2020-08-11 20:10:39 -04:00
|
|
|
from torch.utils.cpp_extension import include_paths, library_paths
|
2021-07-27 12:38:38 -07:00
|
|
|
from setuptools.command.build_ext import build_ext
|
|
|
|
from setuptools.command.test import test as TestCommand
|
|
|
|
import distutils.spawn
|
2020-08-11 20:10:39 -04:00
|
|
|
import torch
|
2021-07-27 12:38:38 -07:00
|
|
|
|
|
|
|
def find_llvm():
|
2021-02-21 15:19:39 -08:00
|
|
|
versions = ["-10", "-10.0", ""]
|
|
|
|
supported = ["llvm-config{v}".format(v=v) for v in versions]
|
2021-07-27 12:38:38 -07:00
|
|
|
paths = [distutils.spawn.find_executable(cfg) for cfg in supported]
|
|
|
|
paths = [p for p in paths if p is not None]
|
|
|
|
if paths:
|
2021-02-08 12:16:41 -08:00
|
|
|
return paths[0]
|
2021-02-21 15:19:39 -08:00
|
|
|
config = distutils.spawn.find_executable("llvm-config")
|
|
|
|
instructions = "Please install llvm-10-dev"
|
2021-07-27 12:38:38 -07:00
|
|
|
if config is None:
|
2021-02-21 15:19:39 -08:00
|
|
|
raise RuntimeError("Could not find llvm-config. " + instructions)
|
|
|
|
version = os.popen("{config} --version".format(config=config)).read()
|
|
|
|
raise RuntimeError("Version {v} not supported. ".format(v=version) + instructions)
|
2021-07-27 12:38:38 -07:00
|
|
|
|
|
|
|
class CMakeExtension(Extension):
|
2021-02-21 15:19:39 -08:00
|
|
|
def __init__(self, name, path, sourcedir=""):
|
2021-07-27 12:38:38 -07:00
|
|
|
Extension.__init__(self, name, sources=[])
|
|
|
|
self.sourcedir = os.path.abspath(sourcedir)
|
|
|
|
self.path = path
|
|
|
|
|
|
|
|
class CMakeBuild(build_ext):
|
|
|
|
def run(self):
|
|
|
|
try:
|
2021-02-21 15:19:39 -08:00
|
|
|
out = subprocess.check_output(["cmake", "--version"])
|
2021-07-27 12:38:38 -07:00
|
|
|
except OSError:
|
|
|
|
raise RuntimeError("CMake must be installed to build the following extensions: " +
|
|
|
|
", ".join(e.name for e in self.extensions))
|
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
2021-02-21 15:19:39 -08:00
|
|
|
cmake_version = LooseVersion(re.search(r"version\s*([\d.]+)", out.decode()).group(1))
|
|
|
|
if cmake_version < "3.1.0":
|
2021-07-27 12:38:38 -07:00
|
|
|
raise RuntimeError("CMake >= 3.1.0 is required on Windows")
|
|
|
|
|
|
|
|
for ext in self.extensions:
|
|
|
|
self.build_extension(ext)
|
|
|
|
|
|
|
|
def build_extension(self, ext):
|
2021-02-21 15:19:39 -08:00
|
|
|
# self.debug = True
|
|
|
|
self.debug = False
|
2021-07-27 12:38:38 -07:00
|
|
|
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.path)))
|
|
|
|
# python directories
|
|
|
|
python_include_dirs = distutils.sysconfig.get_python_inc()
|
2021-02-21 15:19:39 -08:00
|
|
|
python_lib_dirs = distutils.sysconfig.get_config_var("LIBDIR")
|
2020-08-11 20:10:39 -04:00
|
|
|
torch_include_dirs = include_paths(True)
|
|
|
|
torch_library_dirs = library_paths(True)
|
2020-11-05 12:37:00 -05:00
|
|
|
cxx11abi = str(int(torch._C._GLIBCXX_USE_CXX11_ABI))
|
2021-02-08 12:16:41 -08:00
|
|
|
cmake_args = [
|
2021-02-21 15:19:39 -08:00
|
|
|
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
|
|
|
|
"-DBUILD_TUTORIALS=OFF",
|
|
|
|
"-DBUILD_PYTHON_MODULE=ON",
|
2021-02-08 12:16:41 -08:00
|
|
|
#'-DPYTHON_EXECUTABLE=' + sys.executable,
|
|
|
|
#'-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON,
|
2021-02-21 15:19:39 -08:00
|
|
|
"-DPYTHON_INCLUDE_DIRS=" + ";".join([python_include_dirs] + include_paths(True)),
|
|
|
|
"-DPYTHON_LINK_DIRS=" + ";".join(library_paths(True)),
|
|
|
|
"-DTORCH_CXX11_ABI=" + cxx11abi,
|
|
|
|
"-DTORCH_LIBRARIES=c10;c10_cuda;torch;torch_cuda;torch_cpu;torch_python;triton",
|
|
|
|
"-DLLVM_CONFIG=" + find_llvm(),
|
2021-02-08 12:16:41 -08:00
|
|
|
]
|
2020-02-24 17:46:20 -05:00
|
|
|
# configuration
|
2021-02-21 15:19:39 -08:00
|
|
|
cfg = "Debug" if self.debug else "Release"
|
|
|
|
build_args = ["--config", cfg]
|
2021-07-27 12:38:38 -07:00
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
2021-02-21 15:19:39 -08:00
|
|
|
cmake_args += ["-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)]
|
2021-07-27 12:38:38 -07:00
|
|
|
if sys.maxsize > 2**32:
|
2021-02-21 15:19:39 -08:00
|
|
|
cmake_args += ["-A", "x64"]
|
|
|
|
build_args += ["--", "/m"]
|
2021-07-27 12:38:38 -07:00
|
|
|
else:
|
2021-02-21 15:19:39 -08:00
|
|
|
cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg]
|
|
|
|
build_args += ["--", "-j4"]
|
2021-07-27 12:38:38 -07:00
|
|
|
|
|
|
|
env = os.environ.copy()
|
|
|
|
if not os.path.exists(self.build_temp):
|
|
|
|
os.makedirs(self.build_temp)
|
2021-02-21 15:19:39 -08:00
|
|
|
sourcedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "src"))
|
|
|
|
subprocess.check_call(["cmake", sourcedir] + cmake_args, cwd=self.build_temp, env=env)
|
|
|
|
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=self.build_temp)
|
2020-03-13 18:03:25 +00:00
|
|
|
|
2021-07-27 12:38:38 -07:00
|
|
|
setup(
|
2021-02-21 15:19:39 -08:00
|
|
|
name="triton",
|
|
|
|
version="1.0.0",
|
|
|
|
author="Philippe Tillet",
|
|
|
|
author_email="phil@openai.com",
|
|
|
|
description="A language and compiler for custom Deep Learning operations",
|
|
|
|
long_description="",
|
|
|
|
packages=["triton", "triton/_C", "triton/ops", "triton/ops/blocksparse"],
|
|
|
|
install_requires=["numpy", "torch"],
|
|
|
|
package_data={"triton/ops": ["*.c"], "triton/ops/blocksparse": ["*.c"]},
|
2021-01-29 17:27:16 -05:00
|
|
|
include_package_data=True,
|
2021-02-21 15:19:39 -08:00
|
|
|
ext_modules=[CMakeExtension("triton", "triton/_C/")],
|
|
|
|
cmdclass={"build_ext": CMakeBuild},
|
2021-07-27 12:38:38 -07:00
|
|
|
zip_safe=False,
|
2020-05-04 08:58:58 -04:00
|
|
|
# for PyPI
|
2021-02-21 15:19:39 -08:00
|
|
|
keywords=["Compiler", "Deep Learning"],
|
|
|
|
url="https://github.com/ptillet/triton/",
|
|
|
|
download_url="https://github.com/ptillet/triton/archive/v0.1.tar.gz",
|
2020-05-04 08:58:58 -04:00
|
|
|
classifiers=[
|
2021-02-21 15:19:39 -08:00
|
|
|
"Development Status :: 3 - Alpha", # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
|
|
|
|
"Intended Audience :: Developers", # Define that your audience are developers
|
|
|
|
"Topic :: Software Development :: Build Tools",
|
|
|
|
"License :: OSI Approved :: MIT License", # Again, pick a license
|
|
|
|
"Programming Language :: Python :: 3.6",
|
2021-02-08 12:16:41 -08:00
|
|
|
],
|
2021-07-27 12:38:38 -07:00
|
|
|
)
|