code: def test_legalize_conv2d_HWNC():
      """test legalize HWNC conv2d to enable tensorcore"""
  
      def _test_legalize_conv2d(
          data_shape, kernel_shape, pad_shape, dtype, do_pad=True
      ):
          out_channel = kernel_shape[2]
          out_shape = list(data_shape)
          out_shape[3] = out_channel
          db, di, do = pad_shape
  
          def before():
              x = relay.var("x", shape=data_shape, dtype=dtype)
              weight = relay.var(
                  "weight", shape=kernel_shape, dtype=dtype
              )
              y = relay.nn.conv2d(
                  x,
                  weight,
                  channels=out_channel,
                  kernel_size=(3, 3),
                  padding=(1, 1),
                  data_layout="HWNC",
                  kernel_layout="HWOI",
              )
              y = relay.Function([x, weight], y)
              return y
  
          def legalize_conv2d(attrs, inputs, types):
              with tvm.target.Target("cuda"):
                  return topi.nn.conv2d_legalize(attrs, inputs, types)
  
          def expected():
              if not do_pad:
                  return before()
              x = relay.var("x", shape=data_shape, dtype=dtype)
              if db or di:
                  x_pad = relay.nn.pad(
                      x, pad_width=((0, 0), (0, 0), (0, db), (0, di))
                  )
              else:
                  x_pad = x
              weight = relay.var(
                  "weight", shape=(kernel_shape), dtype=dtype
              )
              if di or do:
                  weight_pad = relay.nn.pad(
                      weight,
                      pad_width=((0, 0), (0, 0), (0, do), (0, di)),
                  )
              else:
                  weight_pad = weight
              y_pad = relay.nn.conv2d(
                  x_pad,
                  weight=weight_pad,
                  channels=out_channel + do,
                  kernel_size=(3, 3),
                  padding=(1, 1),
                  data_layout="HWNC",
                  kernel_layout="HWOI",
              )
              if db or do:
                  y = relay.strided_slice(
                      y_pad, begin=[0, 0, 0, 0], end=out_shape
                  )
              else:
                  y = y_pad
              y = relay.Function([x, weight], y)
              return y
  
          with TempOpAttr("nn.conv2d", "FTVMLegalize", legalize_conv2d):
              a = before()
              a = run_opt_pass(a, transform.Legalize())
              b = run_opt_pass(expected(), transform.InferType())
          assert tvm.ir.structural_equal(a, b), (
              "Actual = \n" + str(a) + "Expected = \n" + str(b)
          )
  
      # conv2d pad batch
      _test_legalize_conv2d(
          (16, 16, 7, 64), (3, 3, 64, 64), (1, 0, 0), "int8"
      )
      _test_legalize_conv2d(
          (16, 16, 3, 64), (3, 3, 64, 64), (5, 0, 0), "int8"
      )
      _test_legalize_conv2d(
          (2, 16, 16, 64), (3, 3, 64, 64), (0, 0, 0), "int8", False
      )
      _test_legalize_conv2d(
          (16, 16, 7, 64), (3, 3, 64, 64), (1, 0, 0), "int4"
      )
      _test_legalize_conv2d(
          (16, 16, 3, 64), (3, 3, 64, 64), (5, 0, 0), "int4"
      )
      _test_legalize_conv2d(
          (2, 16, 16, 64), (3, 3, 64, 64), (0, 0, 0), "int4", False
      )
      # conv2d pad in_channel
      _test_legalize_conv2d(
          (16, 16, 8, 63), (3, 3, 64, 63), (0, 1, 0), "int8"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 33), (3, 3, 64, 33), (0, 15, 0), "int8"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 13), (3, 3, 64, 13), (0, 3, 0), "int8"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 1), (3, 3, 64, 1), (0, 0, 0), "int8", False
      )
      _test_legalize_conv2d(
          (16, 16, 8, 63), (3, 3, 64, 63), (0, 1, 0), "int4"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 33), (3, 3, 64, 33), (0, 31, 0), "int4"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 13), (3, 3, 64, 13), (0, 19, 0), "int4"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 1), (3, 3, 64, 1), (0, 0, 0), "int4", False
      )
      # conv2d pad out_channel
      _test_legalize_conv2d(
          (16, 16, 8, 64), (3, 3, 63, 64), (0, 0, 1), "int8"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 64), (3, 3, 33, 64), (0, 0, 31), "int8"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 64), (3, 3, 1, 64), (0, 0, 0), "int8", False
      )
      _test_legalize_conv2d(
          (16, 16, 8, 64), (3, 3, 63, 64), (0, 0, 1), "int4"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 64), (3, 3, 33, 64), (0, 0, 7), "int4"
      )
      _test_legalize_conv2d(
          (16, 16, 8, 64), (3, 3, 1, 64), (0, 0, 0), "int4", False
      )
  
file_path: tvm/tests/python/relay/test_pass_legalize_tensorcore.py
imports: import numpy
  import tvm
  from tvm import te
  from tvm import topi
  from tvm import relay
  from tvm.contrib import graph_executor
  from tvm.relay import transform, analysis
  from tvm.relay.testing.temp_op_attr import TempOpAttr
label_desc: Use image node_id 3 for calling a global function with example usage: test_legalize_conv2d_HWNC() and returns: y, y, topi, before