File size: 1,202 Bytes
12acbba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import os
import glob
import sys
from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension


cxx_flags = ["-O3"]
nvcc_flags = ["-O3", "--use_fast_math", "--extra-device-vectorization"]
# `-arch=native` detects the building machine's GPU at compile time, which is
# convenient interactively but (a) fails when no GPU is visible during the build
# and (b) can conflict with the `-gencode` flags torch appends from
# TORCH_CUDA_ARCH_LIST. So only use `native` when the caller has NOT pinned the
# arch via TORCH_CUDA_ARCH_LIST (e.g. cluster builds set it to "8.0").
if not os.environ.get("TORCH_CUDA_ARCH_LIST"):
    nvcc_flags.append("-arch=native")
if sys.platform == 'win32':
    cxx_flags = ["/O2"]


setup(
    name='inference_extensions_cuda',
    ext_modules=[
        CUDAExtension(
            name='inference_extensions_cuda',
            sources=glob.glob('*.cpp') + glob.glob('*.cu'),
            extra_compile_args={
                "cxx": cxx_flags,
                "nvcc": nvcc_flags,
            },
        ),
    ],
    cmdclass={
        'build_ext': BuildExtension
    }
)