0Pricing
CUDA Academy · レッスン

GPUメモリへのポインター

デバイスポインターをホスト変数に保持します。

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

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

A Pointer That Lives on the CPU

cudaMalloc hands you a normal C++ pointer variable. It sits in host memory, but the address inside it points into GPU memory. 🔗

The Address Means the Device

A device pointer holds a number that is only valid in the GPU's address space. To the CPU it is just an integer, not real RAM.

float* d_data;  // host variable, device address

The d_ Naming Habit

Programmers prefix device pointers with d_ and host pointers with h_. The name alone reminds you which side each one belongs to.

float* h_data;
float* d_data;

Do Not Dereference on the Host

Writing *d_data in CPU code is a trap. The host cannot touch GPU memory directly, so this crashes or reads nonsense.

Kernels Dereference It Freely

Inside a kernel the same device pointer is perfectly valid. There, d_data[i] reads and writes real GPU memory as you expect.

__global__ void k(float* d) {
    d[0] = 1.0f;
}

Pass It Into the Kernel

You hand the device pointer to a kernel as an argument. The GPU then uses that address to find your data.

myKernel<<<grid, block>>>(d_data);

Two Pointers, Two Spaces

Keep host and device pointers strictly apart. A host pointer is meaningless on the GPU, and a device pointer is meaningless on the CPU.

cudaMemcpy Bridges the Gap

To get data between the two, you copy it. cudaMemcpy takes both pointers and moves bytes across the divide for you.

Pointer Arithmetic Still Works

You may offset a device pointer on the host, like d_data + n, to point at a slice. You just must not read through it there.

float* d_tail = d_data + 100;

Mixing Them Up Is Subtle

The compiler will not stop you from confusing the two. Many CUDA bugs are simply a host pointer handed where a device pointer belonged.

Discipline Beats Debugging

Clear naming and a fixed convention save hours. Decide your d_ and h_ scheme early and never break it. 🧹

Quick Check

Let us test where a device pointer can safely be dereferenced.

Recap

You learned a device pointer lives in a host variable but addresses GPU memory: usable inside kernels, off-limits to direct host access. 🎉

よくある質問

「GPUメモリへのポインター」レッスンは無料ですか?

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

「GPUメモリへのポインター」で何を学びますか?

デバイスポインターをホスト変数に保持します。 ブラウザで直接実行するハンズオンコードでCUDA Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「GPUメモリへのポインター」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. cudaMallocとcudaFree
  2. GPUメモリへのポインター
  3. 初期化にcudaMemsetを使う
  4. メモリリークと二重解放を防ぐ
← CUDA Academyに戻る