karpathy / llm.c

LLM training in simple, raw C/CUDA
MIT License
21.28k stars 2.31k forks source link

Cast Get2dNoiseUint computation to uint #619

Closed gordicaleksa closed 6 days ago

gordicaleksa commented 1 week ago

After the conversation with Squirrel (author of the noise rnd generator we're using) it might be a good idea to cast the intermediate computation to uint to avoid dealing with ints having UB (undefined behavior) overflow.

See discord thread.

gordicaleksa commented 1 week ago

cc: @ademeure

ademeure commented 1 week ago

Looks good to me, although we could probably just change the parameters for indexX and indexY to unsigned int as well, rather than just casting them in the function, as I don't think we have any reason to ever pass negative values there. But either way solves the problem :)

gordicaleksa commented 1 week ago

Agree, but left it there in case someone wants to experiment with negative values. Although it all boils down to unsigned.