code: def profile_and_build(
      mod,
      params,
      sm,
      split_k_slices=[1],
      tmp_dir="./tmp",
      use_fast_math=False,
      use_3xtf32=True,
      use_ansor=False,
      ansor_tuning=False,
  ):
      logging.info("before partitioning:\n%s", mod)
      mod = partition_for_cutlass(mod)
      logging.info("after partitioning:\n%s", mod)
  
      num_cutlass_partition = num_cutlass_partitions(mod)
      host = tvm.target.Target("llvm")
      cuda = tvm.target.Target("cuda", host=host)
      cutlass = tvm.target.Target(
          {
              "kind": "cutlass",
              "sm": sm,
              "use_3xtf32": use_3xtf32,
              "split_k_slices": split_k_slices,
              "profile_all_alignments": False,
              "find_first_valid": True,
              "use_multiprocessing": True,
              "use_fast_math": use_fast_math,
              "tmp_dir": tmp_dir,
          },
          host=host,
      )
  
      if use_ansor:
          with tvm.transform.PassContext(
              opt_level=3,
              config={"relay.backend.use_auto_scheduler": True},
          ):
              tasks, task_weights = auto_scheduler.extract_tasks(
                  mod,
                  params,
                  cuda,
                  include_simple_tasks=True,
                  opt_level=3,
                  other_targets=[cutlass],
              )
          for idx, (task, task_weight) in enumerate(
              zip(tasks, task_weights)
          ):
              logging.info(
                  f"==== Task {idx}: {task.desc} (weight {task_weight} key: {task.workload_key}) ====="
              )
              logging.info(task.compute_dag)
  
          with tempfile.NamedTemporaryFile() as fp:
              log_file = fp.name
  
              # auto-tuning is disabled by default
              if ansor_tuning:
                  measure_ctx = auto_scheduler.LocalRPCMeasureContext(
                      repeat=3, min_repeat_ms=200, timeout=10
                  )
                  tuner = auto_scheduler.TaskScheduler(
                      tasks, task_weights
                  )
                  tuner.tune(
                      auto_scheduler.TuningOptions(
                          num_measure_trials=100,
                          runner=measure_ctx.runner,
                          measure_callbacks=[
                              auto_scheduler.RecordToFile(log_file),
                          ],
                      )
                  )
  
              with auto_scheduler.ApplyHistoryBest(log_file):
                  with tvm.transform.PassContext(
                      opt_level=3,
                      config={"relay.backend.use_auto_scheduler": True},
                  ):
                      lib = relay.build(
                          mod,
                          target=cuda,
                          target_host=host,
                          params=params,
                      )
      else:
          with tvm.transform.PassContext(opt_level=3):
              lib = relay.build(
                  mod, target=[cuda, cutlass], params=params
              )
      lib = finalize_modules(lib, "compile.so", tmp_dir)
      dev = tvm.device("cuda", 0)
      rt_mod = tvm.contrib.graph_executor.GraphModule(
          lib["default"](dev)
      )
      return rt_mod, dev, num_cutlass_partition
  
imports: import logging
  import tempfile
  import math
  import tvm
  from tvm import relay
  from tvm.contrib.cudnn import conv_output_shape
  import numpy
  from tvm.relay import op
  from tvm.runtime.vm import VirtualMachine
  from tvm.relay.op.contrib.cutlass import partition_for_cutlass
  from tvm import auto_scheduler
  from tvm.relay.transform import FirstOrderGradient, ToMixedPrecision, InferType
  from tvm.contrib.cutlass import has_cutlass, num_cutlass_partitions, finalize_modules, finalize_modules_vm
  import tvm.testing
label_desc: Use image node_id 27 for calling a global function with example usage: profile_and_build(mod, params, sm, split_k_slices, tmp_dir, use_fast_math, use_3xtf32, use_ansor, ansor_tuning) and returns: rt_mod,  dev,  num_cutlass_partition