code: def test_coreml_runtime():
      import coremltools
      from coremltools.models.neural_network import NeuralNetworkBuilder
  
      def create_coreml_model():
          shape = (2,)
          alpha = 2
  
          inputs = [
              ("input0", coremltools.models.datatypes.Array(*shape)),
              ("input1", coremltools.models.datatypes.Array(*shape)),
          ]
          outputs = [
              ("output0", coremltools.models.datatypes.Array(*shape)),
              ("output1", coremltools.models.datatypes.Array(*shape)),
          ]
          builder = NeuralNetworkBuilder(inputs, outputs)
          builder.add_elementwise(
              name="Add",
              input_names=["input0", "input1"],
              output_name="output0",
              mode="ADD",
          )
          builder.add_elementwise(
              name="Mul",
              alpha=alpha,
              input_names=["input0"],
              output_name="output1",
              mode="MULTIPLY",
          )
          return coremltools.models.MLModel(builder.spec)
  
      def verify(coreml_model, model_path, dev):
          coreml_model = create_coreml_model()
  
          out_spec = coreml_model.output_description._fd_spec
          out_names = [spec.name for spec in out_spec]
  
          # inference via coremltools
          inputs = {}
          for in_spec in coreml_model.input_description._fd_spec:
              name = in_spec.name
              shape = in_spec.type.multiArrayType.shape
              inputs[name] = np.random.random_sample(shape)
  
          coreml_outputs = [
              coreml_model.predict(inputs)[name] for name in out_names
          ]
  
          # inference via tvm coreml runtime
          runtime = coreml_runtime.create("main", model_path, dev)
          for name in inputs:
              runtime.set_input(name, tvm.nd.array(inputs[name], dev))
          runtime.invoke()
          tvm_outputs = [
              runtime.get_output(i).numpy()
              for i in range(runtime.get_num_outputs())
          ]
  
          for c_out, t_out in zip(coreml_outputs, tvm_outputs):
              np.testing.assert_almost_equal(c_out, t_out, 3)
  
      def check_remote(coreml_model):
          temp = utils.tempdir()
          compiled_model = xcode.compile_coreml(
              coreml_model, out_dir=temp.temp_dir
          )
          xcode.popen_test_rpc(
              proxy_host,
              proxy_port,
              key,
              destination=destination,
              libs=[compiled_model],
          )
          compiled_model = os.path.basename(compiled_model)
          remote = rpc.connect(proxy_host, proxy_port, key=key)
          dev = remote.cpu(0)
          verify(coreml_model, compiled_model, dev)
  
      def check_local(coreml_model):
          temp = utils.tempdir()
          compiled_model = xcode.compile_coreml(
              coreml_model, out_dir=temp.temp_dir
          )
          dev = tvm.cpu(0)
          verify(coreml_model, compiled_model, dev)
  
      coreml_model = create_coreml_model()
      check_remote(coreml_model)
      check_local(coreml_model)
  
file_path: tvm/tests/python/contrib/test_coreml_runtime.py
imports: import tvm
  from tvm import te
  import numpy
  from tvm import rpc
  from tvm.contrib import utils, xcode, coreml_runtime
  import pytest
  import os
label_desc: Use image node_id 1 for calling a global function with example usage: test_coreml_runtime() and returns: coremltools