parameters: (name,
                  cpp_sources,
                  cuda_sources=None,
                  functions=None,
                  extra_cflags=None,
                  extra_cuda_cflags=None,
                  extra_ldflags=None,
                  extra_include_paths=None,
                  build_directory=None,
                  verbose=False,
                  with_cuda=None,
                  is_python_module=True,
                  with_pytorch_error_handling=True,
                  keep_intermediates=True)
return_statement: return _jit_compile(
          name,
          sources,
          extra_cflags,
          extra_cuda_cflags,
          extra_ldflags,
          extra_include_paths,
          build_directory,
          verbose,
          with_cuda,
          is_python_module,
          is_standalone=False,
          keep_intermediates=keep_intermediates)
docstring: r'''
      Loads a PyTorch C++ extension just-in-time (JIT) from string sources.
  
      This function behaves exactly like :func:`load`, but takes its sources as
      strings rather than filenames. These strings are stored to files in the
      build directory, after which the behavior of :func:`load_inline` is
      identical to :func:`load`.
  
      See `the
      tests <https://github.com/pytorch/pytorch/blob/master/test/test_cpp_extensions_jit.py>`_
      for good examples of using this function.
  
      Sources may omit two required parts of a typical non-inline C++ extension:
      the necessary header includes, as well as the (pybind11) binding code. More
      precisely, strings passed to ``cpp_sources`` are first concatenated into a
      single ``.cpp`` file. This file is then prepended with ``#include
      <torch/extension.h>``.
  
      Furthermore, if the ``functions`` argument is supplied, bindings will be
      automatically generated for each function specified. ``functions`` can
      either be a list of function names, or a dictionary mapping from function
      names to docstrings. If a list is given, the name of each function is used
      as its docstring.
  
      The sources in ``cuda_sources`` are concatenated into a separate ``.cu``
      file and  prepended with ``torch/types.h``, ``cuda.h`` and
      ``cuda_runtime.h`` includes. The ``.cpp`` and ``.cu`` files are compiled
      separately, but ultimately linked into a single library. Note that no
      bindings are generated for functions in ``cuda_sources`` per  se. To bind
      to a CUDA kernel, you must create a C++ function that calls it, and either
      declare or define this C++ function in one of the ``cpp_sources`` (and
      include its name in ``functions``).
  
      See :func:`load` for a description of arguments omitted below.
  
      Args:
          cpp_sources: A string, or list of strings, containing C++ source code.
          cuda_sources: A string, or list of strings, containing CUDA source code.
          functions: A list of function names for which to generate function
              bindings. If a dictionary is given, it should map function names to
              docstrings (which are otherwise just the function names).
          with_cuda: Determines whether CUDA headers and libraries are added to
              the build. If set to ``None`` (default), this value is
              automatically determined based on whether ``cuda_sources`` is
              provided. Set it to ``True`` to force CUDA headers
              and libraries to be included.
          with_pytorch_error_handling: Determines whether pytorch error and
              warning macros are handled by pytorch instead of pybind. To do
              this, each function ``foo`` is called via an intermediary ``_safe_foo``
              function. This redirection might cause issues in obscure cases
              of cpp. This flag should be set to ``False`` when this redirect
              causes issues.
  
      Example:
          >>> from torch.utils.cpp_extension import load_inline
          >>> source = \'\'\'
          at::Tensor sin_add(at::Tensor x, at::Tensor y) {
            return x.sin() + y.sin();
          }
          \'\'\'
          >>> module = load_inline(name='inline_extension',
                                   cpp_sources=[source],
                                   functions=['sin_add'])
  
      .. note::
          By default, the Ninja backend uses #CPUS + 2 workers to build the
          extension. This may use up too many resources on some systems. One
          can control the number of workers by setting the `MAX_JOBS` environment
          variable to a non-negative number.
docstring_summary: r'''
      Loads a PyTorch C++ extension just-in-time (JIT) from string sources.
