code: def override_native_generic_func(func_name):
      """Override a generic function defined in C++
  
      Generic function allows registration of further functions
      that can be dispatched on current target context.
      If no registered dispatch is matched, the fdefault will be called.
  
      Parameters
      ----------
      func_name : string
          The name of the generic func to be overridden
  
      Returns
      -------
      fgeneric : function
          A wrapped generic function.
  
      Example
      -------
      .. code-block:: python
  
        import tvm
        # wrap function as target generic
        @tvm.target.override_native_generic_func("my_func")
        def my_func(a):
            return a + 1
        # register specialization of my_func under target cuda
        @my_func.register("cuda")
        def my_func_cuda(a):
            return a + 2
        # displays 3, because my_func is called
        print(my_func(2))
        # displays 4, because my_func_cuda is called
        with tvm.target.cuda():
            print(my_func(2))
      """
      generic_func_node = get_native_generic_func(func_name)
  
      def fdecorate(fdefault):
          """Wrap a target generic function, overriding the previous
          default that was set for the generic function.
  
          Parameters
          ----------
          fdefault : function
              The default function.
  
          Returns
          -------
          fgeneric : function
              A wrapped generic function.
  
          """
          generic_func_node.set_default(fdefault, allow_override=True)
  
          def register(key, func=None, override=True):
              """Register function to be the dispatch function.
  
              Parameters
              ----------
              key : str or list of str
                  The key to be registered.
  
              func : function
                  The function to be registered.
  
              override : bool, optional
                  Whether override existing registration.
  
              Returns
              -------
              The register function is necessary.
              """
  
              def _do_reg(myf):
                  generic_func_node.register(myf, key, override)
                  return myf
  
              if func:
                  return _do_reg(func)
              return _do_reg
  
          def dispatch_func(func, *args, **kwargs):
              # pylint: disable=unused-argument
              """The wrapped dispath function"""
              if kwargs:
                  raise RuntimeError(
                      "Keyword arguments cannot be used when invoking generic_func %s"
                      % func_name
                  )
              return generic_func_node(*args)
  
          fresult = decorate(fdefault, dispatch_func)
          fresult.fdefault = fdefault
          fresult.register = register
          fresult.generic_func_node = generic_func_node
          return fresult
  
      return fdecorate
  
file_path: tvm/python/tvm/target/generic_func.py
imports: import tvm._ffi
  from tvm.runtime import Object
  from .target import Target
  from .None import _ffi_api
label_desc: Use image node_id 2 for calling a global function with example usage: override_native_generic_func(func_name) and returns: fdecorate, fresult, _do_reg, generic_func_node, myf, _do_reg