Skip to content

Commit 4329994

Browse files
LessUpCopilot
andcommitted
task/2.2: Consolidate dependency metadata to pyproject.toml
CHANGES: - setup.py: Removed duplicate package metadata (name, version, description). Now delegates all metadata to pyproject.toml while keeping CUDA extension compilation logic. Made CUDA_HOME check optional for non-CUDA installations. - requirements.txt: Changed from listing core dependencies to a guide file pointing users to pip install -e ".[extra]" pattern. - pyproject.toml: Remains single source of truth for: * Package metadata (name, version, description, classifiers, etc.) * Core dependencies (torch, numpy) * Optional dependencies (test, benchmark, dev) VERIFICATION: - All metadata correctly read from pyproject.toml - pip install -e . succeeds without CUDA_HOME - pip install -e ".[test]" correctly installs test dependencies - python -m compileall cuda_llm_ops tests benchmarks succeeds - ruff check passes on all modified files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2a99313 commit 4329994

2 files changed

Lines changed: 56 additions & 87 deletions

File tree

requirements.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# Core dependencies
2-
# For full installation with all optional dependencies, use:
3-
# pip install -e ".[dev]"
4-
# or
5-
# pip install -e ".[test,benchmark,dev]"
1+
# Development and testing dependencies
2+
# All project metadata and dependencies are defined in pyproject.toml
3+
# Use one of the following to install:
4+
# pip install -e . # Install base package only
5+
# pip install -e ".[test]" # Install with test dependencies
6+
# pip install -e ".[dev]" # Install with dev tools (recommended for contributors)
7+
# pip install -e ".[benchmark]" # Install with benchmark tools
8+
# pip install -e ".[test,dev]" # Install with multiple extras
69

7-
torch>=2.0.0
8-
numpy>=1.20.0

setup.py

Lines changed: 48 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,69 @@
11
"""
2-
Setup script for CUDA LLM Kernel Optimization package.
3-
Version is read from pyproject.toml (single source of truth).
2+
Setup script for CUDA extension compilation only.
3+
4+
Package metadata, dependencies, and optional-dependencies are defined exclusively
5+
in pyproject.toml. Setuptools will automatically read them from there.
6+
This script handles only CUDA extension compilation configuration.
47
"""
58

69
import os
710
import platform
8-
import re
9-
from pathlib import Path
10-
from setuptools import setup, find_packages
11+
12+
from setuptools import setup
1113
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
1214

1315

14-
def _read_version() -> str:
15-
"""Read version from pyproject.toml."""
16-
text = Path(__file__).with_name("pyproject.toml").read_text()
17-
# Match version = "X.Y.Z" in [project] section
18-
match = re.search(r'^version\s*=\s*"([^"]+)"', text, re.MULTILINE)
19-
if not match:
20-
raise RuntimeError("Cannot find version in pyproject.toml")
21-
return match.group(1)
16+
def _build_cuda_extensions():
17+
"""Build CUDA extensions with configurable architecture support.
2218
23-
# CUDA architectures to compile for
24-
CUDA_ARCHS = os.environ.get('CUDA_ARCHS', '70;75;80;86;89;90')
19+
Returns empty list if CUDA_HOME is not set (for pip install without CUDA).
20+
Set CUDA_HOME to enable CUDA extension compilation.
21+
"""
22+
if not os.environ.get('CUDA_HOME'):
23+
return []
2524

26-
# Source files
27-
cuda_sources = [
28-
'src/naive_attention.cu',
29-
'src/tiled_attention.cu',
30-
'src/flash_attention.cu',
31-
'src/tensor_core_gemm.cu',
32-
'src/hgemm_kernel.cu',
33-
'cuda_llm_ops/bindings.cpp',
34-
]
25+
cuda_archs = os.environ.get('CUDA_ARCHS', '70;75;80;86;89;90')
3526

36-
# Include directories
37-
include_dirs = [
38-
'include',
39-
]
27+
cuda_sources = [
28+
'src/naive_attention.cu',
29+
'src/tiled_attention.cu',
30+
'src/flash_attention.cu',
31+
'src/tensor_core_gemm.cu',
32+
'src/hgemm_kernel.cu',
33+
'cuda_llm_ops/bindings.cpp',
34+
]
4035

41-
# Compiler flags (platform-aware)
42-
if platform.system() == 'Windows':
43-
extra_compile_args = {
44-
'cxx': ['/O2', '/std:c++17'],
45-
'nvcc': [
46-
'-O3',
47-
'--use_fast_math',
48-
'-std=c++17',
49-
]
50-
}
51-
else:
52-
extra_compile_args = {
53-
'cxx': ['-O3', '-std=c++17'],
54-
'nvcc': [
55-
'-O3',
56-
'--use_fast_math',
57-
'-std=c++17',
58-
'-Xcompiler', '-fPIC',
59-
]
60-
}
36+
include_dirs = ['include']
6137

62-
# Add architecture flags
63-
for arch in CUDA_ARCHS.split(';'):
64-
extra_compile_args['nvcc'].extend([
65-
f'-gencode=arch=compute_{arch},code=sm_{arch}',
66-
])
38+
# Platform-aware compiler flags
39+
if platform.system() == 'Windows':
40+
extra_compile_args = {
41+
'cxx': ['/O2', '/std:c++17'],
42+
'nvcc': ['-O3', '--use_fast_math', '-std=c++17']
43+
}
44+
else:
45+
extra_compile_args = {
46+
'cxx': ['-O3', '-std=c++17'],
47+
'nvcc': ['-O3', '--use_fast_math', '-std=c++17', '-Xcompiler', '-fPIC']
48+
}
6749

68-
setup(
69-
name='cuda_llm_ops',
70-
version=_read_version(),
71-
description='High-performance CUDA kernels for LLM inference',
72-
author='CUDA LLM Kernel Optimization',
73-
packages=['cuda_llm_ops'],
74-
package_dir={'cuda_llm_ops': 'cuda_llm_ops'},
75-
ext_modules=[
50+
# Add compute capability flags
51+
for arch in cuda_archs.split(';'):
52+
extra_compile_args['nvcc'].extend([
53+
f'-gencode=arch=compute_{arch},code=sm_{arch}',
54+
])
55+
56+
return [
7657
CUDAExtension(
7758
name='cuda_llm_ops._cuda_llm_ops',
7859
sources=cuda_sources,
7960
include_dirs=include_dirs,
8061
extra_compile_args=extra_compile_args,
8162
)
82-
],
83-
cmdclass={
84-
'build_ext': BuildExtension
85-
},
86-
install_requires=[
87-
'torch>=2.0.0',
88-
'numpy>=1.20.0',
89-
],
90-
extras_require={
91-
'test': [
92-
'pytest',
93-
'hypothesis',
94-
],
95-
'benchmark': [
96-
'matplotlib',
97-
'pandas',
98-
],
99-
},
100-
python_requires='>=3.8',
63+
]
64+
65+
66+
setup(
67+
ext_modules=_build_cuda_extensions(),
68+
cmdclass={'build_ext': BuildExtension},
10169
)

0 commit comments

Comments
 (0)