code: def check_packed_func(target="llvm"):
      ib = tvm.tir.ir_builder.create()
  
      m = n = k = 16
  
      #
      # Prepare buffer for a, b and c:
      #
      a = te.placeholder((m, k), name="a", dtype="float64")
      b = te.placeholder((k, n), name="b", dtype="float64")
      k = te.reduce_axis((0, k), name="k")
      c = te.compute(
          (m, n),
          lambda i, j: te.sum(a[i, k] * b[k, j], axis=k),
          name="c",
      )
  
      a_buffer = tvm.tir.decl_buffer(
          a.shape,
          a.dtype,
          name="a_buffer",
          offset_factor=1,
          strides=[te.var("s1"), 1],
      )
      b_buffer = tvm.tir.decl_buffer(
          b.shape,
          b.dtype,
          name="b_buffer",
          offset_factor=1,
          strides=[te.var("s2"), 1],
      )
      c_buffer = tvm.tir.decl_buffer(
          c.shape,
          c.dtype,
          name="c_buffer",
          offset_factor=1,
          strides=[te.var("s3"), 1],
      )
  
      with ib.for_range(0, 10, "i", kind="parallel"):
          ib.emit(
              tvm.tir.call_packed(
                  "tvm.test_matmul", a_buffer, b_buffer, c_buffer
              )
          )
  
      stmt = ib.get()
  
      # Construct a valid IRModule to be lowered:
      mod = tvm.IRModule.from_expr(
          tvm.tir.PrimFunc([a_buffer, b_buffer, c_buffer], stmt)
      )
  
      target = tvm.target.Target(target, host="llvm")
      mod = tvm.tir.transform.Apply(
          lambda f: f.with_attr("target", target)
      )(mod)
      mod = tvm.tir.transform.Apply(
          lambda f: f.with_attr("global_symbol", "main")
      )(mod)
      mod = tvm.tir.transform.MakePackedAPI()(mod)
  
      # Do the lowering:
      mod = tvm.tir.transform.LowerTVMBuiltin()(mod)
  
      # Get the PrimFunc from module:
      prim_func = mod.functions.items()[0][1]
  
      node = prim_func.body
  
      # Recursively visit PrimFunc until we meet the for-loop:
      while True:
          if isinstance(
              node,
              (
                  tvm.tir.AssertStmt,
                  tvm.tir.LetStmt,
                  tvm.tir.AttrStmt,
                  tvm.tir.DeclBuffer,
              ),
          ):
              node = node.body
          elif isinstance(node, tvm.tir.SeqStmt):
              node = node[0]
          else:
              break
  
      # For-loop:
      assert isinstance(node, tvm.tir.stmt.For)
  
      #
      # let stack_tcode = tir.tvm_stack_alloca("arg_tcode", 4)
      #
      alloca_tcode = node.body
      assert isinstance(alloca_tcode, tvm.tir.LetStmt)
  
      expected_value = tvm.tir.call_intrin(
          "handle",
          tvm.ir.Op.get("tir.tvm_stack_alloca"),
          "arg_tcode",
          4,
      )
      expected_var = alloca_tcode.var
      expected_stmt = tvm.tir.LetStmt(
          expected_var, expected_value, alloca_tcode.body
      )
  
      tvm.ir.assert_structural_equal(
          alloca_tcode, expected_stmt, map_free_vars=True
      )
  
      #
      # let stack_value = tir.tvm_stack_alloca("arg_value", 4)
      #
      alloca_value = alloca_tcode.body.body
      assert isinstance(alloca_value, tvm.tir.LetStmt)
  
      expected_value = tvm.tir.call_intrin(
          "handle",
          tvm.ir.Op.get("tir.tvm_stack_alloca"),
          "arg_value",
          4,
      )
      expected_var = alloca_value.var
      expected_stmt = tvm.tir.LetStmt(
          expected_var, expected_value, alloca_value.body
      )
  
      tvm.ir.assert_structural_equal(
          alloca_value, expected_stmt, map_free_vars=True
      )
  
      #
      # let stack_array = tir.tvm_stack_alloca("array", 3)
      #
      alloca_array = alloca_value.body
      assert isinstance(alloca_array, tvm.tir.LetStmt)
  
      expected_value = tvm.tir.call_intrin(
          "handle", tvm.ir.Op.get("tir.tvm_stack_alloca"), "array", 3
      )
      expected_var = alloca_array.var
      expected_stmt = tvm.tir.LetStmt(
          expected_var, expected_value, alloca_array.body
      )
  
      tvm.ir.assert_structural_equal(
          alloca_array, expected_stmt, map_free_vars=True
      )
  
      #
      # let stack_shape = tir.tvm_stack_alloca("shape", 12)
      #
      alloca_shape = alloca_array.body
      assert isinstance(alloca_shape, tvm.tir.LetStmt)
  
      expected_value = tvm.tir.call_intrin(
          "handle", tvm.ir.Op.get("tir.tvm_stack_alloca"), "shape", 12
      )
      expected_var = alloca_shape.var
      expected_stmt = tvm.tir.LetStmt(
          expected_var, expected_value, alloca_shape.body
      )
  
      tvm.ir.assert_structural_equal(
          alloca_shape, expected_stmt, map_free_vars=True
      )
  
imports: import tvm
  import tvm.testing
  from tvm import te
  from tvm.script import tir
  import numpy
  from tvm.tir.schedule.testing import assert_structural_equal_ignore_global_symbol
label_desc: Use image node_id 2 for calling a global function with example usage: check_packed_func(target) without return types