Debug Caffe on Ubuntu with GDB

In this post I will briefly introduce how to use GDB(GNU Dbug tool) to debug caffe CPU code on Ubuntu.

1. Installation

Firstly you install GDB on you Ubuntu system, simplely type sudo apt-get install gdb.

2. Build caffe with Debug mode

We have to build caffe with debug mode on, this can be done easily by uncommenting DEBUG := 1 in “Makefile.config, if you are familar with gcc compiler, it’s simplely add a -g option when compling.

3. Using gdb to debug lenet as an example

Assume you are at root folder of caffe source:

As gdb cannot debug the GPU code, so you have to set solver mode to ‘CPU’ at the solver file(usually named solver.prototxt). In our example, this file is examples/mnist/lenet_solver.prototxt, modify solver_mode=GPU to CPU.

  1. Start debug lenet with gdb --args build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxtThe --args option indicates that you will take some arguments into the target.

  2. Set a breakpoint using break command: break conv_layer.cpp:30(or b conv_layer.cpp:30 for short),choose y When ask whether to pending from extra library.

    • Use of breakbreak FILE_NAME:LINE_NUMBER
    • Or more complicate you can set conditional break point by break FILE_NAME:LINE_NUMBER if (SOME CONDITION)

  1. Start running by run(or r for short). You will break at line30 of conv_layer.cpp, then you can access the intermediate value by print them.
    • print top.size(): print the number of top(output) blobs in conv_layer.
    • print top[0]->shape(): print shape of the first output blob of conv_layer.

More complicated function you should refer to information about GDB itself, because this post aim at telling you how to debug caffe, rather than a tutorial on how to use GDB.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值