0Pricing
CUDA Academy · Lesson

Return Codes vs Async Errors

Why kernels fail silently by default.

Return Codes vs Async Errors 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 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. 🎉

Frequently asked questions

Is the “Return Codes vs Async Errors” lesson free?

Yes — the full text of “Return Codes vs Async Errors” 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 “Return Codes vs Async Errors”?

Why kernels fail silently by default. 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 “Return Codes vs Async Errors” 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. Return Codes vs Async Errors
  2. cudaGetLastError After Launch
  3. A Reusable CUDA_CHECK Macro
  4. Decoding cudaGetErrorString
← Back to CUDA Academy