forked from rusty1s/pytorch_sparse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rusty1s#180 from kkleidal/build-cpu-and-gpu-versions
Build both cpu and gpu binaries
- Loading branch information
Showing
10 changed files
with
70 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,69 @@ | ||
import os | ||
import os.path as osp | ||
import sys | ||
import glob | ||
import os.path as osp | ||
from itertools import product | ||
from setuptools import setup, find_packages | ||
|
||
import torch | ||
from torch.__config__ import parallel_info | ||
from torch.utils.cpp_extension import BuildExtension | ||
from torch.utils.cpp_extension import CppExtension, CUDAExtension, CUDA_HOME | ||
|
||
WITH_CUDA = torch.cuda.is_available() and CUDA_HOME is not None | ||
suffices = ['cpu', 'cuda'] if WITH_CUDA else ['cpu'] | ||
if os.getenv('FORCE_CUDA', '0') == '1': | ||
WITH_CUDA = True | ||
if os.getenv('FORCE_CPU', '0') == '1': | ||
WITH_CUDA = False | ||
suffices = ['cuda', 'cpu'] | ||
if os.getenv('FORCE_ONLY_CUDA', '0') == '1': | ||
suffices = ['cuda'] | ||
if os.getenv('FORCE_ONLY_CPU', '0') == '1': | ||
suffices = ['cpu'] | ||
|
||
BUILD_DOCS = os.getenv('BUILD_DOCS', '0') == '1' | ||
|
||
|
||
def get_extensions(): | ||
Extension = CppExtension | ||
define_macros = [] | ||
extra_compile_args = {'cxx': ['-O2']} | ||
extra_link_args = ['-s'] | ||
|
||
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', '-O2'] | ||
extra_compile_args['nvcc'] = nvcc_flags | ||
extensions = [] | ||
|
||
extensions_dir = osp.join(osp.dirname(osp.abspath(__file__)), 'csrc') | ||
main_files = glob.glob(osp.join(extensions_dir, '*.cpp')) | ||
extensions = [] | ||
for main in main_files: | ||
name = main.split(os.sep)[-1][:-4] | ||
|
||
for main, suffix in product(main_files, suffices): | ||
define_macros = [] | ||
extra_compile_args = {'cxx': ['-O2']} | ||
extra_link_args = ['-s'] | ||
|
||
info = parallel_info() | ||
if '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 suffix == 'cuda': | ||
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 | ||
|
||
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): | ||
if suffix == 'cuda' and osp.exists(path): | ||
sources += [path] | ||
|
||
Extension = CppExtension if suffix == 'cpu' else CUDAExtension | ||
extension = Extension( | ||
'torch_scatter._' + name, | ||
f'torch_scatter._{name}_{suffix}', | ||
sources, | ||
include_dirs=[extensions_dir], | ||
define_macros=define_macros, | ||
|
@@ -65,7 +81,7 @@ def get_extensions(): | |
|
||
setup( | ||
name='torch_scatter', | ||
version='2.0.5', | ||
version='2.0.6', | ||
author='Matthias Fey', | ||
author_email='[email protected]', | ||
url='https://github.com/rusty1s/pytorch_scatter', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters