Skip to content

Conversation

@mbernat
Copy link

@mbernat mbernat commented Nov 2, 2025

When running p03 on macos the check passes even with an incorrect kernel.

    # FILL ME IN (roughly 2 lines)
    output[i] = a[i] + 10
(mojo-gpu-puzzles) chill@Mareks-Laptop mojo-gpu-puzzles % pixi run p03
✨ Pixi task (p03 in default): mojo problems/p03/p03.mojo                                                                                                  
out: HostBuffer([10.0, 11.0, 12.0, 13.0])
expected: HostBuffer([10.0, 11.0, 12.0, 13.0])

This PR catches the mistake by using a bigger array.

(mojo-gpu-puzzles) chill@Mareks-Laptop mojo-gpu-puzzles % pixi run p03              
✨ Pixi task (p03 in default): mojo problems/p03/p03.mojo                                                                                                  
out: HostBuffer([10.0, 11.0, 12.0, 13.0, 10.0, 10.0, 10.0, 10.0])
expected: HostBuffer([10.0, 11.0, 12.0, 13.0, 0.0, 0.0, 0.0, 0.0])
stack trace was not collected. Enable stack trace collection with environment variable `MOJO_ENABLE_STACK_TRACE_ON_ERROR`
Unhandled exception caught during execution: At /Users/chill/Documents/GitHub/mojo-gpu-puzzles/problems/p03/p03.mojo:55:29: AssertionError: `left == right` comparison failed:
   left: 10.0
  right: 0.0
  • The incorrect kernel might have a UB, so this is just a best effort check to protect against that.
  • This might need additional discussion in the puzzle text itself to make the distinction between thread count and array size clearer.
  • Another approach would be to tell the user they likely forgot to check the bounds but hide the bigger array from them.
  • Once some form of this PR is accepted I'd be happy to apply it also to other puzzles that suffer from the same problem.

@ehsanmok
Copy link
Collaborator

ehsanmok commented Nov 3, 2025

That's by design! Please take a look at the solution. The UB is called out and discussed later.

@ehsanmok ehsanmok closed this Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants