-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup_AMD.py
130 lines (121 loc) · 4.13 KB
/
setup_AMD.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
127
128
129
################################################################################
# Copyright 2022-2023 Lawrence Livermore National Security, LLC and other
# LEAP project developers. See the LICENSE file for details.
# SPDX-License-Identifier: MIT
#
# LivermorE AI Projector for Computed Tomography (LEAP)
# setup.py for pytorch module
################################################################################
from setuptools import setup, find_packages
from setuptools.command.install import install
from torch.utils.cpp_extension import CUDAExtension
from torch.utils.cpp_extension import CppExtension
from torch.utils.cpp_extension import BuildExtension
import os
import pybind11
import torch
from sys import platform as _platform
## todo
# compiler options (optimization flags, cufft options)
# leapctype : libleap.so
cpp_files=[
'analytic_ray_tracing.cpp',
'cpu_utils.cpp',
'file_io.cpp',
'filtered_backprojection.cpp',
'find_center_cpu.cpp',
'list_of_tomographic_models.cpp',
'parameters.cpp',
'phantom.cpp',
'projectors.cpp',
'projectors_Joseph_cpu.cpp',
'projectors_SF_cpu.cpp',
'projectors_Siddon_cpu.cpp',
'projectors_symmetric_cpu.cpp',
'ramp_filter_cpu.cpp',
'ray_weighting_cpu.cpp',
'rebin.cpp',
'sensitivity_cpu.cpp',
'resample_cpu.cpp',
'sinogram_replacement.cpp',
'tomographic_models_c_interface.cpp',
'tomographic_models.cpp',
]
cuda_files=[
'bilateral_filter.cu',
'guided_filter.cu',
'cuda_utils.cu',
'matching_pursuit.cu',
'noise_filters.cu',
'projectors_attenuated.cu',
'projectors_extendedSF.cu',
'projectors_Joseph.cu',
'projectors_SF.cu',
'projectors_Siddon.cu',
'projectors_symmetric.cu',
'ramp_filter.cu',
'ray_weighting.cu',
'scatter_models.cu',
'sensitivity.cu',
'resample.cu',
'total_variation.cu',
'geometric_calibration.cu',
'analytic_ray_tracing_gpu.cu',
'backprojectors_VD.cu',
]
cuda = torch.cuda.is_available()
if cuda:
source_files = []
for cpp_file in cpp_files:
source_files.append(os.path.join('src', cpp_file))
for cuda_file in cuda_files:
source_files.append(os.path.join('src', cuda_file))
# optionally we could add '-O3'
# or extra_link_args=["-std=c++11"]
rocm = "AMD" in torch.cuda.get_device_name(0)
if rocm: # AMD ROCM GPU
extra_compile_args={'cxx': ['-D__USE_GPU'],
'nvcc': ['-D__USE_GPU', '-O3']}
libraries = []
else: # CUDA GPU
extra_compile_args={'cxx': ['-D__USE_GPU'],
'nvcc': ['-D__USE_GPU', '-O3']}
#extra_compile_args={'cxx': ['-D__USE_GPU', '-lcufft', '-D__INCLUDE_CUFFT'],
# 'nvcc': ['-D__USE_GPU', '-O3', '-lcufft', '-D__INCLUDE_CUFFT']}
#libraries = ['cufft']
libraries = []
ext_mod = CUDAExtension(
name='leapct',
sources=source_files,
extra_compile_args=extra_compile_args,
libraries = libraries,
#extra_link_args=["-lcufft"],
extra_cflags=['-O3'])
else:
source_files = []
for cpp_file in cpp_files:
source_files.append(os.path.join('src', cpp_file))
ext_mod = CppExtension(
name='leapct',
sources=source_files,
extra_cflags=['-O3'],
#extra_link_args=["-lcufft"],
extra_compile_args={'cxx': ['-D__USE_CPU']}
#extra_compile_args=['-g', '-D__USE_CPU'],
)
setup(
name='leapct',
version='1.25',
author='Kyle Champley, Hyojin Kim',
author_email='champley@gmail.com, hkim@llnl.gov',
description='LivermorE AI Projector for Computed Tomography (LEAPCT)',
keywords='Machine Learning, ML, AI, Computed Tomography, CT, Differentiable Project, Forward Project, Back Project',
python_requires='>=3.6',
packages=find_packages("src"),
package_dir={'': 'src'},
install_requires=['numpy', 'torch'],
py_modules=['leaptorch','leapctype', 'leap_filter_sequence', 'leap_preprocessing_algorithms'],
ext_modules=[ext_mod],
cmdclass={'build_ext': BuildExtension},
#package_data={'': [lib_fname]},
)