code: def test_alter_layout_depthwise_conv2d():
      """Test depthwise_conv2d operator"""
  
      def before():
          x = relay.var("x", shape=(1, 32, 56, 56))
          w = relay.var("w", shape=(32, 1, 3, 3))
          y = relay.nn.conv2d(
              x,
              w,
              padding=(1, 1),
              channels=32,
              kernel_size=(3, 3),
              groups=32,
          )
          y = relay.Function(analysis.free_vars(y), y)
          return y
  
      from tvm import topi
  
      def alter_conv2d(attrs, inputs, tinfos, out_type):
          with tvm.target.Target(
              "llvm -mtriple=x86_64-linux-gnu -mcpu=core-avx2"
          ):
              return topi.nn.conv2d_alter_layout(
                  attrs, inputs, tinfos, out_type
              )
  
      def expected():
          x = relay.var("x", shape=(1, 32, 56, 56))
          w = relay.var("w", shape=(32, 1, 3, 3))
          x = relay.layout_transform(x, "NCHW", "NCHW8c")
          w = relay.layout_transform(w, "OIHW", "OIHW1i8o")
          y = relay.nn.contrib_depthwise_conv2d_nchwc(
              x,
              w,
              padding=(1, 1, 1, 1),
              channels=32,
              kernel_size=(3, 3),
              groups=32,
              data_layout="NCHW8c",
              kernel_layout="OIHW1i8o",
              out_layout="NCHW8c",
          )
          y = relay.layout_transform(y, "NCHW8c", "NCHW")
          y = relay.Function(analysis.free_vars(y), y)
          return y
  
      with TempOpAttr("nn.conv2d", "FTVMAlterOpLayout", alter_conv2d):
          a = before()
          a = run_opt_pass(
              a,
              [transform.CanonicalizeOps(), transform.AlterOpLayout()],
          )
          b = run_opt_pass(expected(), transform.InferType())
  
      assert tvm.ir.structural_equal(a, b)
  
imports: import pytest
  import tvm
  from tvm import relay, topi
  from tvm.relay import transform, analysis
  from tvm.relay.testing.temp_op_attr import TempOpAttr
  from tvm.relay.testing import run_infer_type
  import numpy
  import tvm.testing
  from tvm.relay import testing
label_desc: Use image node_id 18 for calling a global function with example usage: test_alter_layout_depthwise_conv2d() and returns: y, y, topi