docstring_tokens: r Loads a PyTorch C ++ extension just - in - time ( JIT ) from string sources .
function: def load_inline(name,
                  cpp_sources,
                  cuda_sources=None,
                  functions=None,
                  extra_cflags=None,
                  extra_cuda_cflags=None,
                  extra_ldflags=None,
                  extra_include_paths=None,
                  build_directory=None,
                  verbose=False,
                  with_cuda=None,
                  is_python_module=True,
                  with_pytorch_error_handling=True,
                  keep_intermediates=True):
      r'''
      Loads a PyTorch C++ extension just-in-time (JIT) from string sources.
  
      This function behaves exactly like :func:`load`, but takes its sources as
      strings rather than filenames. These strings are stored to files in the
      build directory, after which the behavior of :func:`load_inline` is
      identical to :func:`load`.
  
      See `the
      tests <https://github.com/pytorch/pytorch/blob/master/test/test_cpp_extensions_jit.py>`_
      for good examples of using this function.
  
      Sources may omit two required parts of a typical non-inline C++ extension:
      the necessary header includes, as well as the (pybind11) binding code. More
      precisely, strings passed to ``cpp_sources`` are first concatenated into a
      single ``.cpp`` file. This file is then prepended with ``#include
      <torch/extension.h>``.
  
      Furthermore, if the ``functions`` argument is supplied, bindings will be
      automatically generated for each function specified. ``functions`` can
      either be a list of function names, or a dictionary mapping from function
      names to docstrings. If a list is given, the name of each function is used
      as its docstring.
  
      The sources in ``cuda_sources`` are concatenated into a separate ``.cu``
      file and  prepended with ``torch/types.h``, ``cuda.h`` and
      ``cuda_runtime.h`` includes. The ``.cpp`` and ``.cu`` files are compiled
      separately, but ultimately linked into a single library. Note that no
      bindings are generated for functions in ``cuda_sources`` per  se. To bind
      to a CUDA kernel, you must create a C++ function that calls it, and either
      declare or define this C++ function in one of the ``cpp_sources`` (and
      include its name in ``functions``).
  
      See :func:`load` for a description of arguments omitted below.
  
      Args:
          cpp_sources: A string, or list of strings, containing C++ source code.
          cuda_sources: A string, or list of strings, containing CUDA source code.
          functions: A list of function names for which to generate function
              bindings. If a dictionary is given, it should map function names to
              docstrings (which are otherwise just the function names).
          with_cuda: Determines whether CUDA headers and libraries are added to
              the build. If set to ``None`` (default), this value is
              automatically determined based on whether ``cuda_sources`` is
              provided. Set it to ``True`` to force CUDA headers
              and libraries to be included.
          with_pytorch_error_handling: Determines whether pytorch error and
              warning macros are handled by pytorch instead of pybind. To do
              this, each function ``foo`` is called via an intermediary ``_safe_foo``
              function. This redirection might cause issues in obscure cases
              of cpp. This flag should be set to ``False`` when this redirect
              causes issues.
  
      Example:
          >>> from torch.utils.cpp_extension import load_inline
          >>> source = \'\'\'
          at::Tensor sin_add(at::Tensor x, at::Tensor y) {
            return x.sin() + y.sin();
          }
          \'\'\'
          >>> module = load_inline(name='inline_extension',
                                   cpp_sources=[source],
                                   functions=['sin_add'])
  
      .. note::
          By default, the Ninja backend uses #CPUS + 2 workers to build the
          extension. This may use up too many resources on some systems. One
          can control the number of workers by setting the `MAX_JOBS` environment
          variable to a non-negative number.
      '''
      build_directory = build_directory or _get_build_directory(name, verbose)
  
      if isinstance(cpp_sources, str):
          cpp_sources = [cpp_sources]
      cuda_sources = cuda_sources or []
      if isinstance(cuda_sources, str):
          cuda_sources = [cuda_sources]
  
      cpp_sources.insert(0, '#include <torch/extension.h>')
  
      # If `functions` is supplied, we create the pybind11 bindings for the user.
      # Here, `functions` is (or becomes, after some processing) a map from
      # function names to function docstrings.
      if functions is not None:
          module_def = []
          module_def.append('PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {')
          if isinstance(functions, str):
              functions = [functions]
          if isinstance(functions, list):
              # Make the function docstring the same as the function name.
              functions = dict((f, f) for f in functions)
          elif not isinstance(functions, dict):
              raise ValueError(f"Expected 'functions' to be a list or dict, but was {type(functions)}")
          for function_name, docstring in functions.items():
              if with_pytorch_error_handling:
                  module_def.append(
                      'm.def("{0}", torch::wrap_pybind_function({0}), "{1}");'
                      .format(function_name, docstring))
              else:
                  module_def.append('m.def("{0}", {0}, "{1}");'.format(function_name, docstring))
          module_def.append('}')
          cpp_sources += module_def
  
      cpp_source_path = os.path.join(build_directory, 'main.cpp')
      with open(cpp_source_path, 'w') as cpp_source_file:
          cpp_source_file.write('\n'.join(cpp_sources))
  
      sources = [cpp_source_path]
  
      if cuda_sources:
          cuda_sources.insert(0, '#include <torch/types.h>')
          cuda_sources.insert(1, '#include <cuda.h>')
          cuda_sources.insert(2, '#include <cuda_runtime.h>')
  
          cuda_source_path = os.path.join(build_directory, 'cuda.cu')
          with open(cuda_source_path, 'w') as cuda_source_file:
              cuda_source_file.write('\n'.join(cuda_sources))
  
          sources.append(cuda_source_path)
  
      return _jit_compile(
          name,
          sources,
          extra_cflags,
          extra_cuda_cflags,
          extra_ldflags,
          extra_include_paths,
          build_directory,
          verbose,
          with_cuda,
          is_python_module,
          is_standalone=False,
          keep_intermediates=keep_intermediates)
