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

Function load_inline

python/tvm_ffi/cpp/extension.py:989–1146  ·  view source on GitHub ↗

Compile, build and load a C++/CUDA module from inline source code. This function compiles the given C++ and/or CUDA source code into a shared library. Both ``cpp_sources`` and ``cuda_sources`` are compiled to an object file, and then linked together into a shared library. It's possible to o

(  # 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,
    keep_module_alive: bool = True,
    backend: str | None = None,
)

Source from the content-addressed store, hash-verified

987
988
989def load_inline( # noqa: PLR0913
990 name: str,
991 *,
992 cpp_sources: Sequence[str] | str | None = None,
993 cuda_sources: Sequence[str] | str | None = None,
994 functions: Mapping[str, str] | Sequence[str] | str | None = None,
995 extra_cflags: Sequence[str] | None = None,
996 extra_cuda_cflags: Sequence[str] | None = None,
997 extra_ldflags: Sequence[str] | None = None,
998 extra_include_paths: Sequence[str] | None = None,
999 build_directory: str | None = None,
1000 embed_cubin: Mapping[str, bytes] | None = None,
1001 keep_module_alive: bool = True,
1002 backend: str | None = None,
1003) -> Module:
1004 """Compile, build and load a C++/CUDA module from inline source code.
1005
1006 This function compiles the given C++ and/or CUDA source code into a shared library. Both ``cpp_sources`` and
1007 ``cuda_sources`` are compiled to an object file, and then linked together into a shared library. It's possible to only
1008 provide cpp_sources or cuda_sources.
1009
1010 The ``functions`` parameter is used to specify which functions in the source code should be exported to the tvm ffi
1011 module. It can be a mapping, a sequence, or a single string. When a mapping is given, the keys are the names of the
1012 exported functions, and the values are docstrings for the functions. When a sequence of string is given, they are
1013 the function names needed to be exported, and the docstrings are set to empty strings. A single function name can
1014 also be given as a string, indicating that only one function is to be exported.
1015
1016 Extra compiler and linker flags can be provided via the ``extra_cflags``, ``extra_cuda_cflags``, and ``extra_ldflags``
1017 parameters. The default flags are generally sufficient for most use cases, but you may need to provide additional
1018 flags for your specific use case.
1019
1020 The include dir of tvm ffi and dlpack are used by default for the compiler to find the headers. Thus, you can
1021 include any header from tvm ffi in your source code. You can also provide additional include paths via the
1022 ``extra_include_paths`` parameter and include custom headers in your source code.
1023
1024 The compiled shared library is cached in a cache directory to avoid recompilation. The `build_directory` parameter
1025 is provided to specify the build directory. If not specified, a default tvm ffi cache directory will be used.
1026 The default cache directory can be specified via the `TVM_FFI_CACHE_DIR` environment variable. If not specified,
1027 the default cache directory is ``~/.cache/tvm-ffi``.
1028
1029 Parameters
1030 ----------
1031 name
1032 The name of the tvm ffi module.
1033 cpp_sources
1034 The C++ source code. It can be a list of sources or a single source.
1035 cuda_sources
1036 The CUDA source code. It can be a list of sources or a single source.
1037 functions
1038 The functions in cpp_sources or cuda_source that will be exported to the tvm ffi module. When a mapping is
1039 given, the keys are the names of the exported functions, and the values are docstrings for the functions
1040 (use an empty string to skip documentation for specific functions). When a sequence or a single string is given, they are
1041 the functions needed to be exported, and the docstrings are set to empty strings. A single function name can
1042 also be given as a string. When cpp_sources is given, the functions must be declared (not necessarily defined)
1043 in the cpp_sources. When cpp_sources is not given, the functions must be defined in the cuda_sources. If not
1044 specified, no function will be exported.
1045 extra_cflags
1046 The extra compiler flags for C++ compilation.

Callers

nothing calls this directly

Calls 2

load_moduleFunction · 0.90
build_inlineFunction · 0.85

Tested by

no test coverage detected