pytorch/test/cpp_extensions/setup.py
peter 946f3a9ed7 Refactor and add VS 14.16 and 2019 CI for Windows (#33117)
Summary:
Changes according to https://github.com/pytorch/pytorch/issues/18319.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33117

Differential Revision: D19858239

Pulled By: ezyang

fbshipit-source-id: f068d8505886b92c9388c9c636eab5bd20377ceb
2020-02-13 11:45:41 -08:00

44 lines
1.3 KiB
Python

import sys
import torch.cuda
import os
from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CppExtension, CUDAExtension
from torch.utils.cpp_extension import CUDA_HOME
if sys.platform == 'win32':
vc_version = os.getenv('VCToolsVersion', '')
if vc_version.startswith('14.16.'):
CXX_FLAGS = ['/sdl']
else:
CXX_FLAGS = ['/sdl', '/permissive-']
else:
CXX_FLAGS = ['-g']
USE_NINJA = os.getenv('USE_NINJA') == '1'
ext_modules = [
CppExtension(
'torch_test_cpp_extension.cpp', ['extension.cpp'],
extra_compile_args=CXX_FLAGS),
CppExtension(
'torch_test_cpp_extension.msnpu', ['msnpu_extension.cpp'],
extra_compile_args=CXX_FLAGS),
]
if torch.cuda.is_available() and CUDA_HOME is not None:
extension = CUDAExtension(
'torch_test_cpp_extension.cuda', [
'cuda_extension.cpp',
'cuda_extension_kernel.cu',
'cuda_extension_kernel2.cu',
],
extra_compile_args={'cxx': CXX_FLAGS,
'nvcc': ['-O2']})
ext_modules.append(extension)
setup(
name='torch_test_cpp_extension',
packages=['torch_test_cpp_extension'],
ext_modules=ext_modules,
cmdclass={'build_ext': BuildExtension.with_options(use_ninja=USE_NINJA)})