M
Modular•11mo ago
benny

Create a SIMD[DType.address] from a DTypePointer[T]

It would seem like DTypePointer[T].address_of(SIMD[T) would be correct, but this returns a DTypePointer aswell, which has type T, not DType.address. A bitcast seems incorrect as this would directly cast the numeric value into a pointer location, which is wrong, and I do not feel that loading the data as an address is the correct answer either. Hoping to use gather and scatter on SIMD vectors from a DTypePointer if possible.
11 Replies
ModularBot
ModularBot•11mo ago
Congrats @benny, you just advanced to level 8!
Maxim
Maxim•11mo ago
I had the same question. 🙂
benny
bennyOP•11mo ago
any luck? i’m still stuck
Maxim
Maxim•11mo ago
Same I think since 24.1.0 you can write int(p) and get the int representation of the pointer address, so I thought maybe I can wrap it in SIMD[DType.address,1] but this also doesn’t work. I have a feeling it’s something which was introduced early, but now needs reworking so until it’s done, nobody wants to talk about it 😀.
benny
bennyOP•11mo ago
@Jack Clayton any insight on this? still havent found a solution
Jack Clayton
Jack Clayton•11mo ago
Hi @benny is this what you're looking for:
fn main():
var x = Int64(42)
var p =Pointer[Scalar[DType.int64]].address_of(x)
print(int(p))
fn main():
var x = Int64(42)
var p =Pointer[Scalar[DType.int64]].address_of(x)
print(int(p))
Or are you trying to fill a SIMD vec with addresses?
benny
bennyOP•11mo ago
that is the issue yes for potentially use with gather / scatter (that’s the required input) i figured once stdlib is open sourced their may be some use of what i’m trying to do in there I can look for, but until then I got nothing
Jack Clayton
Jack Clayton•11mo ago
Ok haven't seen that, asking the team
adakkak
adakkak•11mo ago
You should be able to do SIMD[DType.address](int(my_pointer)) E.g.
fn main():
var x = Int64(42)
var p = DTypePointer.address_of(x)
print(int(p))
print(SIMD[DType.address, 4](int(p)).type)
fn main():
var x = Int64(42)
var p = DTypePointer.address_of(x)
print(int(p))
print(SIMD[DType.address, 4](int(p)).type)
sadly print on DType.address is broken right now. Will fix
benny
bennyOP•11mo ago
perfect! thank you so much :)
alain
alain•11mo ago
Finally, we can try to actually use gather/scatter based on this. There is an open change request to make that way less clunky but Mojo team considers it 'just semantic sugar'. Kind request for the first successful example code using gather and scatter to be shared amongst mojicans !

Did you find this page helpful?