forked from bigrl-team/gear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
126 lines (108 loc) · 3.41 KB
/
setup.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import glob
import os
from setuptools import find_packages, setup
from torch.utils import cpp_extension
class EnvVarError(Exception):
...
def find_cuda():
# TODO: find cuda
home = os.getenv("CUDA_HOME")
path = os.getenv("CUDA_PATH")
if home is not None:
return home
elif path is not None:
return path
else:
return "/usr/local/cuda"
def find_nccl():
home = os.getenv("NCCL_HOME")
if home is not None:
return home
else:
raise EnvVarError("Set the 'NCCL_HOME' variable before compilation")
def have_cuda():
return True
import torch
return torch.cuda.is_available()
def create_extension(with_cuda=False):
srcs = []
srcs += glob.glob("src/*.cc")
srcs += glob.glob("src/**/*.cc")
infinity_src_dir = "./third-party/infinity"
infinity_srcs = [
infinity_src_dir + "/core/Context.cpp",
infinity_src_dir + "/memory/Atomic.cpp",
infinity_src_dir + "/memory/Buffer.cpp",
infinity_src_dir + "/memory/Region.cpp",
infinity_src_dir + "/memory/RegionToken.cpp",
infinity_src_dir + "/memory/RegisteredMemory.cpp",
infinity_src_dir + "/queues/QueuePair.cpp",
infinity_src_dir + "/queues/QueuePairFactory.cpp",
infinity_src_dir + "/requests/RequestToken.cpp",
infinity_src_dir + "/utils/Address.cpp",
]
srcs += infinity_srcs
include_dirs = [os.path.abspath("./include/"), os.path.abspath("./third-party/")]
library_dirs = ["/usr/local/lib64"]
libraries = ["ibverbs"]
extra_cxx_flags = [
"-std=c++17",
"-fvisibility=hidden", # pybind requirement
# TODO: enforce strict build
# '-Wall',
# '-Werror',
# '-Wfatal-errors',
]
if with_cuda:
cuda_home = find_cuda()
nccl_home = find_nccl()
include_dirs += [os.path.join(cuda_home, "include")]
library_dirs += [os.path.join(cuda_home, "lib64")]
include_dirs += [os.path.join(nccl_home, "include")]
library_dirs += [os.path.join(nccl_home, "lib")]
srcs += glob.glob("src/cuda/*.cu")
extra_cxx_flags += [
"-DHAVE_CUDA",
# "-DGEAR_VERBOSE_DEBUG_ON",
# "-DINFINITY_DEBUG_ON",
# "-DINFINITY_ASSERT_ON",
"-DPYBIND11_DETAILED_ERROR_MESSAGES",
]
return cpp_extension.CppExtension(
name="libgear",
sources=srcs,
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
with_cuda=with_cuda,
extra_compile_args={
"cxx": extra_cxx_flags,
"nvcc": ["-O3", "--expt-extended-lambda", "-lnuma"],
},
)
package_dir = "./"
setup(
name="gear",
version="0.2.0",
author="Hanjing Wang",
author_email="wanghanjingwhj@sjtu.edu.cn",
url="https://github.com/VegeWong/PipelineDT",
description=("GPU-centric data buffer for reinforcement learning"),
keywords=["PyTorch", "Distributed", "Reinforcement Learning", "Machine Learning"],
license="Apache",
python_requires=">=3.6",
package_dir={
"": package_dir,
},
packages=find_packages(package_dir),
package_data={
"libgear": ["*.pyi"],
},
ext_modules=[
create_extension(with_cuda=True),
],
cmdclass={
# FIXME: parallel build, (pip_install took 1m16s)
"build_ext": cpp_extension.BuildExtension,
},
)