News for hackers. Stuff that matters.
Re:RLSL: a Rust to SPIR-V Compiler by pcwalton on Monday October 21, 2019 @04:26PM (#21316915)
There's no memory safety problem if the data you're racing on is pointer-free. Rust allows racing on memory with Relaxed atomics [1]. (Yes, I know about potential UB with floating point and whatnot; this is solvable.) Happily, GPU programming tends to use a lot of indices as opposed to direct pointers, because it makes CPU/GPU memory management easier--indices are valid no matter where in the address space the data in question is mapped.

Of course, you might then ask "what's the point of using Rust at all?" The answer is that a lot of code can be expressed in regular patterns idiomatic to the Rust type system and borrow checker. This isn't particularly different from any other type of programming. You sometimes see people say "Rust is useless because you can't safely write an arbitrary graph with direct pointers". The obvious fallacy with this argument is that most code doesn't need an arbitrary graph with direct pointers; for the small amount of code that does, you can drop into unsafe in a targeted way and still have a much safer program than one written in e.g. C. GPU programming is no different.

[1] https://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html

(Note than on x86 Relaxed atomics turn into plain mov instructions, and on ARM they turn into plain ldr and str.)

Re:RLSL: a Rust to SPIR-V Compiler by AndrewGaspar on Tuesday October 22, 2019 @10:28AM (#21323955)
Huh - to make sure I understand correctly, is it your view (ignoring portability concerns) that it should be legal to store and load directly from a non-mut &[f32] when the platform has relaxed-atomic memory consistency by default? Or just that you should use a hypothetical "AtomicF32" with relaxed loads and stores and not worry about it from a performance perspective?
Re:RLSL: a Rust to SPIR-V Compiler by pcwalton on Tuesday October 22, 2019 @10:51AM (#21324238)
There should be an AtomicF32 type that supports unsynchronized reads/writes on GPU.
Re:RLSL: a Rust to SPIR-V Compiler by AndrewGaspar on Tuesday October 22, 2019 @11:13AM (#21324537)
Thanks, that makes a lot of sense!