Is there any convenient way to print the Tensor<xpu, dim> struct content in the operator forward function?
Hello, I want to debug the operator forward and backward function in operator class to see what it means. And I write a function in that class to print out the data in Tensor.
template <int dim>
void print_info(const mshadow::Tensor<xpu, dim >& tensor, const std::string& name ) {
std::cout << "Tensor " << name << "info list as below: " << std::endl;
std::cout << "shape: (";
int len = 1;
for(int i = 0; i < dim; i++) {
len *= tensor.shape_[i];
std::cout << tensor.shape_[i] << ",";
if (i == dim - 1)
std::cout << ")";
}
std::cout << "data info list as below: " << std::endl;
for (int j = 0; j < len; j ++) {
std::cout << tensor.dptr_[j] << " ";
}
std::cout << std::endl;
}
When I run mxnet with this code, invoke the function like this
print_info(tensor, "data")
However, The program will generate the 'Segment fault' error when execute the std::cout << tensor.dptr_[j] << " ";.
Waiting for your help, thanks!
If u are using GPU, ur data are on device. Copy them back to memory before calling this function. Also there is a monitor callback to look into these array.
@Godricly , yes , I am using GPU, How can I copy the tensor on gpu to cpu memory through cpp, Which api can i use? And what's the monitor callback you talk about ? Thanks!
use example/python-howto/monitor_weight.py
@piiswrong, I want to print the input and output of an operator in c++, Is there any convenient way to do this? thanks!
.
This issue is closed due to lack of activity in the last 90 days. Feel free to reopen if this is still an active issue. Thanks!