0Pricing
CUDA Academy · Lektion

Das Enum für die Kopierrichtung

cudaMemcpyKind und seine korrekte Verwendung.

Das Enum für die Kopierrichtung ist eine kostenlose CUDA Academy-Lektion auf CoddyKit. Dies ist Lektion 3 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.

The Fourth Argument

Every cudaMemcpy ends with a direction flag of type cudaMemcpyKind. It tells the runtime which way the bytes travel. 🧭

cudaMemcpy(dst, src, bytes, kind);

Host to Device

Use cudaMemcpyHostToDevice to upload inputs from CPU RAM into GPU memory before a kernel runs.

cudaMemcpy(d_a, h_a, bytes, cudaMemcpyHostToDevice);

Device to Host

Use cudaMemcpyDeviceToHost to download results from GPU memory back into CPU RAM after computing.

cudaMemcpy(h_c, d_c, bytes, cudaMemcpyDeviceToHost);

Device to Device

To copy between two GPU buffers without touching the CPU, reach for cudaMemcpyDeviceToDevice.

cudaMemcpy(d_b, d_a, bytes, cudaMemcpyDeviceToDevice);

Host to Host

There is even cudaMemcpyHostToHost, a plain CPU copy. You rarely need it since standard memcpy already does the job.

Let the Driver Decide

With cudaMemcpyDefault, the runtime infers direction from the pointers. It needs unified addressing to work safely.

cudaMemcpy(dst, src, bytes, cudaMemcpyDefault);

The Direction Must Match

The flag must agree with your real pointers. A device pointer with a HostToHost kind triggers an error or a crash.

A Common Mix-Up

Swapping HostToDevice and DeviceToHost is a frequent bug. The compiler stays silent, so read each call carefully. 🐛

Read It Like a Sentence

The enum name spells the data flow: HostToDevice means from host to device. Match it to your source and destination.

Pair It With the Pointers

Look at which buffer is the source and which is the destination, then pick the kind that names that exact path.

When in Doubt, Be Explicit

Prefer the named direction over cudaMemcpyDefault. Being explicit makes your intent obvious and catches mistakes sooner.

Quick Check

You are copying one device buffer into another device buffer, never touching the CPU. Which kind fits?

Recap

You met every cudaMemcpyKind: HostToDevice, DeviceToHost, DeviceToDevice, HostToHost, and Default. Match the flag to your pointers every time. 🎉

Häufig gestellte Fragen

Ist die Lektion „Das Enum für die Kopierrichtung“ kostenlos?

Ja — der vollständige Text von „Das Enum für die Kopierrichtung“ 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 „Das Enum für die Kopierrichtung“?

cudaMemcpyKind und seine korrekte Verwendung. 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 3 von 4.

Wie lange dauert die Lektion „Das Enum für die Kopierrichtung“?

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. Transfers vom Host zum Device
  2. Transfers vom Device zum Host
  3. Das Enum für die Kopierrichtung
  4. Der PCIe-Transferengpass
← Zurück zu CUDA Academy