Der Funktionsqualifizierer __global__
Kennzeichnen Sie eine Funktion als GPU-Kernel.
Der Funktionsqualifizierer __global__ ist eine kostenlose CUDA Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des CUDA Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der CUDA Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. 🎉
Häufig gestellte Fragen
Ist die Lektion „Der Funktionsqualifizierer __global__“ kostenlos?
Ja — der vollständige Text von „Der Funktionsqualifizierer __global__“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des CUDA Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der CUDA Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Der Funktionsqualifizierer __global__“?
Kennzeichnen Sie eine Funktion als GPU-Kernel. Du übst CUDA Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um CUDA Academy zu starten?
Keine Vorkenntnisse erforderlich. CUDA Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Der Funktionsqualifizierer __global__“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser CUDA Academy-Lektion Code schreiben und ausführen?
Ja. Jede CUDA Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Der Funktionsqualifizierer __global__
- __device__- und __host__-Funktionen
- Getrennte Adressräume
- Der Lebenszyklus eines CUDA-Programms