0Pricing
CUDA Academy · 강의

커널의 구조

시그니처, 반환 자료형과 void 규칙을 알아봅니다.

커널의 구조은(는) CoddyKit의 무료 CUDA Academy 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 CUDA Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. CUDA Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What a Kernel Is

A kernel is a single C++ function that runs on the GPU, executed at once by thousands of threads. You write it once, the hardware fans it out. 🚀

The __global__ Marker

You mark a kernel with the __global__ qualifier. It tells nvcc this function is called from the CPU but actually runs on the device.

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

Kernels Return void

Every kernel must return void. There is no return value to hand back, so results travel out through pointers to device memory instead.

__global__ void k() { /* void only */ }

Why Not Return a Value?

Thousands of threads run your kernel together, so a single return value would make no sense. Each thread writes its own slot of an output array.

Parameters Are by Value

Kernel parameters are copied to every thread, so pass small things: ints, sizes, and pointers. Never pass big objects by value.

__global__ void add(float* out, float* a, int n) {}

Pass Pointers, Not Arrays

To give a kernel an array, you pass a device pointer. The kernel reads and writes the GPU memory that pointer addresses.

__global__ void scale(float* data, float k) {}

Each Thread Picks Its Work

The same code runs in every thread, so each one uses its index to decide which element to touch. That is how one function covers a whole array.

int i = threadIdx.x; // who am I?

A Tiny Complete Kernel

Here is a full kernel: it doubles one element per thread. Notice the __global__ marker, the void return, and the pointer parameter all together.

__global__ void doubleIt(float* x) {
    int i = threadIdx.x;
    x[i] = x[i] * 2.0f;
}

Host Code Stays Separate

Your normal CPU function, often main, is host code. It sets things up and then asks the GPU to run the kernel.

int main() {
    // host side: prepare and launch
}

No Recursion or I/O Surprises

A kernel runs on hardware with tight rules, so keep it simple: avoid deep recursion and heavy standard-library calls inside it.

Naming Your Kernels

Treat a kernel like any function: give it a clear, verb-based name like vectorAdd. Good names make launches far easier to read.

__global__ void vectorAdd(float* c, float* a, float* b);

Quick Check

Let us check the kernel signature rules.

Recap: Kernel Anatomy

A kernel is a __global__ void function run by many threads. Pass pointers and small values, and let each thread use its index. Nicely done! 🎉

자주 묻는 질문

“커널의 구조” 강의는 무료인가요?

네 — “커널의 구조” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 CUDA Academy 강의 전체를 잠금 해제할 수 있습니다. CUDA Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“커널의 구조”에서 뭘 배우나요?

시그니처, 반환 자료형과 void 규칙을 알아봅니다. 브라우저에서 직접 실행하는 실습 코드로 CUDA Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

CUDA Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 CUDA Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“커널의 구조” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 CUDA Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 CUDA Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 커널의 구조
  2. 세 겹 꺾쇠괄호로 실행하기
  3. 커널 내부의 printf
  4. cudaDeviceSynchronize 설명
← CUDA Academy(으)로 돌아가기