mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Is there any convenient way to print the Tensor<xpu, dim> struct content in the operator forward function?

Open pinglforever opened this issue 10 years ago • 6 comments

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!

pinglforever avatar Aug 29 '16 02:08 pinglforever

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 avatar Aug 29 '16 08:08 Godricly

@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!

pinglforever avatar Aug 29 '16 08:08 pinglforever

use example/python-howto/monitor_weight.py

piiswrong avatar Aug 29 '16 12:08 piiswrong

@piiswrong, I want to print the input and output of an operator in c++, Is there any convenient way to do this? thanks!

pinglforever avatar Aug 30 '16 03:08 pinglforever

.

mcxkarakoc avatar May 10 '17 16:05 mcxkarakoc

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!

yajiedesign avatar Sep 30 '17 11:09 yajiedesign