Create a :class:`setuptools.Extension` for CUDA/C++. Convenience method that creates a :class:`setuptools.Extension` with the bare minimum (but often sufficient) arguments to build a CUDA/C++ extension. This includes the CUDA include path, library path and runtime library.
(name, sources, *args, **kwargs)
| 971 | |
| 972 | |
| 973 | def CUDAExtension(name, sources, *args, **kwargs): |
| 974 | """ |
| 975 | Create a :class:`setuptools.Extension` for CUDA/C++. |
| 976 | |
| 977 | Convenience method that creates a :class:`setuptools.Extension` with the |
| 978 | bare minimum (but often sufficient) arguments to build a CUDA/C++ |
| 979 | extension. This includes the CUDA include path, library path and runtime |
| 980 | library. |
| 981 | |
| 982 | All arguments are forwarded to the :class:`setuptools.Extension` |
| 983 | constructor. |
| 984 | |
| 985 | Example: |
| 986 | >>> # xdoctest: +SKIP |
| 987 | >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CPP_EXT) |
| 988 | >>> from setuptools import setup |
| 989 | >>> from torch.utils.cpp_extension import BuildExtension, CUDAExtension |
| 990 | >>> setup( |
| 991 | ... name='cuda_extension', |
| 992 | ... ext_modules=[ |
| 993 | ... CUDAExtension( |
| 994 | ... name='cuda_extension', |
| 995 | ... sources=['extension.cpp', 'extension_kernel.cu'], |
| 996 | ... extra_compile_args={'cxx': ['-g'], |
| 997 | ... 'nvcc': ['-O2']}) |
| 998 | ... ], |
| 999 | ... cmdclass={ |
| 1000 | ... 'build_ext': BuildExtension |
| 1001 | ... }) |
| 1002 | |
| 1003 | Compute capabilities: |
| 1004 | |
| 1005 | By default the extension will be compiled to run on all archs of the cards visible during the |
| 1006 | building process of the extension, plus PTX. If down the road a new card is installed the |
| 1007 | extension may need to be recompiled. If a visible card has a compute capability (CC) that's |
| 1008 | newer than the newest version for which your nvcc can build fully-compiled binaries, Pytorch |
| 1009 | will make nvcc fall back to building kernels with the newest version of PTX your nvcc does |
| 1010 | support (see below for details on PTX). |
| 1011 | |
| 1012 | You can override the default behavior using `TORCH_CUDA_ARCH_LIST` to explicitly specify which |
| 1013 | CCs you want the extension to support: |
| 1014 | |
| 1015 | ``TORCH_CUDA_ARCH_LIST="6.1 8.6" python build_my_extension.py`` |
| 1016 | ``TORCH_CUDA_ARCH_LIST="5.2 6.0 6.1 7.0 7.5 8.0 8.6+PTX" python build_my_extension.py`` |
| 1017 | |
| 1018 | The +PTX option causes extension kernel binaries to include PTX instructions for the specified |
| 1019 | CC. PTX is an intermediate representation that allows kernels to runtime-compile for any CC >= |
| 1020 | the specified CC (for example, 8.6+PTX generates PTX that can runtime-compile for any GPU with |
| 1021 | CC >= 8.6). This improves your binary's forward compatibility. However, relying on older PTX to |
| 1022 | provide forward compat by runtime-compiling for newer CCs can modestly reduce performance on |
| 1023 | those newer CCs. If you know exact CC(s) of the GPUs you want to target, you're always better |
| 1024 | off specifying them individually. For example, if you want your extension to run on 8.0 and 8.6, |
| 1025 | "8.0+PTX" would work functionally because it includes PTX that can runtime-compile for 8.6, but |
| 1026 | "8.0 8.6" would be better. |
| 1027 | |
| 1028 | Note that while it's possible to include all supported archs, the more archs get included the |
| 1029 | slower the building process will be, as it will build a separate kernel image for each arch. |
| 1030 |
no test coverage detected
searching dependent graphs…