0Pricing
CUDA Academy · 강의

여러 블록의 최종 축소

블록별 부분 합을 결합합니다.

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

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

Blocks Cannot Talk

A reduction within a block is easy, but blocks run independently and cannot synchronize with each other mid-kernel. So one launch cannot sum everything.

Each Block Produces a Partial

So every block reduces its own chunk to one number, a partial sum, and writes it to a small output array indexed by blockIdx.

if (tid == 0)
  out[blockIdx.x] = data[0];

Now You Have Fewer Values

With 1000 blocks you go from a million inputs to 1000 partials. The hard part is done; only a tiny array remains to combine.

Strategy One: Launch Again

The simplest finish is a second launch of the same kernel on the partials. Repeat until only one value is left.

Recursive Until One

Each pass shrinks the array by the block size. A few recursive launches reduce millions down to a single final sum.

Strategy Two: Atomics

Alternatively, thread 0 of each block can add its partial straight into one global total with atomicAdd, avoiding a second kernel.

if (tid == 0)
  atomicAdd(total, data[0]);

Atomics Trade Off

Atomics are simple and need only one launch, but many blocks contending on the same address can serialize. With few partials it is usually fine.

Strategy Three: Grid-Stride

A grid-stride loop lets each thread first sum many elements into a register, so far fewer blocks are needed before the final step.

for (int i = gid; i < n; i += gridDim.x * blockDim.x)
  sum += in[i];

Fewer Blocks, Less Overhead

Doing more work per thread up front means fewer partials and fewer launches. This often beats spawning one thread per element.

Zero the Total First

If you use atomics, remember to zero the global total before launching, or your sum starts from garbage left in that memory.

Pick by Problem Size

Small inputs love atomics for their simplicity; huge inputs favor a two-pass or grid-stride design. Measure on your data to choose.

Quick Check

Think about why a single kernel launch cannot sum the whole array directly.

Recap

Blocks each emit a partial sum, then you combine them with a second launch, atomics, or grid-stride. You can now reduce arrays of any size. 🏁

자주 묻는 질문

“여러 블록의 최종 축소” 강의는 무료인가요?

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

“여러 블록의 최종 축소”에서 뭘 배우나요?

블록별 부분 합을 결합합니다. 브라우저에서 직접 실행하는 실습 코드로 CUDA Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

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

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

“여러 블록의 최종 축소” 강의는 얼마나 걸리나요?

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

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

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

이 강의의 모든 강의

  1. 축소 트리 개념
  2. 워프 분기 없애기
  3. 순차 주소 지정
  4. 여러 블록의 최종 축소
← CUDA Academy(으)로 돌아가기