M
Modular2w ago
Firas

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
5 Replies
Jake Brooks
Jake Brooks2w ago
If i understand your question correctly, the second process will be slower since you would be fetching data from the heap before performing the multiplication. Simply multiplying two SIMDs is faster than storing the data on the heap, reading it into two SIMD objects and then multiplying them. Also, a word of caution for the future, the current plan as I understand it is to remove DTypePointer in the future. You should use UnsafePointer instead.
Firas
Firas2w ago
thanks Jake ! thanks for letting me know about the pointer things 👍 Regarding the question, for instance, if we examine the inner loop in the matrix multiplication example from Mojo, they implement it using vectorization. Therefore, if we convert the data to SIMD format and utilize SIMD operations, would the process would be faster ?
Jake Brooks
Jake Brooks7d ago
In Mojo, all values are SIMD values, so by loading data from the heap (via SIMD.load) you are already creating a SIMD value that can use SIMD operations. Under the hood, all vectorize is doing is picking an optimal value of simd_width to use. There are no special conversions going on.
Firas
Firas4d ago
Thanks a lot ... yes at the end i assumed that....
ModularBot
ModularBot4d ago
Congrats @Firas, you just advanced to level 4!
Want results from more Discord servers?
Add your server