Files
DeepGEMM/setup.py

86 lines
2.6 KiB
Python
Raw Normal View History

2025-02-25 22:52:41 +08:00
import os
import setuptools
import shutil
import subprocess
2025-02-26 17:48:57 +00:00
from setuptools.command.build_py import build_py
2025-02-25 22:52:41 +08:00
from setuptools.command.develop import develop
current_dir = os.path.dirname(os.path.realpath(__file__))
2025-02-27 10:50:20 +08:00
jit_include_dirs = ('deep_gemm/include/deep_gemm', )
2025-02-26 17:48:57 +00:00
third_party_include_dirs = (
2025-02-27 10:50:20 +08:00
'third-party/cutlass/include/cute',
'third-party/cutlass/include/cutlass',
2025-02-26 17:48:57 +00:00
)
2025-02-25 22:52:41 +08:00
class PostDevelopCommand(develop):
def run(self):
develop.run(self)
self.make_jit_include_symlinks()
@staticmethod
def make_jit_include_symlinks():
# Make symbolic links of third-party include directories
for d in third_party_include_dirs:
2025-02-27 10:50:20 +08:00
dirname = d.split('/')[-1]
src_dir = f'{current_dir}/{d}'
dst_dir = f'{current_dir}/deep_gemm/include/{dirname}'
2025-02-25 22:52:41 +08:00
assert os.path.exists(src_dir)
if os.path.exists(dst_dir):
assert os.path.islink(dst_dir)
os.unlink(dst_dir)
os.symlink(src_dir, dst_dir, target_is_directory=True)
2025-02-26 17:48:57 +00:00
class CustomBuildPy(build_py):
2025-02-25 22:52:41 +08:00
def run(self):
2025-02-26 17:48:57 +00:00
# First, prepare the include directories
self.prepare_includes()
2025-02-27 10:50:20 +08:00
2025-02-26 17:48:57 +00:00
# Then run the regular build
build_py.run(self)
2025-02-25 22:52:41 +08:00
2025-02-26 17:48:57 +00:00
def prepare_includes(self):
# Create temporary build directory instead of modifying package directory
2025-02-27 10:50:20 +08:00
build_include_dir = os.path.join(self.build_lib, 'deep_gemm/include')
2025-02-26 17:48:57 +00:00
os.makedirs(build_include_dir, exist_ok=True)
# Copy third-party includes to the build directory
for d in third_party_include_dirs:
2025-02-27 10:50:20 +08:00
dirname = d.split('/')[-1]
2025-02-26 17:48:57 +00:00
src_dir = os.path.join(current_dir, d)
dst_dir = os.path.join(build_include_dir, dirname)
# Remove existing directory if it exists
if os.path.exists(dst_dir):
shutil.rmtree(dst_dir)
# Copy the directory
2025-02-25 22:52:41 +08:00
shutil.copytree(src_dir, dst_dir)
2025-02-27 10:50:20 +08:00
if __name__ == '__main__':
2025-02-25 22:52:41 +08:00
# noinspection PyBroadException
try:
2025-02-27 10:50:20 +08:00
cmd = ['git', 'rev-parse', '--short', 'HEAD']
revision = '+' + subprocess.check_output(cmd).decode('ascii').rstrip()
2025-02-25 22:52:41 +08:00
except:
2025-02-27 10:50:20 +08:00
revision = ''
2025-02-25 22:52:41 +08:00
setuptools.setup(
2025-02-27 10:50:20 +08:00
name='deep_gemm',
version='1.0.0' + revision,
packages=['deep_gemm', 'deep_gemm/jit', 'deep_gemm/jit_kernels'],
2025-02-26 17:48:57 +00:00
package_data={
2025-02-27 10:50:20 +08:00
'deep_gemm': [
'include/deep_gemm/*',
2025-02-27 10:50:20 +08:00
'include/cute/**/*',
'include/cutlass/**/*',
2025-02-26 17:48:57 +00:00
]
},
2025-02-25 22:52:41 +08:00
cmdclass={
2025-02-27 10:50:20 +08:00
'develop': PostDevelopCommand,
'build_py': CustomBuildPy,
2025-02-26 17:48:57 +00:00
},
2025-02-25 22:52:41 +08:00
)