0Pricing
CUDA Academy · レッスン

コピー方向の列挙型

cudaMemcpyKindを正しく指定します。

「コピー方向の列挙型」はCoddyKit上の無料CUDA Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはCUDA Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 CUDA Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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. 🎉

よくある質問

「コピー方向の列挙型」レッスンは無料ですか?

はい。「コピー方向の列挙型」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、CUDA Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 CUDA Academyコースには全4レッスンが含まれています。

「コピー方向の列挙型」で何を学びますか?

cudaMemcpyKindを正しく指定します。 ブラウザで直接実行するハンズオンコードでCUDA Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

CUDA Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのCUDA Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「コピー方向の列挙型」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このCUDA Academyレッスンでコードを書いて実行できますか?

はい。すべてのCUDA Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ホストからデバイスへの転送
  2. デバイスからホストへの転送
  3. コピー方向の列挙型
  4. PCIe転送のボトルネック
← CUDA Academyに戻る