Exemple #1
0
def create(graph_json_str, libmod, device, dump_root=None):
    """Create a runtime executor module given a graph and module.

    Parameters
    ----------
    graph_json_str : str
        The graph to be deployed in json format output by graph compiler.
        The graph can contain operator(tvm_op) that points to the name
        of PackedFunc in the libmod.

    libmod : tvm.Module
        The module of the corresponding function.

    device : Device
        The device to deploy the module, can be local or remote.

    dump_root : str
        To select which folder the outputs should be kept.
        None will make a temp folder in /tmp/tvmdbg<rand_string> and does the dumping
    Returns
    -------
    graph_module : GraphModuleDebug
        Debug Runtime graph module that can be used to execute the graph.
    """
    assert isinstance(graph_json_str, string_types)

    try:
        dev, num_rpc_dev, device_type_id = graph_executor.get_device(
            libmod, device)
        if num_rpc_dev == len(dev):
            fcreate = dev[0]._rpc_sess.get_function(
                "tvm.graph_executor_debug.create")
        else:
            fcreate = tvm._ffi.get_global_func(
                "tvm.graph_executor_debug.create")
    except ValueError:
        raise ValueError("Please set '(USE_PROFILER ON)' in "
                         "config.cmake and rebuild TVM to enable debug mode")
    func_obj = fcreate(graph_json_str, libmod, *device_type_id)
    gmod = GraphModuleDebug(func_obj, dev, graph_json_str, dump_root)

    # Automatically set params if they can be extracted from the libmod
    try:
        params = libmod["get_graph_params"]()
    except (AttributeError, tvm.error.RPCError):
        # Params can not be extracted from the libmod and must be set somewhere else manually
        # Do not set params during RPC communication
        pass
    else:
        gmod.set_input(**params)

    return gmod
Exemple #2
0
def create(graph_json_str, libmod, device):
    """Create a runtime executor module given a graph and module.

    Parameters
    ----------
    graph_json_str : str
        The graph to be deployed in json format output by json graph.
        The graph can contain operator(tvm_op) that points to the name
        of PackedFunc in the libmod.

    libmod : tvm.runtime.Module
        The module of the corresponding function

    device : Device
        The device to deploy the module, only supports CUDA GPU

    Returns
    -------
    graph_module : GraphModuleCudaGraph
        CUDA graph executor module that can be used to execute the graph.

    Note
    ----
    See also :py:class:`tvm.contrib.cuda_graph.cuda_graph_executor.GraphModuleCudaGraph`
    for examples to directly construct a GraphModuleCudaGraph from an exported
    relay compiled library.
    """
    assert isinstance(graph_json_str, string_types)
    try:
        dev, num_rpc_dev, device_type_id = graph_executor.get_device(
            libmod, device)
        if num_rpc_dev == len(dev):
            fcreate = dev[0]._rpc_sess.get_function(
                "tvm.graph_executor_cuda_graph.create")
        else:
            fcreate = tvm._ffi.get_global_func(
                "tvm.graph_executor_cuda_graph.create")
    except ValueError:
        raise ValueError(
            "To enable CUDA graph support (experimental), please set "
            "'(USE_GRAPH_EXECUTOR_CUGRAPH ON)' in config.cmake and rebuild TVM"
        )

    return GraphModuleCudaGraph(
        fcreate(graph_json_str, libmod, *device_type_id))
Exemple #3
0
def create(graph_json_str, libmod, device, dump_root=None):
    """Create a runtime executor module given a graph and module.

    Parameters
    ----------
    graph_json_str : str
        The graph to be deployed in json format output by graph compiler.
        The graph can contain operator(tvm_op) that points to the name
        of PackedFunc in the libmod.

    libmod : tvm.Module
        The module of the corresponding function.

    device : Device
        The device to deploy the module, can be local or remote.

    dump_root : str
        To select which folder the outputs should be kept.
        None will make a temp folder in /tmp/tvmdbg<rand_string> and does the dumping
    Returns
    -------
    graph_module : GraphModuleDebug
        Debug Runtime graph module that can be used to execute the graph.
    """
    assert isinstance(graph_json_str, string_types)

    try:
        dev, num_rpc_dev, device_type_id = graph_executor.get_device(
            libmod, device)
        if num_rpc_dev == len(dev):
            fcreate = dev[0]._rpc_sess.get_function(
                "tvm.graph_executor_debug.create")
        else:
            fcreate = tvm._ffi.get_global_func(
                "tvm.graph_executor_debug.create")
    except ValueError:
        raise ValueError("Please set '(USE_GRAPH_EXECUTOR_DEBUG ON)' in "
                         "config.cmake and rebuild TVM to enable debug mode")
    func_obj = fcreate(graph_json_str, libmod, *device_type_id)
    return GraphModuleDebug(func_obj, dev, graph_json_str, dump_root)