Skip to content

Commit

Permalink
debugging mxnet c++ operator (apache#4926)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taras Sereda authored and mli committed Mar 15, 2017
1 parent 2f201fa commit 99cd4ad
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
31 changes: 31 additions & 0 deletions example/python-howto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,34 @@ Python Howto Examples
=====================
* [Configuring Net to get Multiple Ouputs](multiple_outputs.py)
* [Configuring Image Record Iterator](data_iter.py)
* Set break point in C++ code of the symbol using gdb under Linux:

* Build mxnet with following values:

```
DEBUG=1
CUDA=0 #to make sure convolution-inl.h will be used
CUDNN=0 #to make sure convolution-inl.h will be used
```
* run python under gdb: ```gdb --args python debug_conv.py```
* in gdb set break point on particular line of the code and run execution:

```
(gdb) break src/operator/convolution-inl.h:120
(gdb) run
Breakpoint 1, mxnet::op::ConvolutionOp<mshadow::cpu, float>::Forward (this=0x12219d0, ctx=..., in_data=std::vector of length 3, capacity 4 = {...}, req=std::vector of length 1, capacity 1 = {...}, out_data=std::vector of length 1, capacity 1 = {...},
aux_args=std::vector of length 0, capacity 0) at src/operator/./convolution-inl.h:121
121 data.shape_[1] / param_.num_group * param_.kernel[0] * param_.kernel[1]);
(gdb) list
116 }
117 Tensor<xpu, 4, DType> data = in_data[conv::kData].get<xpu, 4, DType>(s);
118 Shape<3> wmat_shape =
119 Shape3(param_.num_group,
120 param_.num_filter / param_.num_group,
121 data.shape_[1] / param_.num_group * param_.kernel[0] * param_.kernel[1]);
122 Tensor<xpu, 3, DType> wmat =
123 in_data[conv::kWeight].get_with_shape<xpu, 3, DType>(wmat_shape, s);
124 Tensor<xpu, 4, DType> out = out_data[conv::kOut].get<xpu, 4, DType>(s);
125 #if defined(__CUDACC__)
```
22 changes: 22 additions & 0 deletions example/python-howto/debug_conv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import mxnet as mx

data_shape = (1,3,5,5)
class SimpleData(object):

def __init__(self, data):
self.data = data

data = mx.sym.Variable('data')
conv = mx.sym.Convolution(data=data, kernel=(3,3), pad=(1,1), stride=(1,1), num_filter=1)
mon = mx.mon.Monitor(1)


mod = mx.mod.Module(conv)
mod.bind(data_shapes=[('data', data_shape)])
mod._exec_group.install_monitor(mon)
mod.init_params()

input_data = mx.nd.ones(data_shape)
mod.forward(data_batch=SimpleData([input_data]))
res = mod.get_outputs()[0].asnumpy()
print(res)

0 comments on commit 99cd4ad

Please sign in to comment.