ลำดับชั้นของเธรด
รวมเธรดเป็นบล็อก และรวมบล็อกเป็นกริด
ลำดับชั้นของเธรด เป็นบทเรียน CUDA Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน CUDA Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส CUDA Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Many Threads, One Job
A CUDA kernel runs in parallel across many threads, and each thread does the same work on its own slice of the data. 🧵
Threads Need Structure
Launching millions of loose threads would be chaos. CUDA organizes them into a clean hierarchy so the hardware can schedule them well.
Threads Form Blocks
Threads are grouped into a block. Every thread in a block runs the same kernel and can cooperate closely with its neighbors.
Blocks Form the Grid
All the blocks for one launch together make up the grid. So the chain is simple: threads live in blocks, and blocks live in the grid.
Why Two Levels?
The two-level design lets one kernel scale from a tiny GPU to a huge one. You describe the work once and the grid stretches to fit.
Picking the Shape at Launch
You choose how many blocks and how many threads per block right at the launch, using the triple-angle-bracket syntax.
myKernel<<<numBlocks, threadsPerBlock>>>(data);A Concrete Example
Say you launch 4 blocks of 256 threads. That gives you 4 times 256, or 1024 threads all running at once.
Blocks Are Independent
Different blocks cannot assume any order or talk to each other directly. This independence is exactly what lets the GPU run them in any sequence.
Threads Within a Block Cooperate
Inside one block, threads can share fast on-chip memory and synchronize with each other. That teamwork is a block's superpower.
Grids and Blocks Can Be 3D
Both the grid and each block can be 1D, 2D, or 3D. The dim3 type lets you map naturally onto images or volumes.
dim3 block(16, 16);
dim3 grid(32, 32);One Thread, One Element
The common goal is to give each thread exactly one data element to handle. The hierarchy is just how you reach that mapping.
Quick Check
Let us check how the pieces nest together.
Recap: The Hierarchy
You learned the CUDA ladder: threads make a block, blocks make the grid. Independent blocks scale, while threads inside a block cooperate. 🎯
คำถามที่พบบ่อย
บทเรียน “ลำดับชั้นของเธรด” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ลำดับชั้นของเธรด” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส CUDA Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส CUDA Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ลำดับชั้นของเธรด”
รวมเธรดเป็นบล็อก และรวมบล็อกเป็นกริด คุณปฏิบัติ CUDA Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน CUDA Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน CUDA Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “ลำดับชั้นของเธรด” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน CUDA Academy นี้ได้ไหม
ได้ บทเรียน CUDA Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