MCPcopy Create free account
hub / github.com/apache/tvm-ffi / build_inline

Function build_inline

python/tvm_ffi/cpp/extension.py:761–986  ·  view source on GitHub ↗

Compile and build a C++/CUDA module from inline source code. This function compiles the given C++ and/or CUDA source code into a shared library or object file. Both ``cpp_sources`` and ``cuda_sources`` are compiled to an object file. When ``output`` is ``None`` (the default) or has a sh

(  # noqa: PLR0913
    name: str,
    *,
    cpp_sources: Sequence[str] | str | None = None,
    cuda_sources: Sequence[str] | str | None = None,
    functions: Mapping[str, str] | Sequence[str] | str | None = None,
    extra_cflags: Sequence[str] | None = None,
    extra_cuda_cflags: Sequence[str] | None = None,
    extra_ldflags: Sequence[str] | None = None,
    extra_include_paths: Sequence[str] | None = None,
    build_directory: str | None = None,
    embed_cubin: Mapping[str, bytes] | None = None,
    backend: str | None = None,
    output: str | None = None,
)

Source from the content-addressed store, hash-verified

759
760
761def build_inline( # noqa: PLR0913
762 name: str,
763 *,
764 cpp_sources: Sequence[str] | str | None = None,
765 cuda_sources: Sequence[str] | str | None = None,
766 functions: Mapping[str, str] | Sequence[str] | str | None = None,
767 extra_cflags: Sequence[str] | None = None,
768 extra_cuda_cflags: Sequence[str] | None = None,
769 extra_ldflags: Sequence[str] | None = None,
770 extra_include_paths: Sequence[str] | None = None,
771 build_directory: str | None = None,
772 embed_cubin: Mapping[str, bytes] | None = None,
773 backend: str | None = None,
774 output: str | None = None,
775) -> str:
776 """Compile and build a C++/CUDA module from inline source code.
777
778 This function compiles the given C++ and/or CUDA source code into a shared library or object file.
779 Both ``cpp_sources`` and ``cuda_sources`` are compiled to an object file. When ``output`` is
780 ``None`` (the default) or has a shared-library extension (``.so``, ``.dll``), object files are
781 linked into a shared library. When ``output`` has an object-file extension (``.o``, ``.obj``),
782 linking is skipped and the path to the object file is returned directly.
783
784 The ``functions`` parameter is used to specify which functions in the source code should be exported to the tvm ffi
785 module. It can be a mapping, a sequence, or a single string. When a mapping is given, the keys are the names of the
786 exported functions, and the values are docstrings for the functions. When a sequence of string is given, they are
787 the function names needed to be exported, and the docstrings are set to empty strings. A single function name can
788 also be given as a string, indicating that only one function is to be exported.
789
790 Extra compiler and linker flags can be provided via the ``extra_cflags``, ``extra_cuda_cflags``, and ``extra_ldflags``
791 parameters. The default flags are generally sufficient for most use cases, but you may need to provide additional
792 flags for your specific use case.
793
794 The include dir of tvm ffi and dlpack are used by default for the compiler to find the headers. Thus, you can
795 include any header from tvm ffi in your source code. You can also provide additional include paths via the
796 ``extra_include_paths`` parameter and include custom headers in your source code.
797
798 The compiled shared library is cached in a cache directory to avoid recompilation. The `build_directory` parameter
799 is provided to specify the build directory. If not specified, a default tvm ffi cache directory will be used.
800 The default cache directory can be specified via the `TVM_FFI_CACHE_DIR` environment variable. If not specified,
801 the default cache directory is ``~/.cache/tvm-ffi``.
802
803 Parameters
804 ----------
805 name
806 The name of the tvm ffi module.
807 cpp_sources
808 The C++ source code. It can be a list of sources or a single source.
809 cuda_sources
810 The CUDA source code. It can be a list of sources or a single source.
811 functions
812 The functions in cpp_sources or cuda_source that will be exported to the tvm ffi module. When a mapping is
813 given, the keys are the names of the exported functions, and the values are docstrings for the functions
814 (use an empty string to skip documentation for specific functions). When a sequence or a single string is given, they are
815 the functions needed to be exported, and the docstrings are set to empty strings. A single function name can
816 also be given as a string. When cpp_sources is given, the functions must be declared (not necessarily defined)
817 in the cpp_sources. When cpp_sources is not given, the functions must be defined in the cuda_sources. If not
818 specified, no function will be exported.

Callers 1

load_inlineFunction · 0.85

Calls 8

FileLockClass · 0.90
_str_seq2listFunction · 0.85
_decorate_with_tvm_ffiFunction · 0.85
_hash_sourcesFunction · 0.85
_maybe_writeFunction · 0.85
_build_implFunction · 0.85
appendMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected