how to use the gather function
Standard library contains a gather function which I would like to use, but I can’t figure out how to create a SIMD[DType.address, 4] vector based on different locations in a DTypePointer or another SIMD vector.
5 Replies
Leandro Campos, has a branch with tests demonstrating how to do this. That exercises the new methods he is adding to DTypePointer. The use of the intrinsic itself is here.
The pointer manipulation to use the intrinsic looks simple now that someone else figured it out for me. 🤦♂️ 🤷 😃
GitHub
mojo/stdlib/src/memory/unsafe.mojo at masked_gather_and_scatter · l...
The Mojo Programming Language. Contribute to leandrolcampos/mojo development by creating an account on GitHub.
GitHub
mojo/stdlib/test/memory/test_memory.mojo at masked_gather_and_scatt...
The Mojo Programming Language. Contribute to leandrolcampos/mojo development by creating an account on GitHub.
Great, thanks Leandro. I wonder how mojo handles this with large vectors of offset values (much larger than simdwidth), and whether we'd be supposed to break up that large vectors in chunks. I.e does it do what tf.gather() does well under the hood.
I am not sure much larger than SIMD width will ever be faster but you would need to experiment to check. There are trade offs between pure SIMD speed, number of reads from heap, and how cache gets used. So testing different widths in your actual use case is worth doing.
Both of those links are dead and there is no trace of using the
gather
function online. 🆘Documentation is here. Example usage is here. 😃 If you really want to use the LLVM intrinsic, example usage is here.
DTypePointer | Modular Docs
Defines a DTypePointer struct that contains an address of the given dtype.
GitHub
mojo/stdlib/test/memory/test_memory.mojo at bf73717d79fbb79b4b2bf58...
The Mojo Programming Language. Contribute to modularml/mojo development by creating an account on GitHub.