0Pricing
CUDA Academy · Lektion

Rückgabecodes vs. asynchrone Fehler

Warum Kernel standardmäßig still fehlschlagen.

Rückgabecodes vs. asynchrone Fehler 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 Ways CUDA Fails

CUDA reports trouble in two flavors: an immediate return code from API calls, and delayed async errors from kernels. Knowing both is key. 🧭

API Calls Return a Code

Most CUDA runtime calls hand back a cudaError_t. A value of cudaSuccess means all good; anything else signals a problem you can act on.

cudaError_t err = cudaMalloc(&d, n);

Check It Right Away

For synchronous calls like cudaMalloc, the returned code is final. Compare it to cudaSuccess immediately and react before moving on.

if (err != cudaSuccess) return 1;

Kernels Return Nothing

A kernel launch with triple brackets has no return value you can test. So launch failures cannot be reported the same easy way.

myKernel<<<g, b>>>(d); // no code to check

Why Kernels Are Async

Launches are asynchronous: the CPU queues the work and races ahead. The GPU may not have even started when your next line runs.

Errors Arrive Late

Because work runs later, a kernel crash becomes an async error. It surfaces on a future call, not at the launch line itself.

Silent by Default

If you never check, a broken kernel fails silently. Your program seems to run while producing garbage or zeros in the output.

Two Kinds of Launch Errors

Launches can fail in two stages: a bad configuration caught at launch, and a runtime fault like out-of-bounds caught while executing.

Sticky Errors

A serious fault leaves the context in a sticky error state. Every later CUDA call then returns the same error until you restart.

Sync to Force Async Errors

To pull a hidden fault into the open, call cudaDeviceSynchronize. It waits for the kernel and returns any runtime error it hit.

cudaError_t e = cudaDeviceSynchronize();

A Reliable Habit

The rule of thumb: check the return code of every API call, and sync to catch kernels. Together they leave no failure unseen.

Quick Check

Test your grasp of how kernels report failure.

Recap: Two Error Paths

API calls give an instant return code, while kernels fail asynchronously. Check codes and synchronize so nothing slips by unnoticed. 🎉

Häufig gestellte Fragen

Ist die Lektion „Rückgabecodes vs. asynchrone Fehler“ kostenlos?

Ja — der vollständige Text von „Rückgabecodes vs. asynchrone Fehler“ 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 „Rückgabecodes vs. asynchrone Fehler“?

Warum Kernel standardmäßig still fehlschlagen. 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 „Rückgabecodes vs. asynchrone Fehler“?

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

  1. Rückgabecodes vs. asynchrone Fehler
  2. cudaGetLastError nach dem Start
  3. Ein wiederverwendbares CUDA_CHECK-Makro
  4. cudaGetErrorString entschlüsseln
← Zurück zu CUDA Academy