-
Notifications
You must be signed in to change notification settings - Fork 51
/
setup.py
109 lines (97 loc) · 3.21 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
import glob
import os
import torch
from setuptools import find_packages, setup
from torch.utils.cpp_extension import include_paths, library_paths
version = "1.1.6"
CUDA = False
CUDA_device_idx = 0 # Optional, ignored if CUDA is False
if CUDA:
torch.cuda.set_device(torch.device("cuda", CUDA_device_idx))
def create_version_py(version, CUDA):
file = open("memtorch/version.py", "w")
if CUDA:
version_string = "__version__ = '{}'".format(version)
else:
version_string = "__version__ = '{}-cpu'".format(version)
file.write(version_string)
file.close()
create_version_py(version, CUDA)
if CUDA:
from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension
ext_modules = [
CUDAExtension(
name="memtorch_cuda_bindings",
sources=glob.glob("memtorch/cu/*.cu")
+ glob.glob("memtorch/cu/*.cpp")
+ ["memtorch/cpp/gen_tiles.cpp"],
library_dirs=["memtorch/submodules"],
include_dirs=[
os.path.join(os.getcwd(), relative_path)
for relative_path in [
"memtorch/cu/",
"memtorch/submodules/eigen/",
]
],
extra_compile_args=["-lineinfo", "-use_fast_math"],
),
CppExtension(
name="memtorch_bindings",
sources=glob.glob("memtorch/cpp/*.cpp"),
include_dirs=[
os.path.join(os.getcwd(), relative_path)
for relative_path in [
"memtorch/cpp/",
"memtorch/submodules/eigen/",
]
],
extra_compile_args=["-O3"],
),
]
name = "memtorch"
else:
from torch.utils.cpp_extension import BuildExtension, CppExtension
ext_modules = [
CppExtension(
name="memtorch_bindings",
sources=glob.glob("memtorch/cpp/*.cpp"),
include_dirs=[
os.path.join(os.getcwd(), relative_path)
for relative_path in [
"memtorch/cpp/",
"memtorch/submodules/eigen/",
]
],
extra_compile_args=["-O3"],
)
]
name = "memtorch-cpu"
if __name__ == "__main__":
setup(
name=name,
version=version,
description="A Simulation Framework for Memristive Deep Learning Systems",
long_description="A Simulation Framework for Memristive Deep Learning Systems which integrates directly with the well-known PyTorch Machine Learning (ML) library",
url="https://github.com/coreylammie/MemTorch",
license="GPL-3.0",
author="Corey Lammie",
author_email="[email protected]",
setup_requires=["ninja"],
ext_modules=ext_modules,
cmdclass={"build_ext": BuildExtension},
packages=find_packages(),
install_requires=[
"numpy",
"pandas",
"scipy",
"sklearn",
"torch>=1.2.0",
"torchvision",
"matplotlib",
"seaborn",
"ipython",
"lmfit",
],
include_package_data=True,
python_requires=">=3.6",
)