Projetando o pipeline de processamento
Estágios, buffers e fluxo de dados.
Projetando o pipeline de processamento é uma aula grátis de CUDA Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de CUDA Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de CUDA Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Think in Stages
A real image pipeline is a chain of stages: load, blur, sharpen, color-correct, save. Each stage is one clear transformation you can reason about alone. 🧩
Data Flows One Way
Pixels move forward through the pipeline: each stage reads the previous output and produces the next input. This one-way data flow keeps the design simple to follow.
Buffers Hold the In-Between
Between two stages you need a place to park pixels. A buffer is just a device array that one kernel writes and the next kernel reads. Plan a buffer per boundary.
float* d_stage1;
cudaMalloc(&d_stage1, width * height * sizeof(float));Ping-Pong Two Buffers
You rarely need a fresh buffer per stage. Ping-pong between two buffers: read from one, write to the other, then swap. Two buffers serve a whole chain.
std::swap(d_in, d_out);One Kernel Per Stage, For Now
Start with one kernel per stage. It is the clearest design and the easiest to verify. You will fuse stages later once each one is correct.
Map Pixels to Threads
The natural mapping is one thread per pixel. A 2D grid covers width and height, so each thread owns exactly one (x, y) location to process.
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;Index With Row Pitch
Images are stored row by row. Turn (x, y) into a flat offset with row-major indexing so every thread reads the right pixel.
int idx = y * width + x;Guard the Image Borders
Your grid is rounded up, so some threads fall outside the image. A simple bounds check keeps them from touching memory they should not.
if (x >= width || y >= height) return;Choose a 2D Block Shape
A block like 16x16 or 32x8 gives good coverage and warp-friendly rows. Pick a 2D block shape that divides the image cleanly when you can.
dim3 block(16, 16);
dim3 grid((width+15)/16, (height+15)/16);Allocate Once, Reuse Often
Allocating device memory is costly, so do it once before the loop. Reuse the same buffers for every frame instead of malloc and free each time.
Sketch Before You Code
Draw the stages, their buffers, and the arrows between them first. A clear diagram of data flow catches design mistakes long before any kernel runs. ✏️
Quick Check
You have a chain of stages. How do you avoid allocating a new buffer for every stage?
Recap
You designed a pipeline as one-way stages joined by buffers, mapped one thread per pixel with a 2D grid, and learned to ping-pong buffers and sketch the flow first. 🎯
Perguntas Frequentes
A aula “Projetando o pipeline de processamento” é grátis?
Sim — o texto completo de “Projetando o pipeline de processamento” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de CUDA Academy, atualize para CoddyKit PRO. O curso de CUDA Academy inclui 4 aulas no total.
O que vou aprender em “Projetando o pipeline de processamento”?
Estágios, buffers e fluxo de dados. Você pratica CUDA Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar CUDA Academy?
Nenhuma experiência prévia é necessária. CUDA Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.
Quanto tempo leva a aula “Projetando o pipeline de processamento”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de CUDA Academy?
Sim. Cada aula de CUDA Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Projetando o pipeline de processamento
- Fundindo filtros em um único kernel
- Transmitindo blocos para imagens grandes
- Perfilar, otimizar, entregar