[project]
name = "tilelang"
description = "A tile level programming language to generate high performance code."
readme = "README.md"
requires-python = ">=3.8"
authors = [{ name = "TileLang Contributors" }, { name = "Tile-AI" }]
maintainers = [{ name = "Lei Wang", email = "leiwang1999@outlook.com" }]
license = "MIT"
keywords = ["BLAS", "CUDA", "HIP", "Code Generation", "TVM"]
classifiers = [
    "Environment :: GPU",
    "Operating System :: POSIX :: Linux",
    "Operating System :: OS Independent",
    "Operating System :: MacOS",
    "Programming Language :: Python :: 3.8",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: 3.11",
    "Programming Language :: Python :: 3.12",
    "Intended Audience :: Developers",
    "Intended Audience :: Science/Research",
    "Scientific/Engineering :: Artificial Intelligence",
]
dynamic = ["version"]
dependencies = [
    "cloudpickle",
    "ml-dtypes",
    "numpy>=1.23.5",
    "psutil",
    "torch",
    "torch>=2.7; platform_system == 'Darwin'",
    "tqdm>=4.62.3",
    "typing-extensions>=4.10.0",
]

[project.optional-dependencies]
# mldtypes should be greater than 0.5.1
# if you want to enable fp4
fp4 = ["ml-dtypes>=0.5.1"]

[build-system]
requires = [
    "cython>=3.0.0",
    "scikit-build-core",
    "setuptools>=63",
]
build-backend = "scikit_build_core.build"

[tool.scikit-build]
wheel.py-api = "cp38"
cmake.version = ">=3.26.1"
build-dir = "build"

# editable.rebuild = true

# Include backend and git info in version
metadata.version.provider = "version_provider"
metadata.version.provider-path = "."
experimental = true

[tool.scikit-build.sdist]
# See MANIFEST.in for details
include = [
    "VERSION",
    "LICENSE",
    "THIRDPARTYNOTICES.txt",
    "version_provider.py",
    "requirements*.txt",
    "tilelang/jit/adapter/cython/cython_wrapper.pyx",
    "CMakeLists.txt",
    "src/**",
    "cmake/**",
    "3rdparty/**",
    "testing/**",
    "examples/**",
]
exclude = [
    ".git",
    ".github",
    "**/.git",
    "**/.github",
    "3rdparty/clang**",
    "3rdparty/llvm**",
    "build",
]

[tool.scikit-build.wheel.packages]
tilelang = "tilelang"
"tilelang/src" = "src"
# NOTE: The mapping below places the contents of '3rdparty' inside 'tilelang/3rdparty' in the wheel.
# This is necessary to find TVM shared libraries at runtime.
"tilelang/3rdparty" = "3rdparty"

[tool.yapf]
based_on_style = "yapf"
column_limit = 100
indent_width = 4

[tool.codespell]
ignore-words = "docs/spelling_wordlist.txt"
skip = [
    "build",
    "3rdparty",
    "dist",
    ".venv"
]

[tool.ruff]
target-version = "py38"
line-length = 100
output-format = "full"

exclude = [
    "3rdparty",
    "examples/deepseek_v32/inference",
]

[tool.ruff.lint.per-file-ignores]
# Do not upgrade type hint in testing and examples.
# See https://github.com/tile-ai/tilelang/issues/1079 for more information.
"testing/**.py" = ["UP", "FA"]
"examples/**.py" = ["UP", "FA"]

[tool.ruff.lint]
select = [
    # pycodestyle
    "E", "W",
    # Pyflakes
    "F",
    # pyupgrade
    "UP", "FA",
    # flake8-bugbear
    "B",
    # flake8-simplify
    "SIM",
    # isort
    # "I",
]
ignore = [
    # Module level import not at top of file
    "E402",
    # star imports
    "F405", "F403",
    # ambiguous name
    "E741",
    # line too long
    "E501",
    # if-else-block instead of ternary
    "SIM108",
    # key in dict.keys()
    "SIM118",
    # open file w.o. ctx manager
    "SIM115",
    # memory leaks
    "B019",
    # zip without explicit strict
    "B905",
    # No such file or directory
    "E902",
]

[tool.pytest.ini_options]
verbosity_assertions = 3
filterwarnings = ["always"]

[tool.cibuildwheel]
archs = ["auto64"]
skip = "*musllinux*"
build-frontend = "build"
environment = { PYTHONDEVMODE = "1", PYTHONUNBUFFERED = "1" }
environment-pass = [
    "CUDA_VERSION",
    "COLUMNS",
    "FORCE_COLOR",
    "CLICOLOR_FORCE",
]
before-build = "env -0 | sort -z | tr '\\0' '\\n'"
windows.before-build = "set"
# Pin to glibc 2.17 for x86 and 2.28 for aarch64 for now
manylinux-x86_64-image = "manylinux2014"
manylinux-aarch64-image = "manylinux_2_28"

[tool.cibuildwheel.linux]
environment = { PYTHONDEVMODE = "1", PYTHONUNBUFFERED = "1", PATH = "/usr/local/cuda/bin:$PATH" }
repair-wheel-command = [
    "auditwheel repair --exclude libcuda.so.1 --exclude '/usr/local/cuda*' -w {dest_dir} {wheel}",
    "pipx run abi3audit --strict --report {wheel}",
]
# Install CUDA runtime and stub driver library
# manylinux_2_28 uses gcc 14, which needs CUDA 12.8
before-all = """
set -eux

case "$(uname -m)" in
    "x86_64")
        yum-config-manager --add-repo https://developer.download.nvidia.cn/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
        ;;
    "aarch64")
        dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel8/sbsa/cuda-rhel8.repo
        ;;
    *)
        exit 1
        ;;
esac

cudaver="$(echo "${CUDA_VERSION:-"12.4"}" | cut -d '.' -f-2)"
v="${cudaver//./-}"
yum install -y "cuda-minimal-build-${v}" "cuda-driver-devel-${v}" "cuda-nvrtc-devel-${v}"
"""
