setup.py 2.85 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
import glob
rusty1s's avatar
rusty1s committed
2
import os
rusty1s's avatar
rusty1s committed
3
import os.path as osp
rusty1s's avatar
rusty1s committed
4
import sys
rusty1s's avatar
rusty1s committed
5
6

import torch
rusty1s's avatar
rusty1s committed
7
from setuptools import find_packages, setup
rusty1s's avatar
rusty1s committed
8
from torch.__config__ import parallel_info
rusty1s's avatar
rusty1s committed
9
10
from torch.utils.cpp_extension import (CUDA_HOME, BuildExtension, CppExtension,
                                       CUDAExtension)
rusty1s's avatar
rusty1s committed
11
12

WITH_CUDA = torch.cuda.is_available() and CUDA_HOME is not None
rusty1s's avatar
rusty1s committed
13
14
15
16
if os.getenv('FORCE_CUDA', '0') == '1':
    WITH_CUDA = True
if os.getenv('FORCE_ONLY_CPU', '0') == '1':
    WITH_CUDA = False
rusty1s's avatar
rusty1s committed
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


def get_extensions():
    Extension = CppExtension
    define_macros = []
    libraries = []
    extra_compile_args = {'cxx': []}
    extra_link_args = []

    info = parallel_info()
    if 'parallel backend: OpenMP' in info and 'OpenMP not found' not in info:
        extra_compile_args['cxx'] += ['-DAT_PARALLEL_OPENMP']
        if sys.platform == 'win32':
            extra_compile_args['cxx'] += ['/openmp']
        else:
            extra_compile_args['cxx'] += ['-fopenmp']
    else:
        print('Compiling without OpenMP...')

    if WITH_CUDA:
        Extension = CUDAExtension
        define_macros += [('WITH_CUDA', None)]
        nvcc_flags = os.getenv('NVCC_FLAGS', '')
        nvcc_flags = [] if nvcc_flags == '' else nvcc_flags.split(' ')
        nvcc_flags += ['-arch=sm_35', '--expt-relaxed-constexpr']
        extra_compile_args['nvcc'] = nvcc_flags

rusty1s's avatar
rusty1s committed
44
    extensions_dir = osp.join('csrc')
rusty1s's avatar
rusty1s committed
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
    main_files = glob.glob(osp.join(extensions_dir, '*.cpp'))
    extensions = []
    for main in main_files:
        name = main.split(os.sep)[-1][:-4]

        sources = [main]

        path = osp.join(extensions_dir, 'cpu', f'{name}_cpu.cpp')
        if osp.exists(path):
            sources += [path]

        path = osp.join(extensions_dir, 'cuda', f'{name}_cuda.cu')
        if WITH_CUDA and osp.exists(path):
            sources += [path]

        extension = Extension(
            'torch_geometric_autoscale._' + name,
            sources,
            include_dirs=[extensions_dir],
            define_macros=define_macros,
            extra_compile_args=extra_compile_args,
            extra_link_args=extra_link_args,
            libraries=libraries,
        )
        extensions += [extension]

    return extensions


rusty1s's avatar
rusty1s committed
74
install_requires = ['ogb', 'hydra-core']
rusty1s's avatar
rusty1s committed
75
76
77
78
79
80
setup_requires = ['pytest-runner']
tests_require = ['pytest', 'pytest-cov']

setup(
    name='torch_geometric_autoscale',
    version='0.0.0',
rusty1s's avatar
rusty1s committed
81
82
83
    author='Matthias Fey',
    author_email='matthias.fey@tu-dortmund.de',
    description='PyGAS: Auto-Scaling GNNs in PyTorch Geometric',
rusty1s's avatar
rusty1s committed
84
85
86
87
    python_requires='>=3.6',
    install_requires=install_requires,
    setup_requires=setup_requires,
    tests_require=tests_require,
rusty1s's avatar
rusty1s committed
88
    extras_require={'test': tests_require},
rusty1s's avatar
rusty1s committed
89
90
91
92
93
94
95
    ext_modules=get_extensions(),
    cmdclass={
        'build_ext':
        BuildExtension.with_options(no_python_abi_suffix=True, use_ninja=False)
    },
    packages=find_packages(),
)