-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
104 lines (85 loc) · 3.07 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
# -*- coding:utf-8 -*-
import os
import glob
import setuptools
from setuptools import setup
import numpy
import torch
from torch.utils import cpp_extension
from torch.utils.cpp_extension import CUDAExtension, CppExtension, CUDA_HOME
def print_compile_env():
import subprocess
print('torch :', torch.__version__)
print('torch.cuda :', torch.version.cuda)
print("CUDA_HOME :", CUDA_HOME)
try:
with open(os.devnull, 'w') as devnull:
gcc = subprocess.check_output(['gcc', '--version'],
stderr=devnull).decode().rstrip('\r\n').split('\n')[0]
print('gcc :', gcc)
except Exception as e:
pass
def get_extensions():
this_dir = os.path.dirname(os.path.abspath(__file__))
extensions_dir = os.path.join(this_dir, 'medvision', 'csrc')
main_file = glob.glob(os.path.join(extensions_dir, '*.cpp'))
source_cpu = glob.glob(os.path.join(extensions_dir, 'cpu', '*.cpp'))
source_cuda = glob.glob(os.path.join(extensions_dir, 'cuda', '*.cu'))
source_cuda += glob.glob(os.path.join(extensions_dir, 'cuda_aug', '*.cu'))
sources = main_file + source_cpu
extension = CppExtension
define_macros = []
extra_compile_args = {}
if torch.cuda.is_available() and CUDA_HOME is not None:
extension = CUDAExtension
sources += source_cuda
define_macros += [('WITH_CUDA', None)]
nvcc_flags = os.getenv('NVCC_FLAGS', '')
if nvcc_flags == '':
nvcc_flags = []
else:
nvcc_flags = nvcc_flags.split(' ')
extra_compile_args = {
'cxx': ['-O0'],
'nvcc': nvcc_flags,
}
sources = [os.path.join(extensions_dir, s) for s in sources]
include_dirs = [extensions_dir, numpy.get_include()]
ext_modules = [
extension(
'medvision._C',
sources,
include_dirs=include_dirs,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
libraries=[
'curand', # the CUDA random number generation library
]
)
]
return ext_modules
if __name__ == "__main__":
print_compile_env()
with open("README.md", "r", encoding='utf-8') as fh:
long_description = fh.read()
setup(
name='medvision',
version='0.0.4',
author="timothy, qiaoyf",
author_email="[email protected], [email protected]",
description='Medical Image Vision',
keywords='Medical Image, Vision',
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/TimothyZero/MedVision',
license='Apache License 2.0',
packages=setuptools.find_packages('.'),
ext_modules=get_extensions(),
cmdclass={'build_ext': cpp_extension.BuildExtension},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
zip_safe=True,
)