0Pricing
CUDA Academy · Lesson

The __global__ Function Qualifier

Marking a function as a GPU kernel.

The __global__ Function Qualifier is a free CUDA Academy lesson on CoddyKit — lesson 1 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.

Two Worlds, Two Compilers

Your CUDA file holds both CPU and GPU code. A tiny keyword tells the compiler which side a function belongs to. That keyword is the function qualifier. ⚡

Meet __global__

The __global__ qualifier marks a function as a GPU kernel: code the CPU launches but the GPU actually runs across many threads.

__global__ void myKernel() {
    // runs on the GPU
}

Called Here, Runs There

A __global__ function is the only kind the host can call but the device executes. It is the bridge between your two worlds.

Always Returns void

A kernel must return void. It cannot hand a value back to the CPU, so results travel out through memory instead.

__global__ void addOne(int* data) {
    data[0] += 1;
}

Launching Is Asynchronous

When you launch a __global__ kernel, the CPU does not wait. The call returns instantly while the GPU works in the background. 🚀

Many Threads, One Function

One __global__ definition runs on thousands of threads at once. You write the body once; the GPU clones the work across cores.

The Launch Syntax

Calling a kernel needs special triple angle brackets that set how many threads run. Normal parentheses alone will not do.

myKernel<<<1, 256>>>();

Parameters by Value

Kernel arguments are copied to the device. Pass device pointers for arrays, since a host pointer would be meaningless on the GPU.

Not the Same as __device__

Do not confuse them: __global__ is a launchable entry point, while __device__ functions are helpers callable only from GPU code.

No Recursion at the Entry

A __global__ kernel cannot call itself directly the way host functions do. Classic recursion belongs to device helper functions instead.

Why It Matters

Mastering __global__ unlocks everything ahead: every kernel you write, launch, and tune starts with this one little keyword.

Quick Check

Let us check your grasp of the __global__ qualifier.

Recap

You learned that __global__ marks a GPU kernel: called by the host, run by the device, returns void, and launched with triple angle brackets. 🎉

Frequently asked questions

Is the “The __global__ Function Qualifier” lesson free?

Yes — the full text of “The __global__ Function Qualifier” 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 “The __global__ Function Qualifier”?

Marking a function as a GPU kernel. 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 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The __global__ Function Qualifier” 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. The __global__ Function Qualifier
  2. __device__ and __host__ Functions
  3. Separate Address Spaces
  4. The Life of a CUDA Program
← Back to CUDA Academy