function_tokens: def load_inline ( name , cpp_sources , cuda_sources = None , functions = None , extra_cflags = None , extra_cuda_cflags = None , extra_ldflags = None , extra_include_paths = None , build_directory = None , verbose = False , with_cuda = None , is_python_module = True , with_pytorch_error_handling = True , keep_intermediates = True ) : build_directory = build_directory or _get_build_directory ( name , verbose ) if isinstance ( cpp_sources , str ) : cpp_sources = [ cpp_sources ] cuda_sources = cuda_sources or [ ] if isinstance ( cuda_sources , str ) : cuda_sources = [ cuda_sources ] cpp_sources . insert ( 0 , '#include <torch/extension.h>' ) # If `functions` is supplied, we create the pybind11 bindings for the user. # Here, `functions` is (or becomes, after some processing) a map from # function names to function docstrings. if functions is not None : module_def = [ ] module_def . append ( 'PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {' ) if isinstance ( functions , str ) : functions = [ functions ] if isinstance ( functions , list ) : # Make the function docstring the same as the function name. functions = dict ( ( f , f ) for f in functions ) elif not isinstance ( functions , dict ) : raise ValueError ( f"Expected 'functions' to be a list or dict, but was {type(functions)}" ) for function_name , docstring in functions . items ( ) : if with_pytorch_error_handling : module_def . append ( 'm.def("{0}", torch::wrap_pybind_function({0}), "{1}");' . format ( function_name , docstring ) ) else : module_def . append ( 'm.def("{0}", {0}, "{1}");' . format ( function_name , docstring ) ) module_def . append ( '}' ) cpp_sources += module_def cpp_source_path = os . path . join ( build_directory , 'main.cpp' ) with open ( cpp_source_path , 'w' ) as cpp_source_file : cpp_source_file . write ( '\n' . join ( cpp_sources ) ) sources = [ cpp_source_path ] if cuda_sources : cuda_sources . insert ( 0 , '#include <torch/types.h>' ) cuda_sources . insert ( 1 , '#include <cuda.h>' ) cuda_sources . insert ( 2 , '#include <cuda_runtime.h>' ) cuda_source_path = os . path . join ( build_directory , 'cuda.cu' ) with open ( cuda_source_path , 'w' ) as cuda_source_file : cuda_source_file . write ( '\n' . join ( cuda_sources ) ) sources . append ( cuda_source_path ) return _jit_compile ( name , sources , extra_cflags , extra_cuda_cflags , extra_ldflags , extra_include_paths , build_directory , verbose , with_cuda , is_python_module , is_standalone = False , keep_intermediates = keep_intermediates )