0Pricing
CUDA Academy · Lesson

Pointers to GPU Memory

Device pointers live in host variables.

Pointers to GPU Memory is a free CUDA Academy lesson on CoddyKit — lesson 2 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.

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

Frequently asked questions

Is the “Pointers to GPU Memory” lesson free?

Yes — the full text of “Pointers to GPU Memory” 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 “Pointers to GPU Memory”?

Device pointers live in host variables. 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 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Pointers to GPU Memory” 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. cudaMalloc and cudaFree
  2. Pointers to GPU Memory
  3. cudaMemset for Initialization
  4. Avoiding Leaks and Double-Frees
← Back to CUDA Academy