C++ API print DLTensor values?

How to convenient print DLTensor values?

Like

DLTensor* a;

I have to using ((float*)a->data)[0] any better way to print one value out?

@jinfagang

  1. convert DLTensor to NDArray; https://github.com/apache/tvm/blob/58716081637fdf21bdae44122086f1dbc35f7c35/include/tvm/runtime/ndarray.h#L92
  2. Print NDArray: https://github.com/apache/tvm/blob/8bbb2066860670e67389496f91b81d3d1f9e3170/src/printer/tvmscript_printer.cc#L422

thanks. does there any demo to call these api? for instance, I have a tvm::runtime::NDArray a

can I using cout << a to print values?

Maybe no (need to confirm) but you can use NDArrayToTIR<float>(a, std::cout) from here:

I note that this is from source file so maybe just copy and paste the implementation to your project.