...
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
...
- File → Open → Select the MXNet directory.
- Setup VSCode for Debugging Python and C++ code
- View → Debug
- Click on the Current configuration drop-down (in screenshot below it says "No Configurations")
- In the drop-down choose "Add Configuration"
- Choose "Python" as the configuration type
- 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.
- Setup VSCode for Debugging Python and C++ code
Copy below snippet to 'launch.json' and save. We have 3 launch configurations below:
...
- Open 'incubator-mxnet/tests/python/unittest/test_operator.py
- 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)
- Add breakpoint. You can click to left of the line number where you want to add a breakpoint for debugging.
- Go to softmax implementation code - 'incubator-mxnet/src/operator/nn/softmax-inl.h'
- Add breakpoint in the softmax function - 'inline void Softmax(..)'
Now, let us debug.
...
- Go back to the test_operator.py file.
- Open Debug window: View→ Debug
- 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.
At the top you can see the debugging controls. (Or, you can use shortcut commands, see appendix below)
Now, you should hit the debug point in your softmax test function like below.
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.
You can now see that debug point is attached to the softmax CPP implementation code.
On the left, debug panel, you use 'python' and 'lldb' debugger to switch between
Now, you can continue execution, debug, inspect values and more.
You can also use Debug console to inspect and debug.
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.
...