[SOLVED]How to get a shape unknown output with C++ API?

When using C++ API to run model, one can get output like this:

DLTensor* y; 
int out_ndim = 2; 
int64_t out_shape[2] = {1, 3,}; 
TVMArrayAlloc(out_shape, out_ndim, dtype_code, dtype_bits, dtype_lanes, device_type, device_id, &y);
 // get the function from the module(run it) 
tvm::runtime::PackedFunc run = mod.GetFunction("run");
 // get the function from the module(get output data) 
tvm::runtime::PackedFunc get_output = mod.GetFunction("get_output");

run(); 
get_output(0, y);

In this way, I must know the output shape first, then i can get it.
But my model is a full convolutional network, the output shape is uncertain. How can i get the output if the output shape is uncertain?

Thank you for your reply.

I think you can get the output shape according to the input shape.
for a full convolutional network, the input shape is also variable.

Thank you.
But i think this not very convenient.
The Python API can return the output when only passed the first param, so i think there may be a similar way in C++.

I found code from https://github.com/dmlc/tvm/blob/master/tests/cpp/build_module_test.cc

  PackedFunc set_input = mod.GetFunction("set_input", false);
  PackedFunc run = mod.GetFunction("run", false);
  PackedFunc get_output = mod.GetFunction("get_output", false);
  set_input("A", a_val);
  set_input("B", b_val);
  set_input("C", c_val);

  run();
  tvm::runtime::NDArray out = get_output(0);
  float* p_out = (float*)out.ToDLPack()->dl_tensor.data;

1 Like