Separate Address Spaces
Why a host pointer is invalid on the device.
Separate Address Spaces is a free CUDA Academy lesson on CoddyKit — lesson 3 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.
Two Separate Memories
The CPU and GPU each own their own RAM. They do not share one address space, and that single fact shapes all of CUDA. 🧠
What an Address Means
A pointer is just a number naming a slot in memory. That slot only makes sense in the address space where it was created.
Host Pointers Are Local
A pointer from malloc names host memory. The GPU has no such slot, so handing it to a kernel points nowhere valid.
int* h = (int*)malloc(n * sizeof(int));Device Pointers Are Local Too
A pointer from cudaMalloc names device memory. The CPU cannot read it directly; dereferencing it on the host crashes.
int* d;
cudaMalloc(&d, n * sizeof(int));The Classic Mistake
Passing a host pointer into a kernel compiles fine but fails at runtime. The number is valid; the memory it names is not on the GPU.
Why It Compiles Anyway
Both pointers look like the same type to C++, so the compiler stays silent. The mismatch only bites when the GPU touches the address.
Bridging with cudaMemcpy
To move data between spaces you must copy it explicitly with cudaMemcpy. There is no automatic sharing across the divide.
cudaMemcpy(d, h, bytes, cudaMemcpyHostToDevice);A Naming Convention Helps
Many programmers prefix host pointers with h_ and device pointers with d_. It is a habit that prevents painful mix-ups.
float *h_a, *d_a;Kernels See Device Space
Inside a kernel every pointer you dereference must live in device memory. That is the only space the GPU threads can reach.
Unified Memory Hint
Later you will meet unified memory, one pointer valid on both sides. For now, keep host and device pointers strictly apart.
The Mental Model
Picture two rooms with no shared shelves. To use data in the other room you must carry a copy over, never just point across.
Quick Check
Let us confirm you understand separate address spaces.
Recap
You learned host and device live in separate address spaces, pointers are not interchangeable, and cudaMemcpy is how data crosses the gap. ✅
Frequently asked questions
Is the “Separate Address Spaces” lesson free?
Yes — the full text of “Separate Address Spaces” 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 “Separate Address Spaces”?
Why a host pointer is invalid on the device. 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 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Separate Address Spaces” 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
- The __global__ Function Qualifier
- __device__ and __host__ Functions
- Separate Address Spaces
- The Life of a CUDA Program