code: def test_extern_dnnl():
      def annotated(dtype, ishape, w1shape):
          data = relay.var("data", shape=(ishape), dtype=dtype)
          weight1 = relay.var("weight1", shape=(w1shape), dtype=dtype)
          depthwise_conv2d_1 = relay.nn.conv2d(
              data,
              weight1,
              kernel_size=(3, 3),
              padding=(1, 1),
              groups=32,
          )
          depthwise_conv2d_2 = relay.nn.conv2d(
              depthwise_conv2d_1,
              weight1,
              kernel_size=(3, 3),
              padding=(1, 1),
              groups=32,
          )
          out = relay.add(depthwise_conv2d_1, depthwise_conv2d_2)
  
          f = relay.Function([data, weight1], out)
  
          mod = tvm.IRModule.from_expr(f)
          return mod
  
      def expected(dtype, ishape, w1shape):
          data = relay.var("data", shape=(ishape), dtype=dtype)
          weight1 = relay.var("weight1", shape=(w1shape), dtype=dtype)
          begin0 = relay.annotation.compiler_begin(data, "dnnl")
          begin1 = relay.annotation.compiler_begin(weight1, "dnnl")
          depthwise_conv2d_1 = relay.nn.conv2d(
              begin0,
              begin1,
              kernel_size=(3, 3),
              padding=(1, 1),
              groups=32,
          )
          end0 = relay.annotation.compiler_end(
              depthwise_conv2d_1, "dnnl"
          )
          end1 = relay.annotation.compiler_end(
              depthwise_conv2d_1, "dnnl"
          )
          begin2 = relay.annotation.compiler_begin(end1, "dnnl")
          begin3 = relay.annotation.compiler_begin(end0, "dnnl")
          begin4 = relay.annotation.compiler_begin(weight1, "dnnl")
          depthwise_conv2d_2 = relay.nn.conv2d(
              begin3,
              begin4,
              kernel_size=(3, 3),
              padding=(1, 1),
              groups=32,
          )
          end2 = relay.annotation.compiler_end(
              depthwise_conv2d_2, "dnnl"
          )
          begin5 = relay.annotation.compiler_begin(end2, "dnnl")
          out = relay.add(begin2, begin5)
          end3 = relay.annotation.compiler_end(out, "dnnl")
          f = relay.Function([data, weight1], end3)
          mod = tvm.IRModule.from_expr(f)
          return mod
  
      dtype = "float32"
      ishape = (1, 32, 14, 14)
      w1shape = (32, 1, 3, 3)
  
      def test_annotate():
          mod = annotated(dtype, ishape, w1shape)
          mod = transform.AnnotateTarget("dnnl")(mod)
          mod = relay.transform.InferType()(mod)
          ref_mod = expected(dtype, ishape, w1shape)
          ref_mod = relay.transform.InferType()(ref_mod)
          tvm.ir.assert_structural_equal(mod, ref_mod)
  
      def test_run():
          if not tvm.get_global_func("relay.ext.dnnl", True):
              print("skip because DNNL codegen is not available")
              return
  
          ref_mod = annotated(dtype, ishape, w1shape)
          mod = annotated(dtype, ishape, w1shape)
          mod = transform.PartitionGraph()(mod)
  
          i_data = np.random.uniform(0, 1, ishape).astype(dtype)
          w1_data = np.random.uniform(0, 1, w1shape).astype(dtype)
  
          ref_res = relay.create_executor(
              "graph", mod=ref_mod, device=tvm.cpu()
          ).evaluate()(i_data, w1_data)
  
          check_result(
              mod,
              {"data": i_data, "weight1": w1_data},
              (1, 32, 14, 14),
              ref_res.numpy(),
              tol=1e-5,
          )
  
      test_annotate()
      test_run()
  
imports: import os
  import sys
  import numpy
  import pytest
  import tvm
  import tvm.relay.testing
  import tvm.relay.transform
  from tvm import relay
  from tvm import runtime
  from tvm.contrib import utils
label_desc: Use image node_id 2 for calling a global function with example usage: test_extern_dnnl() and returns: mod, mod