0Pricing
CUDA Academy · Aula

O qualificador de função __global__

Marque uma função como um núcleo da GPU.

O qualificador de função __global__ é 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.

Two Worlds, Two Compilers

Your CUDA file holds both CPU and GPU code. A tiny keyword tells the compiler which side a function belongs to. That keyword is the function qualifier. ⚡

Meet __global__

The __global__ qualifier marks a function as a GPU kernel: code the CPU launches but the GPU actually runs across many threads.

__global__ void myKernel() {
    // runs on the GPU
}

Called Here, Runs There

A __global__ function is the only kind the host can call but the device executes. It is the bridge between your two worlds.

Always Returns void

A kernel must return void. It cannot hand a value back to the CPU, so results travel out through memory instead.

__global__ void addOne(int* data) {
    data[0] += 1;
}

Launching Is Asynchronous

When you launch a __global__ kernel, the CPU does not wait. The call returns instantly while the GPU works in the background. 🚀

Many Threads, One Function

One __global__ definition runs on thousands of threads at once. You write the body once; the GPU clones the work across cores.

The Launch Syntax

Calling a kernel needs special triple angle brackets that set how many threads run. Normal parentheses alone will not do.

myKernel<<<1, 256>>>();

Parameters by Value

Kernel arguments are copied to the device. Pass device pointers for arrays, since a host pointer would be meaningless on the GPU.

Not the Same as __device__

Do not confuse them: __global__ is a launchable entry point, while __device__ functions are helpers callable only from GPU code.

No Recursion at the Entry

A __global__ kernel cannot call itself directly the way host functions do. Classic recursion belongs to device helper functions instead.

Why It Matters

Mastering __global__ unlocks everything ahead: every kernel you write, launch, and tune starts with this one little keyword.

Quick Check

Let us check your grasp of the __global__ qualifier.

Recap

You learned that __global__ marks a GPU kernel: called by the host, run by the device, returns void, and launched with triple angle brackets. 🎉

Perguntas Frequentes

A aula “O qualificador de função __global__” é grátis?

Sim — o texto completo de “O qualificador de função __global__” é 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 “O qualificador de função __global__”?

Marque uma função como um núcleo da GPU. 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 “O qualificador de função __global__”?

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. O qualificador de função __global__
  2. Funções __device__ e __host__
  3. Espaços de endereçamento separados
  4. O ciclo de vida de um programa CUDA
← Voltar para CUDA Academy