code: def opencl_cost_estimator(mod, target):
      mod = (
          clml.preprocess_for_clml(mod)
          if "clml" == target.kind.name
          else mod
      )
      try:
          # Build the module.
          logging.info("Compiling module to estimate")
          exe = tvm.relay.vm.compile(mod, target)
      except RuntimeError as err:
          # A build failure indicates the partition is not supported.
          # eg trying to build an nn.batch_norm on GPU, which has no schedule since we assume it
          # is only ever used with a tuple projection which is rewritten away.
          logging.info(
              "Assigning module infinite cost since unable to build: %s",
              err,
          )
          return math.inf
  
      lib = exe.mod
      tracker = rpc.connect_tracker(RPC_TRACKER_HOST, RPC_TRACKER_PORT)
      remote = tracker.request(RPC_KEY, priority=0, session_timeout=600)
      temp = utils.tempdir()
      dso_binary = "dev_lib_cl.so"
      dso_binary_path = temp.relpath(dso_binary)
      ctx = remote.cl(0)
      lib.export_library(dso_binary_path, cc=NDK_CROSS_COMPILER)
      remote_path = dso_binary
      remote.upload(dso_binary_path, target=remote_path)
      lib = remote.load_module(remote_path)
  
      vm_factory = tvm.runtime.vm.VirtualMachine(lib, ctx)
      func_name = "main"
      main_args = {
          v.name_hint: arg_for(v.checked_type, ctx)
          for v in mod[func_name].params
      }
      cost = vm_factory.benchmark(
          ctx,
          repeat=5,
          number=20,
          min_repeat_ms=0,
          func_name=func_name,
          **main_args,
      )
      return cost.mean
  
imports: import tvm
  import logging
  import tempfile
  import os
  import shutil
  import numpy
  from tvm.relay import testing
  from tvm import rpc
  from tvm.contrib import utils, ndk
  from tvm.relay.build_module import bind_params_by_name
  from tvm.relay.collage.collage import *
  from tvm.relay.op.contrib import clml
  import pytest
label_desc: Use image node_id 7 for calling a global function with example usage: opencl_cost_estimator(mod, target) and returns: cost, math