Firas
MModular
•Created by Firas on 9/9/2024 in #questions
vectorize functional VS SIMD regular ops
Hi,
Let say we want to implent simple 2 vector multiplications.
the first implentation is using SIMD as data, we define 2 vectors using SIMD and do mul between them.
the second is using DTypePointer and then using vectorize functional.
What is the diffirence ? is it the same ?
thanks
7 replies
MModular
•Created by Firas on 9/7/2024 in #questions
How to random int ??
I have very simple:
results = DTypePointer[type].alloc(batch * cols)
how to generate random idex (int) in [0,batch * cols] ???
all the random function in mojo returns SIMD,
how to convert simd to regular Int ?
5 replies
MModular
•Created by Firas on 9/2/2024 in #questions
shift right/left in max graphs custom ops
first of all I want to say it's haarddd to learn mojo/max !! I am struggling !! hope it will be worth it...
I have the following new custom simple op in max graph.
for now it's dummy and just do or between two input booleans.
from max.extensibility import Tensor, empty_tensor
from max import register
@register.op("my_rule")
#fn automata_rule[type: DType, rank: Int](values: Tensor[type, rank], rules: Tensor[DType.uint8, rank]) -> Tensor[type, rank]:
fn rule[type: DType, rank: Int](values: Tensor[type, rank], values_2: Tensor[type, rank]) -> Tensor[type, rank]:
var output = empty_tensortype
@always_inline @parameter fn func[width: Int](i: StaticIntTuple[rank]) -> SIMD[type, width]:
var val = values.simd_loadwidth var val_2 = values_2.simd_loadwidth return val & val_2 output.for_eachfunc return output^ I want to just slice the inputs, that means if I have input [1,2,3,4,5] I want to make it [2,3,4,5] and another one to make it [1,2,3,4] How can I do it ?? The docs is documented but htere is no examples there and it's hard for symbolic graph it;s not regular python indexing !!
var output = empty_tensortype
@always_inline @parameter fn func[width: Int](i: StaticIntTuple[rank]) -> SIMD[type, width]:
var val = values.simd_loadwidth var val_2 = values_2.simd_loadwidth return val & val_2 output.for_eachfunc return output^ I want to just slice the inputs, that means if I have input [1,2,3,4,5] I want to make it [2,3,4,5] and another one to make it [1,2,3,4] How can I do it ?? The docs is documented but htere is no examples there and it's hard for symbolic graph it;s not regular python indexing !!
2 replies
MModular
•Created by Firas on 5/2/2024 in #questions
RayTracing example - __add__ method (dunder methods)
In the RayTracing example, in the first class implementation Vec3f, in the dunder methods (add sub ...etc)
the implementation is like this:
fn add(self, other: Vec3f) -> Vec3f:
return self.data + other.data
this return data, and it's type is SIMD,
shouldn't it be:
fn add(self, other: Vec3f) -> Vec3f:
return Vec3f(self.data + other.data)
??
I tried both and both compiled and worked.
But why the the first implementation (the one in the example) work!!
the function needs to return Vec3f but it returns SIMD !!
5 replies