2.3 KiB
2.3 KiB
Debugging Build Flags for libnd4j
This guide covers important build flags used for debugging crashes and performance issues in libnd4j.
Core Debug Flags
1. libnd4j.calltrace
- Purpose: Enables function call tracing for debugging segmentation faults and crashes
- Implementation: Maps to
SD_GCC_FUNC_TRACEcmake flag - How to use:
mvn -Dlibnd4j.calltrace=ON clean install - Technical details:
- Sets optimization level to 0 (
-O0) to preserve debugging information - Enables
-finstrument-functionscompiler flag - Adds debugging symbols with
-g - Sets up function call tracing infrastructure
- Sets optimization level to 0 (
2. libnd4j.printmath
- Purpose: Prints individual math operations for debugging numerical issues
- How to use:
mvn -Dlibnd4j.printmath=ON clean install - Technical details:
- Adds
SD_PRINT_MATHcompile definition - Enables debugging output for operations in platformmath.h and templatemath.h
- Helps track calculation flow and intermediate results
- Adds
3. libnd4j.printindices
- Purpose: Prints indices during array operations to detect out-of-bounds access
- How to use:
mvn -Dlibnd4j.printindices=ON clean install - Technical details:
- Adds
PRINT_INDICEScompile definition - Helps identify where array index violations occur
- Useful for tracking down segmentation faults related to memory access
- Adds
Usage Scenarios
Debugging Segmentation Faults
- Enable calltrace to get function call history:
mvn -Dlibnd4j.calltrace=ON clean install
Debugging Numerical Issues
- Enable math operation printing:
mvn -Dlibnd4j.printmath=ON clean install
Finding Array Access Violations
- Enable index printing:
mvn -Dlibnd4j.printindices=ON clean install
Combined Debugging
For comprehensive debugging, you can combine multiple flags:
mvn -Dlibnd4j.calltrace=ON -Dlibnd4j.printmath=ON -Dlibnd4j.printindices=ON clean install
Additional Notes
- These flags will impact performance significantly and should only be used for debugging
- The calltrace flag is particularly useful with tools like gdb and valgrind
- When using printmath, focus on specific functions by setting PRINT_MATH_FUNCTION_NAME
- For production builds, ensure all debug flags are turned OFF