Commit b43ab2dd authored by Lei Wang's avatar Lei Wang Committed by GitHub
Browse files

[Bugfix] Bugfix of installing with develop mode (#81)

* bump version into v0.1.0

* [Enhancement] Add custom develop command for editable installs and update .gitignore

* [Documentation] Update README to include system dependencies installation instructions

* [Build] Update setup.py to support library file copying for both release and develop modes

* [Build] Refactor library file copying logic in setup.py

* [Documentation] Remove unnecessary install section header in Installation.md
parent d44e291c
...@@ -79,3 +79,6 @@ build_sdist/ ...@@ -79,3 +79,6 @@ build_sdist/
# exclude debug testing folder # exclude debug testing folder
!testing/python/debug !testing/python/debug
# ignore lib with develop mode
tilelang/lib
...@@ -68,6 +68,10 @@ pip install git+https://github.com/tile-ai/tilelang ...@@ -68,6 +68,10 @@ pip install git+https://github.com/tile-ai/tilelang
Or install locally: Or install locally:
```bash ```bash
# install required system dependencies
sudo apt-get update
sudo apt-get install -y python3-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev
pip install . # with -e option if you want to install in editable mode pip install . # with -e option if you want to install in editable mode
``` ```
......
(install)=
# Installation Guide # Installation Guide
## Installing with pip ## Installing with pip
......
...@@ -7,6 +7,7 @@ import shutil ...@@ -7,6 +7,7 @@ import shutil
from setuptools import setup, find_packages, Extension from setuptools import setup, find_packages, Extension
from setuptools.command.build_py import build_py from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist from setuptools.command.sdist import sdist
from setuptools.command.develop import develop
import distutils.dir_util import distutils.dir_util
from typing import List from typing import List
import re import re
...@@ -204,13 +205,14 @@ class TileLangBuilPydCommand(build_py): ...@@ -204,13 +205,14 @@ class TileLangBuilPydCommand(build_py):
self.run_command("build_ext") self.run_command("build_ext")
build_ext_cmd = self.get_finalized_command("build_ext") build_ext_cmd = self.get_finalized_command("build_ext")
build_temp_dir = build_ext_cmd.build_temp build_temp_dir = build_ext_cmd.build_temp
ext_modules = build_ext_cmd.extensions # 列出所有扩展模块 ext_modules = build_ext_cmd.extensions
for ext in ext_modules: for ext in ext_modules:
extdir = build_ext_cmd.get_ext_fullpath(ext.name) # 获取扩展模块的完整路径 extdir = build_ext_cmd.get_ext_fullpath(ext.name)
print(f"Extension {ext.name} output directory: {extdir}") print(f"Extension {ext.name} output directory: {extdir}")
ext_output_dir = os.path.dirname(extdir) ext_output_dir = os.path.dirname(extdir)
print(f"Extension output directory (parent): {ext_output_dir}") print(f"Extension output directory (parent): {ext_output_dir}")
print(f"Build temp directory: {build_temp_dir}")
TILELANG_SRC = [ TILELANG_SRC = [
"src/tl_templates", "src/tl_templates",
...@@ -226,28 +228,41 @@ class TileLangBuilPydCommand(build_py): ...@@ -226,28 +228,41 @@ class TileLangBuilPydCommand(build_py):
if not os.path.exists(target_dir): if not os.path.exists(target_dir):
os.makedirs(target_dir) os.makedirs(target_dir)
shutil.copy2(source_dir, target_dir) shutil.copy2(source_dir, target_dir)
# Copy the built TVM to the package directory
potential_dirs = [
ext_output_dir,
self.build_lib,
build_temp_dir,
os.path.join(ROOT_DIR, "build"),
]
TVM_PREBUILD_ITEMS = [ TVM_PREBUILD_ITEMS = [
f"{ext_output_dir}/libtvm_runtime.so", "libtvm_runtime.so",
f"{ext_output_dir}/libtvm.so", "libtvm.so",
f"{ext_output_dir}/libtilelang.so", "libtilelang.so",
f"{ext_output_dir}/libtilelang_module.so", "libtilelang_module.so",
] ]
for item in TVM_PREBUILD_ITEMS: for item in TVM_PREBUILD_ITEMS:
source_lib_file = os.path.join(ROOT_DIR, item) source_lib_file = None
# only copy the file for dir in potential_dirs:
file_name = os.path.basename(item) candidate = os.path.join(dir, item)
target_dir = os.path.join(self.build_lib, PACKAGE_NAME, file_name) if os.path.exists(candidate):
target_dir = os.path.dirname(target_dir) source_lib_file = candidate
target_dir = os.path.join(target_dir, "lib") break
if not os.path.exists(target_dir):
os.makedirs(target_dir) if source_lib_file:
if os.path.exists(source_lib_file): target_dir_release = os.path.join(self.build_lib, PACKAGE_NAME, "lib")
shutil.copy2(source_lib_file, target_dir) target_dir_develop = os.path.join(PACKAGE_NAME, "lib")
# remove the original file os.makedirs(target_dir_release, exist_ok=True)
os.makedirs(target_dir_develop, exist_ok=True)
shutil.copy2(source_lib_file, target_dir_release)
print(f"Copied {source_lib_file} to {target_dir_release}")
shutil.copy2(source_lib_file, target_dir_develop)
print(f"Copied {source_lib_file} to {target_dir_develop}")
os.remove(source_lib_file) os.remove(source_lib_file)
else: else:
print(f"INFO: {source_lib_file} does not exist.") print(f"WARNING: {item} not found in any expected directories!")
TVM_CONFIG_ITEMS = [ TVM_CONFIG_ITEMS = [
f"{build_temp_dir}/config.cmake", f"{build_temp_dir}/config.cmake",
...@@ -348,6 +363,52 @@ class TileLangSdistCommand(sdist): ...@@ -348,6 +363,52 @@ class TileLangSdistCommand(sdist):
super().make_distribution() super().make_distribution()
# ------------------------------------------------------------------------
# NEW: Add a custom 'develop' command so that `pip install -e .` works.
# ------------------------------------------------------------------------
class TileLangDevelopCommand(develop):
"""
Customized setuptools 'develop' command for an editable install.
Ensures the extension is built and all necessary assets are copied.
"""
def run(self):
# 1. Build the C/C++ extension modules
self.run_command("build_ext")
build_ext_cmd = self.get_finalized_command("build_ext")
ext_modules = build_ext_cmd.extensions
for ext in ext_modules:
extdir = build_ext_cmd.get_ext_fullpath(ext.name)
print(f"Extension {ext.name} output directory: {extdir}")
ext_output_dir = os.path.dirname(extdir)
print(f"Extension output directory (parent): {ext_output_dir}")
# Copy the built TVM to the package directory
TVM_PREBUILD_ITEMS = [
f"{ext_output_dir}/libtvm_runtime.so",
f"{ext_output_dir}/libtvm.so",
f"{ext_output_dir}/libtilelang.so",
f"{ext_output_dir}/libtilelang_module.so",
]
for item in TVM_PREBUILD_ITEMS:
source_lib_file = os.path.join(ROOT_DIR, item)
# only copy the file
file_name = os.path.basename(item)
target_dir = os.path.join(PACKAGE_NAME, file_name)
target_dir = os.path.dirname(target_dir)
target_dir = os.path.join(target_dir, "lib")
if not os.path.exists(target_dir):
os.makedirs(target_dir)
if os.path.exists(source_lib_file):
shutil.copy2(source_lib_file, target_dir)
# remove the original file
os.remove(source_lib_file)
else:
print(f"INFO: {source_lib_file} does not exist.")
class CMakeExtension(Extension): class CMakeExtension(Extension):
""" """
A specialized setuptools Extension class for building a CMake project. A specialized setuptools Extension class for building a CMake project.
...@@ -466,5 +527,6 @@ setup( ...@@ -466,5 +527,6 @@ setup(
"build_py": TileLangBuilPydCommand, "build_py": TileLangBuilPydCommand,
"sdist": TileLangSdistCommand, "sdist": TileLangSdistCommand,
"build_ext": CMakeBuild, "build_ext": CMakeBuild,
"develop": TileLangDevelopCommand,
}, },
) )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment