0Pricing
CUDA Academy · 강의

기본 스트림의 함정

스트림 0이 모든 작업을 직렬화하는 방식을 알아봅니다.

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

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

What Is a Stream?

A stream is an ordered queue of GPU work. Operations in the same stream run one after another, in the order you issued them. ⏳

The Default Stream

If you never name a stream, every call lands in the default stream, also called stream 0. It is where all your work has secretly been running.

Why It Is a Trap

The default stream is synchronizing: it blocks until other streams finish, and they wait for it. Nothing overlaps, so your GPU sits idle between steps.

Everything Serializes

Issue a copy, a kernel, then another copy on stream 0 and they run strictly back to back. The GPU can never start step two before step one ends.

cudaMemcpy(d_a, h_a, n, cudaMemcpyHostToDevice);
kernel<<<grid, block>>>(d_a);
cudaMemcpy(h_a, d_a, n, cudaMemcpyDeviceToHost);

Wasted Hardware

Modern GPUs have separate engines for compute and for copying. On the default stream those engines take turns instead of working together.

The Hidden Cost of Copies

Data transfers over PCIe are slow. When copies cannot overlap with compute, that transfer time is added directly onto your total runtime.

Implicit Synchronization

Many default-stream calls are blocking on the host too. cudaMemcpy returns only after the copy is done, stalling your CPU.

The Legacy Behavior

By default, work in any stream waits for stream 0, and stream 0 waits for them. This legacy rule quietly destroys concurrency you thought you had.

A Telltale Profile

In a profiler the default-stream trap shows up as a single busy lane with gaps, while copy and compute engines sit idle waiting for each other.

The Way Out

The fix is to issue independent work on separate streams. Then copies and kernels can run at the same time and fill those idle gaps.

Per-Thread Default Streams

Compiling with --default-stream per-thread gives each host thread its own default stream, easing the trap without rewriting every call.

nvcc --default-stream per-thread app.cu -o app

Quick Check

Why does putting all work on the default stream hurt performance?

Recap

The default stream serializes your GPU work and blocks overlap. To go faster, you will move independent tasks onto their own streams next. 🚀

자주 묻는 질문

“기본 스트림의 함정” 강의는 무료인가요?

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

“기본 스트림의 함정”에서 뭘 배우나요?

스트림 0이 모든 작업을 직렬화하는 방식을 알아봅니다. 브라우저에서 직접 실행하는 실습 코드로 CUDA Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

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

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

“기본 스트림의 함정” 강의는 얼마나 걸리나요?

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

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

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

이 강의의 모든 강의

  1. 기본 스트림의 함정
  2. 스트림 만들고 사용하기
  3. 시간 측정과 동기화를 위한 이벤트
  4. 복사와 계산 겹치기
← CUDA Academy(으)로 돌아가기