2018-11-06 00:44:45 +00:00
|
|
|
import sys
|
2018-02-13 23:02:50 +00:00
|
|
|
import torch.cuda
|
2021-08-12 18:39:31 +00:00
|
|
|
import os
|
2018-02-13 23:02:50 +00:00
|
|
|
from setuptools import setup
|
2018-11-28 01:33:54 +00:00
|
|
|
from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension
|
2020-02-21 20:07:51 +00:00
|
|
|
from torch.utils.cpp_extension import CUDA_HOME, ROCM_HOME
|
2018-01-23 00:49:11 +00:00
|
|
|
|
2021-08-12 18:39:31 +00:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
|
vc_version = os.getenv('VCToolsVersion', '')
|
|
|
|
|
if vc_version.startswith('14.16.'):
|
|
|
|
|
CXX_FLAGS = ['/sdl']
|
2020-02-14 21:40:15 +00:00
|
|
|
else:
|
2021-08-12 18:39:31 +00:00
|
|
|
CXX_FLAGS = ['/sdl', '/permissive-']
|
2020-02-14 21:40:15 +00:00
|
|
|
else:
|
2021-08-12 18:39:31 +00:00
|
|
|
CXX_FLAGS = ['-g']
|
2020-02-14 21:40:15 +00:00
|
|
|
|
2021-08-12 18:39:31 +00:00
|
|
|
USE_NINJA = os.getenv('USE_NINJA') == '1'
|
2018-11-06 00:44:45 +00:00
|
|
|
|
2018-01-23 00:49:11 +00:00
|
|
|
ext_modules = [
|
2018-02-13 23:02:50 +00:00
|
|
|
CppExtension(
|
2021-08-12 18:39:31 +00:00
|
|
|
'torch_test_cpp_extension.cpp', ['extension.cpp'],
|
|
|
|
|
extra_compile_args=CXX_FLAGS),
|
2019-02-01 18:55:00 +00:00
|
|
|
CppExtension(
|
2021-08-20 18:11:47 +00:00
|
|
|
'torch_test_cpp_extension.ort', ['ort_extension.cpp'],
|
2021-08-12 18:39:31 +00:00
|
|
|
extra_compile_args=CXX_FLAGS),
|
2020-03-22 17:54:06 +00:00
|
|
|
CppExtension(
|
2021-08-12 18:39:31 +00:00
|
|
|
'torch_test_cpp_extension.rng', ['rng_extension.cpp'],
|
|
|
|
|
extra_compile_args=CXX_FLAGS),
|
2018-01-23 00:49:11 +00:00
|
|
|
]
|
|
|
|
|
|
2020-12-03 02:00:15 +00:00
|
|
|
if torch.cuda.is_available() and (CUDA_HOME is not None or ROCM_HOME is not None):
|
2018-02-13 23:02:50 +00:00
|
|
|
extension = CUDAExtension(
|
2021-08-12 18:39:31 +00:00
|
|
|
'torch_test_cpp_extension.cuda', [
|
|
|
|
|
'cuda_extension.cpp',
|
|
|
|
|
'cuda_extension_kernel.cu',
|
|
|
|
|
'cuda_extension_kernel2.cu',
|
2018-02-23 15:15:30 +00:00
|
|
|
],
|
2021-08-12 18:39:31 +00:00
|
|
|
extra_compile_args={'cxx': CXX_FLAGS,
|
|
|
|
|
'nvcc': ['-O2']})
|
2018-02-13 23:02:50 +00:00
|
|
|
ext_modules.append(extension)
|
|
|
|
|
|
2021-04-08 06:41:44 +00:00
|
|
|
if torch.cuda.is_available() and (CUDA_HOME is not None or ROCM_HOME is not None):
|
|
|
|
|
extension = CUDAExtension(
|
2021-08-12 18:39:31 +00:00
|
|
|
'torch_test_cpp_extension.torch_library', [
|
|
|
|
|
'torch_library.cu'
|
|
|
|
|
],
|
|
|
|
|
extra_compile_args={'cxx': CXX_FLAGS,
|
|
|
|
|
'nvcc': ['-O2']})
|
2021-04-08 06:41:44 +00:00
|
|
|
ext_modules.append(extension)
|
2020-11-16 21:01:14 +00:00
|
|
|
|
2018-01-23 00:49:11 +00:00
|
|
|
setup(
|
2021-08-12 18:39:31 +00:00
|
|
|
name='torch_test_cpp_extension',
|
|
|
|
|
packages=['torch_test_cpp_extension'],
|
2018-01-23 00:49:11 +00:00
|
|
|
ext_modules=ext_modules,
|
2021-08-12 18:39:31 +00:00
|
|
|
include_dirs='self_compiler_include_dirs_test',
|
|
|
|
|
cmdclass={'build_ext': BuildExtension.with_options(use_ninja=USE_NINJA)})
|