Иерархия потоков
Потоки объединяются в блоки, а блоки — в сетку.
«Иерархия потоков» — бесплатный урок CUDA Academy на CoddyKit. Это урок 1 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения CUDA Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс CUDA Academy содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
Many Threads, One Job
A CUDA kernel runs in parallel across many threads, and each thread does the same work on its own slice of the data. 🧵
Threads Need Structure
Launching millions of loose threads would be chaos. CUDA organizes them into a clean hierarchy so the hardware can schedule them well.
Threads Form Blocks
Threads are grouped into a block. Every thread in a block runs the same kernel and can cooperate closely with its neighbors.
Blocks Form the Grid
All the blocks for one launch together make up the grid. So the chain is simple: threads live in blocks, and blocks live in the grid.
Why Two Levels?
The two-level design lets one kernel scale from a tiny GPU to a huge one. You describe the work once and the grid stretches to fit.
Picking the Shape at Launch
You choose how many blocks and how many threads per block right at the launch, using the triple-angle-bracket syntax.
myKernel<<<numBlocks, threadsPerBlock>>>(data);A Concrete Example
Say you launch 4 blocks of 256 threads. That gives you 4 times 256, or 1024 threads all running at once.
Blocks Are Independent
Different blocks cannot assume any order or talk to each other directly. This independence is exactly what lets the GPU run them in any sequence.
Threads Within a Block Cooperate
Inside one block, threads can share fast on-chip memory and synchronize with each other. That teamwork is a block's superpower.
Grids and Blocks Can Be 3D
Both the grid and each block can be 1D, 2D, or 3D. The dim3 type lets you map naturally onto images or volumes.
dim3 block(16, 16);
dim3 grid(32, 32);One Thread, One Element
The common goal is to give each thread exactly one data element to handle. The hierarchy is just how you reach that mapping.
Quick Check
Let us check how the pieces nest together.
Recap: The Hierarchy
You learned the CUDA ladder: threads make a block, blocks make the grid. Independent blocks scale, while threads inside a block cooperate. 🎯
Часто задаваемые вопросы
Урок «Иерархия потоков» бесплатный?
Да — полный текст урока «Иерархия потоков» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс CUDA Academy, подпишись на CoddyKit PRO. Курс CUDA Academy содержит 4 уроков всего.
Чему я научусь в уроке «Иерархия потоков»?
Потоки объединяются в блоки, а блоки — в сетку. Ты практикуешь CUDA Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать CUDA Academy?
Предыдущий опыт не требуется. CUDA Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 1 из 4.
Сколько времени занимает урок «Иерархия потоков»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке CUDA Academy?
Да. Каждый урок CUDA Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.