Pré-busca com cudaMemPrefetchAsync
Mova as páginas antes que sejam necessárias.
Pré-busca com cudaMemPrefetchAsync é uma aula grátis de CUDA Academy no CoddyKit. Esta é a aula 3 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.
Stop Paying for Faults
Instead of waiting for slow first-touch faults, you can move pages early. cudaMemPrefetchAsync sends managed data to a device before the kernel needs it.
The Basic Call
You name the pointer, the byte count, and the destination device. This one prefetch migrates the whole range up front in a single efficient move.
cudaMemPrefetchAsync(data, n * sizeof(float), 0);Pick the Destination
The third argument is the device id. Pass a GPU number to stage data on that GPU, ready for the kernel you are about to launch.
int dev = 0;
cudaMemPrefetchAsync(data, bytes, dev);Prefetch Back to the CPU
Use the special id cudaCpuDeviceId to pull results back to the host. Do it before CPU code reads them to avoid a wave of faults.
cudaMemPrefetchAsync(data, bytes, cudaCpuDeviceId);It Is Asynchronous
The Async in the name is real: the call returns immediately and runs in a stream. Your CPU keeps working while pages migrate in the background.
Overlap With Compute
Because it rides a stream, a prefetch can overlap with other kernels. Stage the next chunk while the current one is still being processed.
cudaMemPrefetchAsync(next, bytes, dev, stream);One Move Beats Many Faults
A single bulk prefetch is far cheaper than thousands of tiny faults. You trade scattered overhead for one contiguous high-bandwidth transfer.
Prefetch the Right Range
Only stage what the kernel actually touches. Prefetching a huge buffer the kernel barely reads just wastes bandwidth and GPU memory.
A Two-Sided Pattern
A clean rhythm emerges: prefetch to the GPU, launch the kernel, prefetch results back. This keeps migration off the critical path on both ends.
Measure, Do Not Guess
Add a prefetch, then check Nsight for fewer faults and tighter timelines. Let profiling confirm the win rather than trusting intuition.
Convenience Plus Control
Prefetching keeps the single-pointer ease of managed memory while giving you back control over timing. You get the best of both styles.
Quick Check
Let us confirm what prefetching buys you.
Recap: Prefetching
You learned to stage pages early with cudaMemPrefetchAsync, picking a GPU or cudaCpuDeviceId. It overlaps in streams and beats faulting. Great job! ✨
Perguntas Frequentes
A aula “Pré-busca com cudaMemPrefetchAsync” é grátis?
Sim — o texto completo de “Pré-busca com cudaMemPrefetchAsync” é 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 “Pré-busca com cudaMemPrefetchAsync”?
Mova as páginas antes que sejam necessárias. 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 3 de 4.
Quanto tempo leva a aula “Pré-busca com cudaMemPrefetchAsync”?
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
- Um ponteiro, os dois lados
- Migração de páginas sob demanda
- Pré-busca com cudaMemPrefetchAsync
- Dicas por meio de cudaMemAdvise