0Pricing
CUDA Academy · Lesson

Hello GPU: Your First .cu File

Build and run a minimal CUDA program.

Hello GPU: Your First .cu File is a free CUDA Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CUDA Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Your First .cu File

Time to build something real. A CUDA program lives in a .cu file, which can hold both CPU and GPU code side by side. 🎉

Include the Header

Most CUDA samples start by pulling in standard headers. The CUDA runtime header is included automatically by nvcc, so iostream is often enough.

#include <cstdio>

Marking a Kernel

A function that runs on the GPU is a kernel. You mark it with the __global__ qualifier so nvcc compiles it for the device.

__global__ void hello() {
}

Printing from the GPU

Inside the kernel you can call printf just like on the CPU. Each GPU thread that runs it produces its own line of output.

__global__ void hello() {
  printf("Hello from GPU\n");
}

The Launch Syntax

To run a kernel you use the triple-angle-bracket launch. The numbers inside choose how many blocks and threads will execute it.

hello<<<1, 1>>>();

Launches Are Asynchronous

A kernel launch returns immediately while the GPU works in the background. The CPU keeps going, which is powerful but can be surprising at first.

Waiting for the GPU

Because of that, you must synchronize before the program ends, or the printf output may never appear on screen.

cudaDeviceSynchronize();

Putting It Together

Your main function launches the kernel and then waits. That is the entire skeleton of a working CUDA program.

int main() {
  hello<<<1, 1>>>();
  cudaDeviceSynchronize();
}

Compile It

Save the file as hello.cu and build it with nvcc, naming the output program with the -o flag.

nvcc hello.cu -o hello

Run It

Now run the program. Seeing Hello from GPU printed means your code truly executed on the device. That is your first GPU output! 🚀

./hello

Many Threads at Once

Bump the launch to many threads and you will see the greeting printed several times, one line per thread. That is real parallelism in action.

hello<<<1, 8>>>();

Quick Check

One detail makes or breaks this program.

Recap

You wrote a real CUDA program: a __global__ kernel, a triple-bracket launch, and a sync. Compile with nvcc, run it, and the GPU greets you. Congrats! 🎓

Frequently asked questions

Is the “Hello GPU: Your First .cu File” lesson free?

Yes — the full text of “Hello GPU: Your First .cu File” is free to read here on the web, and the CUDA Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CUDA Academy course, upgrade to CoddyKit PRO.

What will I learn in “Hello GPU: Your First .cu File”?

Build and run a minimal CUDA program. You practise CUDA Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CUDA Academy?

No prior experience is required. CUDA Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Hello GPU: Your First .cu File” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CUDA Academy lesson?

Yes. Every CUDA Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Driver, Runtime, and Toolkit Versions
  2. Reading nvidia-smi Like a Pro
  3. Compiling with nvcc
  4. Hello GPU: Your First .cu File
← Back to CUDA Academy