0Pricing
CUDA Academy · レッスン

__global__関数修飾子

関数をGPUカーネルとして指定します。

「__global__関数修飾子」はCoddyKit上の無料CUDA Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはCUDA Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 CUDA Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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. 🎉

よくある質問

「__global__関数修飾子」レッスンは無料ですか?

はい。「__global__関数修飾子」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、CUDA Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 CUDA Academyコースには全4レッスンが含まれています。

「__global__関数修飾子」で何を学びますか?

関数をGPUカーネルとして指定します。 ブラウザで直接実行するハンズオンコードでCUDA Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

CUDA Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのCUDA Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「__global__関数修飾子」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このCUDA Academyレッスンでコードを書いて実行できますか?

はい。すべてのCUDA Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. __global__関数修飾子
  2. __device__関数と__host__関数
  3. アドレス空間を分離する
  4. CUDAプログラムのライフサイクル
← CUDA Academyに戻る