bugger.
All challenges/Pythonmediumcuda-thread-index-v1
THE INVESTIGATION

Map threads to elements

Compute the global index for every thread in a one-dimensional launch and identify in-bounds threads.

LLM ArchitectureML systems

What’s going wrong

Original LLM Architecture lab. This CUDA fundamentals exercise is a deterministic Python simulation, not CUDA code or GPU execution. Implement solve(data) using the Python standard library.

Given length, blocks and threads_per_block, return {"indices": [...], "active": [...]} in block-major then thread-major order. The global index is block_id * threads_per_block + thread_id; active means index < length. Inputs are nonnegative integers and threads_per_block is positive.

Expected behavior

Compute the global index for every thread in a one-dimensional launch and identify in-bounds threads.

Reproduction

01 Case 1
{"length": 5, "blocks": 2, "threads_per_block": 4}
{"indices": [0, 1, 2, 3, 4, 5, 6, 7], "active": [true, true, true, true, true, false, false, false]}
02 Case 2
{"length": 2, "blocks": 1, "threads_per_block": 2}
{"indices": [0, 1], "active": [true, true]}
03 Case 3
{"length": 0, "blocks": 2, "threads_per_block": 3}
{"indices": [0, 1, 2, 3, 4, 5], "active": [false, false, false, false, false, false]}

Before you begin

  • Python lists and loops

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.