tvm._ffi.libinfo

tvm._ffi.libinfo#

import testing
from tvm._ffi.libinfo import get_dll_directories, find_include_path
get_dll_directories??
Signature: get_dll_directories()
Source:   
def get_dll_directories():
    """Get the possible dll directories"""
    # NB: This will either be the source directory (if TVM is run
    # inplace) or the install directory (if TVM is installed).
    # An installed TVM's curr_path will look something like:
    #   $PREFIX/lib/python3.6/site-packages/tvm/_ffi
    ffi_dir = os.path.dirname(os.path.realpath(os.path.expanduser(__file__)))
    source_dir = os.path.join(ffi_dir, "..", "..", "..")
    install_lib_dir = os.path.join(ffi_dir, "..", "..", "..", "..")

    dll_path = []

    if os.environ.get("TVM_LIBRARY_PATH", None):
        dll_path.append(os.environ["TVM_LIBRARY_PATH"])

    if sys.platform.startswith("linux") or sys.platform.startswith("freebsd"):
        dll_path.extend(split_env_var("LD_LIBRARY_PATH", ":"))
        dll_path.extend(split_env_var("PATH", ":"))
    elif sys.platform.startswith("darwin"):
        dll_path.extend(split_env_var("DYLD_LIBRARY_PATH", ":"))
        dll_path.extend(split_env_var("PATH", ":"))
    elif sys.platform.startswith("win32"):
        dll_path.extend(split_env_var("PATH", ";"))

    # Pip lib directory
    dll_path.append(os.path.join(ffi_dir, ".."))
    # Default cmake build directory
    dll_path.append(os.path.join(source_dir, "build"))
    dll_path.append(os.path.join(source_dir, "build", "Release"))
    # Default make build directory
    dll_path.append(os.path.join(source_dir, "lib"))

    dll_path.append(install_lib_dir)

    # use extra TVM_HOME environment for finding libraries.
    if os.environ.get("TVM_HOME", None):
        tvm_source_home_dir = os.environ["TVM_HOME"]
    else:
        tvm_source_home_dir = source_dir

    if os.path.isdir(tvm_source_home_dir):
        dll_path.append(os.path.join(tvm_source_home_dir, "web", "dist", "wasm"))
        dll_path.append(os.path.join(tvm_source_home_dir, "web", "dist"))

    dll_path = [os.path.realpath(x) for x in dll_path]
    return [x for x in dll_path if os.path.isdir(x)]
File:      /media/pc/data/lxw/ai/tvm/python/tvm/_ffi/libinfo.py
Type:      function

get_dll_directories() 函数,用于获取可能包含动态链接库(DLL)的目录。

该函数首先获取当前文件所在的目录,然后根据不同的操作系统平台,将可能包含 DLL 的目录添加到列表中。例如,在 Linux 和 FreeBSD 上,它将从环境变量 LD_LIBRARY_PATHPATH 中提取路径;在 macOS 上,它将从环境变量 DYLD_LIBRARY_PATHPATH 中提取路径;在 Windows 上,它将从环境变量 PATH 中提取路径。

此外,该函数还将一些默认的构建目录添加到列表中,例如使用 CMake 构建的默认目录、使用 Make 构建的默认目录等。最后,如果设置了环境变量 TVM_HOME,则将其作为查找库的额外目录添加到列表中。最终,该函数返回包含所有有效目录的列表。

find_include_path??
Signature: find_include_path(name=None, search_path=None, optional=False)
Source:   
def find_include_path(name=None, search_path=None, optional=False):
    """Find header files for C compilation.

    Parameters
    ----------
    name : list of str
        List of directory names to be searched.

    Returns
    -------
    include_path : list(string)
        List of all found paths to header files.
    """
    if os.environ.get("TVM_HOME", None):
        source_dir = os.environ["TVM_HOME"]
    else:
        ffi_dir = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
        for source_dir in ["..", "../..", "../../.."]:
            source_dir = os.path.join(ffi_dir, source_dir)
            if os.path.isdir(os.path.join(source_dir, "include")):
                break
        else:
            raise AssertionError("Cannot find the source directory given ffi_dir: {ffi_dir}")
    third_party_dir = os.path.join(source_dir, "3rdparty")

    header_path = []

    if os.environ.get("TVM_INCLUDE_PATH", None):
        header_path.append(os.environ["TVM_INCLUDE_PATH"])

    header_path.append(source_dir)
    header_path.append(third_party_dir)

    header_path = [os.path.abspath(x) for x in header_path]
    if search_path is not None:
        if isinstance(search_path, list):
            header_path = header_path + search_path
        else:
            header_path.append(search_path)
    if name is not None:
        if isinstance(name, list):
            tvm_include_path = []
            for n in name:
                tvm_include_path += [os.path.join(p, n) for p in header_path]
        else:
            tvm_include_path = [os.path.join(p, name) for p in header_path]
        dlpack_include_path = []
        dmlc_include_path = []
    else:
        tvm_include_path = [os.path.join(p, "include") for p in header_path]
        dlpack_include_path = [os.path.join(p, "dlpack/include") for p in header_path]
        dmlc_include_path = [os.path.join(p, "dmlc-core/include") for p in header_path]

        # try to find include path
        include_found = [p for p in tvm_include_path if os.path.exists(p) and os.path.isdir(p)]
        include_found += [p for p in dlpack_include_path if os.path.exists(p) and os.path.isdir(p)]
        include_found += [p for p in dmlc_include_path if os.path.exists(p) and os.path.isdir(p)]

    if not include_found:
        message = (
            "Cannot find the files.\n"
            + "List of candidates:\n"
            + str("\n".join(tvm_include_path + dlpack_include_path))
        )
        if not optional:
            raise RuntimeError(message)
        return None

    return include_found
File:      /media/pc/data/lxw/ai/tvm/python/tvm/_ffi/libinfo.py
Type:      function