0Pricing
CUDA Academy · 강의

분리된 주소 공간

호스트 포인터가 장치에서 유효하지 않은 이유를 알아봅니다.

분리된 주소 공간은(는) CoddyKit의 무료 CUDA Academy 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 CUDA Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. CUDA Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

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

자주 묻는 질문

“분리된 주소 공간” 강의는 무료인가요?

네 — “분리된 주소 공간” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 CUDA Academy 강의 전체를 잠금 해제할 수 있습니다. CUDA Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“분리된 주소 공간”에서 뭘 배우나요?

호스트 포인터가 장치에서 유효하지 않은 이유를 알아봅니다. 브라우저에서 직접 실행하는 실습 코드로 CUDA Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

CUDA Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 CUDA Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“분리된 주소 공간” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 CUDA Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 CUDA Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. __global__ 함수 지정자
  2. __device__와 __host__ 함수
  3. 분리된 주소 공간
  4. CUDA 프로그램의 생애
← CUDA Academy(으)로 돌아가기