Puzzle 4: 2D Map
Overview
Implement a kernel that adds 10 to each position of 2D square matrix a
and stores it in 2D square matrix out
.
Note: You have more threads than positions.
Key concepts
- 2D thread indexing
- Matrix operations on GPU
- Handling excess threads
- Memory layout patterns
For each position \((i,j)\): \[\Large out[i,j] = a[i,j] + 10\]
Implementation approaches
🔰 Raw memory approach
Learn how 2D indexing works with manual memory management.
📚 Learn about LayoutTensor
Discover a powerful abstraction that simplifies multi-dimensional array operations and memory management on GPU.
🚀 Modern 2D operations
Put LayoutTensor into practice with natural 2D indexing and automatic bounds checking.
💡 Note: From this puzzle onward, we’ll primarily use LayoutTensor for cleaner, safer GPU code.