Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

2.4 Build MXNet core engine(After MXNet 1.6 release)

cp makeconfig/osxdarwin.mk ./config.mk
vi config.mk# Set/update USE_PROFILER, DEBUG compile flags with below values and leave the rest as defaults.
# This setting is required for enabling handles for developers.
# Enable profiling
USE_PROFILER = 1
# whether compile with debug
DEBUG = 1
# choose the version of blas you want to use
# can be: mkl, blas, atlas, openblas
USE_BLAS = apple

# Build MXNet (-j8 => use 8 threads to compile and build)
# Optimal number of threads is typically the number of cores available on your Mac. To get the number of cores available, use this command: "sysctl -n hw.ncpu"
make -j8 

cmake config.cmake
mkdir build; cd build
export CC=clang-10
export CXX=clang++-10
export CXXFLAGS='-fstandalone-debug'
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_CUDA=0 ..; ninja 
or with optimization
cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUSE_CUDA=0 ..; ninja

To clean any previous build, use:

make cleanrm -rf build

2.5 Build MXNet Python binding

...

  1. File → Open → Select the MXNet directory.
    1. Setup VSCode for Debugging Python and C++ code
      • View → Debug
      • Click on the Current configuration drop-down (in screenshot below it says "No Configurations")
      Image RemovedImage Added
    • In the drop-down choose "Add Configuration"
      Image RemovedImage Added
    • Choose "Python" as the configuration type
      Image RemovedImage Added
    • And then you'll see the new configuration file "launch.json" with few default debug configurations. Delete all the contents and copy below provided launch.json.
      Image RemovedImage Added



Copy below snippet to 'launch.json' and save. We have 3 launch configurations below:

...

  1. Open 'incubator-mxnet/tests/python/unittest/test_operator.py
  2. Go to test case - 'test_new_softmax()'. We will debug softmax operator. (Note: You can copy the softmax test function to the top of file to avoid waiting for other tests to pass)
  3. Add breakpoint. You can click to left of the line number where you want to add a breakpoint for debugging.

Image RemovedImage Added


  1. Go to softmax implementation code - 'incubator-mxnet/src/operator/nn/softmax-inl.h'
  2. Add breakpoint in the softmax function - 'inline void Softmax(..)'

Image RemovedImage Added


Now, let us debug.

...

  1. Go back to the test_operator.py file. 
  2. Open Debug window: View→ Debug
  3. From the debug dropdown, select 'Python Launch Debug'. This was the debug configuration we had created in earlier steps. This will launch the current python file (test_operator.py) in debug mode.

Image RemovedImage Added


At the top you can see the debugging controls. (Or, you can use shortcut commands, see appendix below)


Image RemovedImage Added 


Now, you should hit the debug point in your softmax test function like below.

Image RemovedImage Added


Step 2: Start lldb debugger and attach to the python program being tested

...

From Debug dropdown, select 'lldb Attach Debug'. Select and start. Now, choose the 'test_operator.py' python process to attach.


Image RemovedImage Added


You can now see that debug point is attached to the softmax CPP implementation code.


 Image RemovedImage Added

On the left, debug panel, you use 'python' and 'lldb' debugger to switch between 


Image RemovedImage Added 


Now, you can continue execution, debug, inspect values and more.


Image RemovedImage Added


You can also use Debug console to inspect and debug.

Image RemovedImage Added


NOTE: If your C++ code debug point is not active, probably it means, symbols loaded in IDE is not the same that your python code is using. Most likely this will happen if you have pip installed mxnet and not compiled and build from mxnet source in the workspace. My pip list of search for MXNet looks like below, observe that MXNet python package is coming from my workspace.

...