Aussie AI
Code Reliability
-
Book Excerpt from "Generative AI in C++"
-
by David Spuler, Ph.D.
Code Reliability
Code reliability means that the execution is predictable and produces the desired results. The reality is that an AI engine is some of the most difficult code you'll ever see. Parallelized code of any kind (e.g. low-level hardware acceleration, multi-threaded, multi-GPU, etc.) multiplies this complexity by another order of magnitude. Hence, starting with the basics of high quality coding practices are ever more important for code reliability, such as:
- Unit tests
- Assertions
- Self-testing code
- Debug tracing methods
- Automated system tests
- Function argument validation
- Error detection (e.g. starting with checking error return codes)
- Exception handling (wrapping code in a full exception handling stack)
- Resilience and failure tolerance
- Regression testing
- Test automation
- Test coverage measurement
One useful method of catching program failures is making the program apply checks to itself. Assertions and other self-testing code have the major advantage that they will catch such errors early, rather than letting the program continue, and cause a failure much later.
All of these techniques involve a significant chunk of extra coding work. Theory says that full exception handling can be 80% of a finalized software product, so it's a four-fold amount of extra work! Maybe that estimate is a little outdated, given improvements in modern tech stacks, but it still contains many grains of truth.
There are many programming tools to help improve code reliability throughout the development, testing and debugging cycle:
- C++ memory debugging tools (e.g. Valgrind on Linux)
- Performance profiling tools (for “de-slugging”)
- Memory usage tracking (ie. memory leaks and allocated memory measurement)
- Interactive debugging tools (eg. debuggers in the IDE, Gnu
gdb
, etc.) - Static analysis tools (“linters”)
- Bug tracking databases (for cussing at each other)
• Next: • Up: Table of Contents |
The new AI programming book by Aussie AI co-founders:
Get your copy from Amazon: Generative AI in C++ |