SIMD or Int what should I use ?
A single integer value can be represented as both SIMD[Dtype, 1] or as Int. When should I use the first and when the former ?
4 Replies
Int is already represented as SIMD of one element, use that
Congrats @Melody Daniel, you just advanced to level 14!
Please check out our recently explainer in X https://x.com/Modular/status/1776287802533245372 also note that
Int
(not Int*
) is different and a special case. It's a numeric type in index
MLIR dialect which can be implicitly converted back and forth to Int*
, Scalar
.Modular (@Modular) on X
In this thread 🧵 we want to dive into SIMD: Mojo's 🔥 main runtime numeric type.
SIMD stands for Single Instruction, Multiple Data.
Using SIMD types allows a single operation to be applied to multiple data simultaneously 🚀 . Let's explore 👇
Twitter
Just to add a quick explination for anyone stumbling on this.
Int8/16/32/64
along with all the other simple numeric types like Float32
, Float64
, UInt8
, etc.. are simply Scalar[DType.int]
, which is equivilent to SIMD[DType.int, 1]
(Where DType.int
changes depending on the actual type.
These are defined in the stdlib simply as alias Int32 = SIMD[DType.int32, 1]
. That being said, as the above mentions, Int
is a special case and provides additional methods, but also comes with potentially additional overhead. Depending on application, Int8/16/32/64
may be more efficient than Int