[AutoTVM] Function has input arguments in different order after building and/or exporting

Hello:

I have a simple application of creating a conv2d_NCHWc.x86 tuning task and generate ASM code for external use. Here’s my code:

import tvm
from tvm import autotvm, te
from tvm.topi.x86.conv2d import *

target = tvm.target.Target("llvm -mcpu=core-avx2")
data = te.placeholder((1, 64, 56, 56), name="data")

kernel = te.placeholder((128, 64, 3, 3), name="kernel")
task = autotvm.task.create("conv2d_NCHWc.x86", args=[data, kernel, 1, 1, 1, "NCHW", "NCHW", "float32"], target=target)

# Edited
# kernel = te.placeholder((128, 64, 1, 1), name="kernel")
# task = autotvm.task.create("conv2d_NCHWc.x86", args=[data, kernel, 1, 0, 1, "NCHW", "NCHW", "float32"], target=target)

print(task.config_space)
print(task.target)
print(task.workload)

measure_option = autotvm.measure_option(
    builder=autotvm.LocalBuilder(),
    runner=autotvm.LocalRunner()
)
tuner = autotvm.tuner.XGBTuner(task, feature_type="curve")
log_name = "test.log"
n_trial = 16

tuner.tune(n_trial=n_trial,
            measure_option=measure_option,
            callbacks=[autotvm.callback.progress_bar(min(n_trial, len(task.config_space))),
                        autotvm.callback.log_to_file(log_name)])

dispatch_context = autotvm.apply_history_best(log_name)
best_config = dispatch_context.query(task.target, task.workload)
print('\nBest config:')
print(best_config)

with target:
    s, arg_bufs = task.instantiate(best_config)
print(tvm.lower(s, arg_bufs, simple_mode=True))
func = tvm.build(s, arg_bufs, target, name='conv2d')
print(func.get_source('asm'))

However, I found that the ASM code has a different order for the input arguments. We expect the order to be data, kernel, and output, while the order in the ASM code is output, kernel, and data (examined by looking at the shape of arguments). This affects the external use of it in C code. Is that by design? Or if not how can we fix it?

Thanks in advance!

Did you check the order of arg_bufs ? It should be the order of the compiled ASM. If that order is incorrect, you probably can dive into the task instantiation to see what happen.

Thanks for the reply. I look into the code and see input tensors are collected in a backward order. That raises a problem that the order of input / kernel of a conv2d will be different in the cases of padding / no padding (see the changes I made in the above code). I think some sorting might be needed here.

Created a PR #9058. Can you take a look at it? Thx!