M
Modular8mo ago
Maxim

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
Michael K
Michael K6mo ago
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.
alain
alain6mo ago
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.
Michael K
Michael K6mo ago
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.
DJ_HalfcourtViolation
Both of those links are dead and there is no trace of using the gather function online. 🆘
Michael K
Michael K4mo ago
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.
Want results from more Discord servers?
Add your server