code: def test_c_link_params(linkable_dtype):
      temp_dir = utils.tempdir()
      mod, param_init = _make_mod_and_params(linkable_dtype)
      rand_input = _make_random_tensor(linkable_dtype, INPUT_SHAPE)
      main_func = mod["main"]
      target = "c"
      executor = Executor("graph", {"link-params": True})
      with tvm.transform.PassContext(
          opt_level=3, config={"tir.disable_vectorize": True}
      ):
          lib = tvm.relay.build(
              mod, target, executor=executor, params=param_init
          )
          assert (
              len(lib.params.keys()) == 0
          )  # NOTE: params became tir.constants
  
          src = lib.lib.get_source()
          lib.lib.save(temp_dir.relpath("test.c"), "c")
          c_dtype = _get_c_datatype(linkable_dtype)
          src_lines = src.split("\n")
          param = param_init[f"{linkable_dtype}_a"].reshape(
              np.prod(KERNEL_SHAPE)
          )
          param_def = rf"^static const {c_dtype} __attribute__\(\(section\(\".rodata.tvm\"\), aligned\(16\)\)\) [a-zA-Z_0-9]*constant_\d+\[{np.prod(param.shape)}\] = {{$"
  
          for i, line in enumerate(src_lines):
              if re.match(param_def, line):
                  i += 1
                  break
          else:
              assert (
                  False
              ), f'did not find parameter definition "{param_def}":\n{src}'
  
          cursor = 0
          width = dtype_info(linkable_dtype).bits // 4 + 2
          if linkable_dtype.startswith("int"):
              width += 1  # Account for sign
  
          while "};" not in src_lines[i]:
              for match in HEX_NUM_RE.finditer(src_lines[i]):
                  cursor += 1
              i += 1
  
          assert cursor == np.prod(param.shape)
  
          # Need a unique name per library to avoid dlopen caching the lib load.
          lib_path = temp_dir.relpath(
              f"test-{linkable_dtype}-linked.so"
          )
          lib["remove_params"]().export_library(lib_path)
          lib_mod = tvm.runtime.load_module(lib_path)
  
          #            lib_mod = lib_factory['default']()
          graph = json.loads(lib.graph_json)
          for p in lib.params:
              _verify_linked_param(
                  linkable_dtype, lib, lib_mod, graph, p
              )
  
          # Wrap in function to explicitly deallocate the runtime.
          def _run_linked(lib_mod):
              graph_rt = tvm.contrib.graph_executor.GraphModule(
                  lib_mod["default"](tvm.cpu(0))
              )
              graph_rt.set_input(
                  "rand_input", rand_input
              )  # NOTE: params not required.
              graph_rt.run()
  
              return graph_rt.get_output(0)
  
          linked_output = _run_linked(lib_mod)
  
      linked_params = lib.params
      with tvm.transform.PassContext(
          opt_level=3, config={"tir.disable_vectorize": True}
      ):
          lib = tvm.relay.build(mod, "c", params=param_init)
          _, _, params = lib
          # Need a unique name per library to avoid dlopen caching the lib load.
          lib_path = temp_dir.relpath(
              f"test-{linkable_dtype}-unlinked.so"
          )
          lib.export_library(lib_path)
          lib_mod = tvm.runtime.load_module(lib_path)
  
          def _run_unlinked(lib_mod):
              graph_rt = tvm.contrib.graph_executor.GraphModule(
                  lib_mod["default"](tvm.cpu(0))
              )
              graph_rt.set_input("rand_input", rand_input, **params)
              graph_rt.run()
              return graph_rt.get_output(0)
  
          unlinked_output = _run_unlinked(lib_mod)
  
      if "int" in linkable_dtype:
          np.testing.assert_equal(
              unlinked_output.numpy(), linked_output.numpy()
          )
      else:
          np.testing.assert_allclose(
              unlinked_output.numpy(), linked_output.numpy()
          )
  
imports: import collections
  import ctypes
  import json
  import os
  import re
  from contextlib import redirect_stderr
  from io import StringIO
  import numpy
  import tvm
  import tvm.relay
  import tvm.testing
  from tvm import meta_schedule
  from tvm import relay
  from tvm.contrib import utils
  from tvm.relay.backend import Executor, Runtime
label_desc: Use image node_id 9 for calling a global function with example usage: test_c_link_params(linkable_dtype) and returns: graph_rt, graph_rt