MCPcopy Create free account
hub / github.com/pytorch/pytorch / CppExtension

Function CppExtension

torch/utils/cpp_extension.py:927–970  ·  view source on GitHub ↗

Create a :class:`setuptools.Extension` for C++. Convenience method that creates a :class:`setuptools.Extension` with the bare minimum (but often sufficient) arguments to build a C++ extension. All arguments are forwarded to the :class:`setuptools.Extension` constructor. E

(name, sources, *args, **kwargs)

Source from the content-addressed store, hash-verified

925
926
927def CppExtension(name, sources, *args, **kwargs):
928 """
929 Create a :class:`setuptools.Extension` for C++.
930
931 Convenience method that creates a :class:`setuptools.Extension` with the
932 bare minimum (but often sufficient) arguments to build a C++ extension.
933
934 All arguments are forwarded to the :class:`setuptools.Extension`
935 constructor.
936
937 Example:
938 >>> # xdoctest: +SKIP
939 >>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CPP_EXT)
940 >>> from setuptools import setup
941 >>> from torch.utils.cpp_extension import BuildExtension, CppExtension
942 >>> setup(
943 ... name='extension',
944 ... ext_modules=[
945 ... CppExtension(
946 ... name='extension',
947 ... sources=['extension.cpp'],
948 ... extra_compile_args=['-g']),
949 ... ],
950 ... cmdclass={
951 ... 'build_ext': BuildExtension
952 ... })
953 """
954 include_dirs = kwargs.get('include_dirs', [])
955 include_dirs += include_paths()
956 kwargs['include_dirs'] = include_dirs
957
958 library_dirs = kwargs.get('library_dirs', [])
959 library_dirs += library_paths()
960 kwargs['library_dirs'] = library_dirs
961
962 libraries = kwargs.get('libraries', [])
963 libraries.append('c10')
964 libraries.append('torch')
965 libraries.append('torch_cpu')
966 libraries.append('torch_python')
967 kwargs['libraries'] = libraries
968
969 kwargs['language'] = 'c++'
970 return setuptools.Extension(name, sources, *args, **kwargs)
971
972
973def CUDAExtension(name, sources, *args, **kwargs):

Callers 3

setup.pyFile · 0.90
setup.pyFile · 0.90
setup.pyFile · 0.90

Calls 4

include_pathsFunction · 0.85
library_pathsFunction · 0.85
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…