appendix-b
appendix B Running the code examples
All code examples live in the public book.cu repository, organized by chapter. Clone it once, and the per-chapter commands that follow will run from inside that directory:
git clone https://github.com/infatoshi/book.cu cd book.cu
Each chapter directory is self-contained with build scripts and README files.
B.1 Chapter 2: Vector addition (0_vecadd/)
What you’ll learn: Basic CUDA kernel launches, memory management, and thread-indexing patterns.
Build and run the following:
cd book.cu/0_vecadd # Using Makefile (recommended) make all make run # Or compile individually nvcc vecadd.cu -o vecadd ./vecadd nvcc vecadd_scalable.cu -o vecadd_scalable ./vecadd_scalable nvcc tensor_add_3d.cu -o tensor_add_3d ./tensor_add_3d
Expected output:
Vector addition successful! All 8 elements match.
Learning path:
- Start with
vecadd.cu, the simplest CUDA program (eight elements, eight threads). - Move to
vecadd_scalable.cuto handle large arrays (1 million elements). - Explore
tensor_add_3d.cufor multidimensional indexing in deep learning.
B.2 Chapter 3: Naive neural network operations (1_naive/)
What you’ll learn: CPU-first development, fundamental neural network operations, correctness verification.
Build and run the following:
cd book.cu/1_naive # Build all examples make all # Run all with verification make run # Or build/run individual operations make vector_add ./vector_add make gemm ./gemm make softmax ./softmax make conv2d ./conv2d
Expected output: