เธรด บล็อก และกริด
รูปแบบการทำงานของ GPU
เธรด บล็อก และกริด เป็นบทเรียน Mojo Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Mojo Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Mojo Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
The Smallest Worker
A GPU runs your kernel as many tiny workers. Each single worker is a thread, and it usually handles one piece of data.
Grouping Threads
Threads are organized into a block. Threads in the same block can cooperate and share fast on-chip memory.
All Blocks Together
All the blocks for one kernel launch form the grid. The grid is the full set of workers handling your whole problem.
A Simple Hierarchy
The model nests neatly: threads live in blocks, and blocks live in a grid. Three levels describe every launch.
Each Thread Has an ID
Every thread can ask where it sits. Its index tells it which element of the data it is responsible for.
var tid = thread_idx.xEach Block Has an ID Too
Blocks are numbered as well. A thread combines its block id with its local id to find a unique spot.
var bid = block_idx.xComputing a Global Index
The classic formula maps each thread to one global element. This global index is how kernels split an array.
var i = block_idx.x * block_dim.x + thread_idx.xChoosing Block Size
You pick how many threads sit in a block. A good size keeps the hardware busy without wasting resources.
Choosing Grid Size
The grid must cover all your data. You size it so threads times blocks reach every element you need.
var blocks = (n + 255) // 256Guarding the Edges
The grid often launches a few extra threads. A simple bounds check stops them from touching memory past the end.
if i < n:
out[i] = a[i] + b[i]Why This Shape Helps
Blocks let groups share memory and sync, while the grid scales to any size. The structure maps work onto hardware cleanly.
Quick Check
A thread needs the position of its element across the whole array.
Recap
Threads group into blocks, blocks form the grid, and combining their ids gives each worker a unique global index. 🧵
คำถามที่พบบ่อย
บทเรียน “เธรด บล็อก และกริด” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “เธรด บล็อก และกริด” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Mojo Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Mojo Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “เธรด บล็อก และกริด”
รูปแบบการทำงานของ GPU คุณปฏิบัติ Mojo Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Mojo Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Mojo Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “เธรด บล็อก และกริด” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Mojo Academy นี้ได้ไหม
ได้ บทเรียน Mojo Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- เหตุใดภาระงานปัญญาประดิษฐ์จึงใช้ GPU
- เธรด บล็อก และกริด
- การเขียนฟังก์ชันเคอร์เนล GPU
- การย้ายข้อมูลไปยังและออกจากอุปกรณ์