For reasons I haven’t been able to do anything with Mojo for a few months. Today I decided to catch up with what’s new, install the latest Mojo, and make sure my Julia set generator in Mojo for CPU and GPU still ran. (https://github.com/laranzu/multijulia)
With the new version (0.26.1.0) I could not declare a GPU function parameter as mutas I expected. I strongly suggest this ought to work as it does for CPU code.
The other changes I had to make to since last October were easy enough. alias becomes comptime, OK. gpu.id for block dimensions and thread IDs is now just gpu, OK.
A new error though, the last line of
fn julia(pixels: UnsafePointer[UInt32], size: Float32, scale: Float32, iterations: Int)
…
pixels[idx] = rgb;
was now being reported as an error, “Expression must be mutable in assignment”
I assumed that the fix would be just like the CPU version, declare that array as
mut pixels: UnsafePointer[UInt32]
But no, I still got the same error message. And now I was deeply confused.
Eventually I worked out that
pixels: UnsafePointer[UInt32, MutAnyOrigin]
did the trick, based on one of the GPU puzzle examples. But I still don’t understand why I couldn’t just declare it as mut.
I’m sure there is a technical reason, but for a programming language designed to be used on both CPU and GPU, I really want the code to work the same way, as much as possible, in both cases. Keep the extra MutAnyOrigin and variant attributes for people who really want or need to go into that level of detail, but can we please make a simple mut just work as well?