0Pricing
CUDA Academy · Aula

cudaMemcpyAsync em um fluxo

Transferências não bloqueantes que se sobrepõem.

cudaMemcpyAsync em um fluxo é 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.

Blocking by Default

Plain cudaMemcpy stops your CPU until the copy finishes. Your host thread just waits, doing nothing useful while bytes move.

The Async Cousin

Meet cudaMemcpyAsync. It queues the copy and returns to your CPU immediately, so the host can keep working while the transfer happens.

It Needs a Stream

The async copy takes an extra argument: a stream. The stream is the ordered queue where the transfer waits its turn to run.

cudaMemcpyAsync(d_data, h_data, bytes, cudaMemcpyHostToDevice, stream);

Pinned or Bust

Here is the catch: async copies only run truly non-blocking from pinned host memory. Pass a pageable buffer and CUDA silently falls back to a blocking copy.

Returns, Does Not Finish

When the call returns, the copy has only been scheduled, not completed. The data may still be in flight, so do not read it yet.

Order Within a Stream

Work in one stream runs in order, one item after another. So a copy issued before a kernel in the same stream is guaranteed to finish first.

Wait When You Must

Before touching the results on the CPU, make sure the queue drained. Call cudaStreamSynchronize to block until that stream's work is done.

cudaStreamSynchronize(stream);

The Whole Point: Overlap

Async copies let a transfer in one stream run while a kernel in another stream computes. That concurrency is how you hide transfer time.

Beware the Default Stream

If you pass stream 0, the legacy default, it can serialize against everything else. Use your own created streams to actually get overlap.

Keep the Buffer Alive

Since the copy finishes later, the host buffer must stay valid until then. Free it too early and the in-flight transfer reads garbage.

A Typical Pattern

The classic flow is async copy in, launch the kernel, then async copy out, all in one stream. Sync only at the very end.

cudaMemcpyAsync(d_in, h_in, bytes, cudaMemcpyHostToDevice, stream);
kernel<<<grid, block, 0, stream>>>(d_in, d_out);

Quick Check

What does cudaMemcpyAsync require to be genuinely non-blocking?

Recap

cudaMemcpyAsync queues a copy in a stream and returns at once, but needs pinned memory to overlap. Sync the stream before reading results. ⚡

Perguntas Frequentes

A aula “cudaMemcpyAsync em um fluxo” é grátis?

Sim — o texto completo de “cudaMemcpyAsync em um fluxo” é 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 “cudaMemcpyAsync em um fluxo”?

Transferências não bloqueantes que se sobrepõem. 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 “cudaMemcpyAsync em um fluxo”?

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

  1. Por que a memória paginável é lenta
  2. Memória fixada com cudaMallocHost
  3. cudaMemcpyAsync em um fluxo
  4. O pipeline de buffers duplos
← Voltar para CUDA Academy