forked from ovg-project/kvcached
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
68 lines (54 loc) · 1.79 KB
/
Copy pathsetup.py
File metadata and controls
68 lines (54 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# SPDX-FileCopyrightText: Copyright contributors to the kvcached project
# SPDX-License-Identifier: Apache-2.0
import os
from pathlib import Path
from typing import List
from setuptools import find_packages, setup
try:
import torch
from torch.utils.cpp_extension import (
BuildExtension,
CUDAExtension,
include_paths,
library_paths,
)
except ImportError:
raise ImportError("Torch not found, please install torch>=2.6.0 first.")
SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
ROOT_PATH = SCRIPT_PATH
CSRC_PATH = os.path.join(ROOT_PATH, "csrc")
def get_csrc_files(path) -> List[str]:
src_dir = Path(path)
# setuptools requires relative paths
cpp_files = [
str(f.relative_to(SCRIPT_PATH)) for f in src_dir.rglob("*.cpp")
]
return cpp_files
def get_extensions():
csrc_files = get_csrc_files(CSRC_PATH)
# Get the C++ ABI flag from PyTorch
cxx_abi = torch._C._GLIBCXX_USE_CXX11_ABI
extra_compile_args = [
"-std=c++17", f"-D_GLIBCXX_USE_CXX11_ABI={int(cxx_abi)}"
]
vmm_ops_module = CUDAExtension(
"kvcached.vmm_ops",
csrc_files,
include_dirs=include_paths() + [os.path.join(CSRC_PATH, "inc")],
library_dirs=library_paths(),
libraries=["torch", "torch_cpu", "torch_python", "cuda"],
extra_compile_args={
"cxx": extra_compile_args,
"nvcc": extra_compile_args
},
)
return [vmm_ops_module], {"build_ext": BuildExtension}
ext_modules, cmdclass = get_extensions()
setup(
packages=find_packages(),
long_description=open("README.md", "r", encoding="utf-8").read(),
long_description_content_type="text/markdown",
ext_modules=ext_modules,
cmdclass=cmdclass,
data_files=[("", ["kvcached_autopatch.pth"])],
)