1.3_Administrative_Items
1.3 Administrative Items
1.3.1 OPEN SOURCE
The source code that accompanies this book is available on www.cudahandbook.com, and it is open source, copyrighted with the 2-clause BSD license.2
1.3.2 CUDA HANDBOOK LIBRARY (CHLIB)
The CUDA Handbook Library, located in the chLib/ directory of the source code, contains a portable library with support for timing, threading, driver API utilities, and more. They are described in more detail in Appendix A.
1.3.3 CODING STYLE
Arguments over brace placement aside, the main feature of the code in this book that will engender comment is the goto-based error handling mechanism. Functions that perform multiple resource allocations (or other operations that might fail, and where failure should be propagated to the caller) are structured around an Initialize / ErrorCheck / Cleanup idiom, similar to a pattern commonly used in Linux kernel code.
On failure, all cleanup is performed by the same body of code at the end of the function. It is important to initialize the resources to guaranteed-invalid values at the top of the function, so the cleanup code knows which resources must be freed. If a resource allocation or other function fails, the code performs a goto to the cleanup code. chError.h, described in Section A.6, defines error-handling macros for the CUDA runtime and the driver API that implement this idiom.
1.3.4 CUDA SDK
The SDK is a shared experience for all CUDA developers, so we assume you've installed the CUDA SDK and that you can build CUDA programs with it. The SDK also includes the GLUT (GL Utility Library), a convenient library that enables OpenGL applications to target a variety of operating systems from the same code base. GLUT is designed to build demo-quality as opposed to production-quality applications, but it fits the bill for our needs.