デバイスとのデータ転送
ホストとデバイス間のメモリ転送を管理します
「デバイスとのデータ転送」はCoddyKit上の無料Mojo Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMojo Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Mojo Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Two Separate Memories
The CPU and GPU each have their own memory. The GPU cannot read your host arrays until the data lives on the device.
Host and Device
We call the CPU side the host and the GPU side the device. Moving data between them is a core part of GPU work.
Allocating on the Device
First you reserve space on the GPU for your data. This device buffer is where inputs and outputs will live.
var d_a = ctx.enqueue_create_buffer[DType.float32](n)Copying Inputs Over
Next you copy your host arrays into those device buffers. This upload gets the GPU the numbers it needs.
ctx.enqueue_copy(d_a, h_a)Running the Kernel
With data on the device, you launch the kernel. It reads and writes the device buffers, never the host ones.
ctx.enqueue_function[kernel](grid_dim=blocks, block_dim=256)Copying Results Back
The output sits on the GPU until you fetch it. A download copies the result buffer back into host memory.
ctx.enqueue_copy(h_out, d_out)Work Is Queued, Not Instant
These calls are enqueued on the GPU, not finished at once. You must synchronize before trusting the results on the host.
ctx.synchronize()The Round Trip
The full cycle is upload, compute, download. Picture data making a round trip from host to device and back.
Transfers Cost Time
Copying over the bus is slow compared to compute. Each transfer can erase your speedup if you do it too often.
Keep Data on the Device
Chain several kernels on the same buffers before copying back. Minimizing round trips keeps the GPU win intact.
Free What You Allocate
Device memory is limited, so release buffers you no longer need. Mojo's ownership rules help free them at the right time.
Quick Check
You want a GPU program to actually run faster end to end.
Recap
Upload inputs to the device, run the kernel, then download results and synchronize, while keeping costly transfers to a minimum. 🔁
よくある質問
「デバイスとのデータ転送」レッスンは無料ですか?
はい。「デバイスとのデータ転送」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Mojo Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Mojo Academyコースには全4レッスンが含まれています。
「デバイスとのデータ転送」で何を学びますか?
ホストとデバイス間のメモリ転送を管理します ブラウザで直接実行するハンズオンコードでMojo Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Mojo Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのMojo Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「デバイスとのデータ転送」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このMojo Academyレッスンでコードを書いて実行できますか?
はい。すべてのMojo Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- AIワークロードにGPUを使う理由
- スレッド、ブロック、グリッド
- GPUカーネル関数の記述
- デバイスとのデータ転送