0Pricing
CUDA Academy · 강의

Hello GPU: 첫 번째 .cu 파일

최소한의 CUDA 프로그램을 빌드하고 실행합니다.

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

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

Your First .cu File

Time to build something real. A CUDA program lives in a .cu file, which can hold both CPU and GPU code side by side. 🎉

Include the Header

Most CUDA samples start by pulling in standard headers. The CUDA runtime header is included automatically by nvcc, so iostream is often enough.

#include <cstdio>

Marking a Kernel

A function that runs on the GPU is a kernel. You mark it with the __global__ qualifier so nvcc compiles it for the device.

__global__ void hello() {
}

Printing from the GPU

Inside the kernel you can call printf just like on the CPU. Each GPU thread that runs it produces its own line of output.

__global__ void hello() {
  printf("Hello from GPU\n");
}

The Launch Syntax

To run a kernel you use the triple-angle-bracket launch. The numbers inside choose how many blocks and threads will execute it.

hello<<<1, 1>>>();

Launches Are Asynchronous

A kernel launch returns immediately while the GPU works in the background. The CPU keeps going, which is powerful but can be surprising at first.

Waiting for the GPU

Because of that, you must synchronize before the program ends, or the printf output may never appear on screen.

cudaDeviceSynchronize();

Putting It Together

Your main function launches the kernel and then waits. That is the entire skeleton of a working CUDA program.

int main() {
  hello<<<1, 1>>>();
  cudaDeviceSynchronize();
}

Compile It

Save the file as hello.cu and build it with nvcc, naming the output program with the -o flag.

nvcc hello.cu -o hello

Run It

Now run the program. Seeing Hello from GPU printed means your code truly executed on the device. That is your first GPU output! 🚀

./hello

Many Threads at Once

Bump the launch to many threads and you will see the greeting printed several times, one line per thread. That is real parallelism in action.

hello<<<1, 8>>>();

Quick Check

One detail makes or breaks this program.

Recap

You wrote a real CUDA program: a __global__ kernel, a triple-bracket launch, and a sync. Compile with nvcc, run it, and the GPU greets you. Congrats! 🎓

자주 묻는 질문

“Hello GPU: 첫 번째 .cu 파일” 강의는 무료인가요?

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

“Hello GPU: 첫 번째 .cu 파일”에서 뭘 배우나요?

최소한의 CUDA 프로그램을 빌드하고 실행합니다. 브라우저에서 직접 실행하는 실습 코드로 CUDA Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

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

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

“Hello GPU: 첫 번째 .cu 파일” 강의는 얼마나 걸리나요?

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

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

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

이 강의의 모든 강의

  1. 드라이버, 런타임과 툴킷 버전
  2. 전문가처럼 nvidia-smi 읽기
  3. nvcc로 컴파일하기
  4. Hello GPU: 첫 번째 .cu 파일
← CUDA Academy(으)로 돌아가기