-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
50 lines (42 loc) · 1.88 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
# This setup.py adds HeadLm Backend as Custom Extension into Pytorch
# Reference: https://pytorch.org/tutorials/intermediate/process_group_cpp_extension_tutorial.html#step-3-build-the-custom-extension
import os
import sys
import torch
from setuptools import setup
from torch.utils import cpp_extension
import torch.utils
torch_install_path = os.path.dirname(
os.path.dirname(torch.utils.cmake_prefix_path))
torch_lib_path = os.path.join(torch_install_path, 'lib')
sources = [
"comm_backend/adapter/CorexAdapter.cpp",
"comm_backend/HeadLmProcessGroup.cpp", "comm_backend/CpuBackend.cpp",
"comm_backend/utils/device.cpp"
]
library_dirs = [torch_lib_path]
include_dirs = [
f"{os.path.dirname(os.path.abspath(__file__))}/comm_backend/",
f"{os.path.dirname(os.path.abspath(__file__))}/comm_backend/adapter",
f"{torch_install_path}/include/"
]
if torch.cuda.is_available():
module = cpp_extension.CUDAExtension(name="headlm_comm",
sources=sources,
include_dirs=include_dirs,
extra_compile_args=[
'-DUSE_C10D_GLOO=1',
'-DUSE_C10D_NCCL=1', '-DUSE_GLOG'
])
else:
module = cpp_extension.CppExtension(name="headlm_comm",
sources=sources,
include_dirs=include_dirs,
extra_compile_args=[
'-DUSE_C10D_GLOO=1',
'-DUSE_C10D_NCCL=1', '-DUSE_GLOG'
])
setup(name="Headlm-Communication",
version="0.0.1",
ext_modules=[module],
cmdclass={'build_ext': cpp_extension.BuildExtension})