|
7 | 7 | from torch.utils.cpp_extension import BuildExtension |
8 | 8 | from torch.utils.cpp_extension import CppExtension, CUDAExtension, CUDA_HOME |
9 | 9 |
|
10 | | -WITH_CUDA = torch.cuda.is_available() and CUDA_HOME is not None |
| 10 | +WITH_CUDA = CUDA_HOME is not None |
11 | 11 | if os.getenv('FORCE_CUDA', '0') == '1': |
12 | 12 | WITH_CUDA = True |
13 | 13 | if os.getenv('FORCE_CPU', '0') == '1': |
|
17 | 17 |
|
18 | 18 |
|
19 | 19 | def get_extensions(): |
20 | | - Extension = CppExtension |
21 | | - define_macros = [] |
22 | | - extra_compile_args = {'cxx': []} |
| 20 | + extensions = [] |
| 21 | + for with_cuda, supername in [ |
| 22 | + (False, "cpu"), |
| 23 | + (True, "gpu"), |
| 24 | + ]: |
| 25 | + if with_cuda and not WITH_CUDA: |
| 26 | + continue |
| 27 | + Extension = CppExtension |
| 28 | + define_macros = [] |
| 29 | + extra_compile_args = {'cxx': []} |
23 | 30 |
|
24 | | - if WITH_CUDA: |
25 | | - Extension = CUDAExtension |
26 | | - define_macros += [('WITH_CUDA', None)] |
27 | | - nvcc_flags = os.getenv('NVCC_FLAGS', '') |
28 | | - nvcc_flags = [] if nvcc_flags == '' else nvcc_flags.split(' ') |
29 | | - nvcc_flags += ['-arch=sm_35', '--expt-relaxed-constexpr'] |
30 | | - extra_compile_args['nvcc'] = nvcc_flags |
| 31 | + if with_cuda: |
| 32 | + Extension = CUDAExtension |
| 33 | + define_macros += [('WITH_CUDA', None)] |
| 34 | + nvcc_flags = os.getenv('NVCC_FLAGS', '') |
| 35 | + nvcc_flags = [] if nvcc_flags == '' else nvcc_flags.split(' ') |
| 36 | + nvcc_flags += ['-arch=sm_35', '--expt-relaxed-constexpr'] |
| 37 | + extra_compile_args['nvcc'] = nvcc_flags |
31 | 38 |
|
32 | | - extensions_dir = osp.join(osp.dirname(osp.abspath(__file__)), 'csrc') |
33 | | - main_files = glob.glob(osp.join(extensions_dir, '*.cpp')) |
34 | | - extensions = [] |
35 | | - for main in main_files: |
36 | | - name = main.split(os.sep)[-1][:-4] |
| 39 | + extensions_dir = osp.join(osp.dirname(osp.abspath(__file__)), 'csrc') |
| 40 | + main_files = glob.glob(osp.join(extensions_dir, '*.cpp')) |
| 41 | + for main in main_files: |
| 42 | + name = main.split(os.sep)[-1][:-4] |
37 | 43 |
|
38 | | - sources = [main] |
| 44 | + sources = [main] |
39 | 45 |
|
40 | | - path = osp.join(extensions_dir, 'cpu', f'{name}_cpu.cpp') |
41 | | - if osp.exists(path): |
42 | | - sources += [path] |
| 46 | + path = osp.join(extensions_dir, 'cpu', f'{name}_cpu.cpp') |
| 47 | + if osp.exists(path): |
| 48 | + sources += [path] |
43 | 49 |
|
44 | | - path = osp.join(extensions_dir, 'cuda', f'{name}_cuda.cu') |
45 | | - if WITH_CUDA and osp.exists(path): |
46 | | - sources += [path] |
| 50 | + path = osp.join(extensions_dir, 'cuda', f'{name}_cuda.cu') |
| 51 | + if with_cuda and osp.exists(path): |
| 52 | + sources += [path] |
47 | 53 |
|
48 | | - extension = Extension( |
49 | | - 'torch_scatter._' + name, |
50 | | - sources, |
51 | | - include_dirs=[extensions_dir], |
52 | | - define_macros=define_macros, |
53 | | - extra_compile_args=extra_compile_args, |
54 | | - ) |
55 | | - extensions += [extension] |
| 54 | + extension = Extension( |
| 55 | + 'torch_scatter._%s_%s' % (name, supername), |
| 56 | + sources, |
| 57 | + include_dirs=[extensions_dir], |
| 58 | + define_macros=define_macros, |
| 59 | + extra_compile_args=extra_compile_args, |
| 60 | + ) |
| 61 | + extensions += [extension] |
56 | 62 |
|
57 | 63 | return extensions |
58 | 64 |
|
|
0 commit comments