![]() |
VOOZH | about |
A CUDA program is "heterogeneous," meaning it consists of code that runs on two different systems at once: the Host (CPU) and the Device (NVIDIA GPU). CUDA programming model is an extension of the C++ language, adding specialized syntax to manage parallel execution. To coordinate these systems, a standard .cu file follows a specific structural template.
For headers, we can add standard C++ headers like <stdio.h> for basic input/output or <math.h> for complex mathematical calculations. For more granular control of the GPU hardware, we use:
#include <cuda.h>
Explanation: cuda.h header provides access to the CUDA Driver API for low-level device management.
The Kernel is a special function designed to run on the GPU. It contains the logic that will be executed in parallel across many threads.
Explanation:
The main() function is the entry point of the program that runs on the CPU. It handles the logical flow, manages memory and tells the GPU when to start working.
Explanation:
This basic "Hello World" example demonstrates the interaction between the CPU and the GPU by launching a single thread to print a message.
Output
Hello world
Explanation: