ModularM
Modular2y ago
2 replies
amiya_mandal

Its possible to create SIMD vector at runtime

I am currently working on a vector implementation using SIMD and I am encountering a challenge. Specifically, I am unable to locate an example demonstrating how to initialize an SIMD vector at runtime.

Here is the relevant code snippet I am working with:

# exmaple form matrix multiplication

struct Vector[vector_size:Int]:
    var data:DTypePointer[DType.float32]

    fn __init__(inout self):
        self.data = DTypePointer[DType.float32].alloc(vector_size)
        memset_zero(self.data, vector_size)

    fn load[nelts: Int](self, x: Int) -> SIMD[DType.float32, nelts]:
        return self.data.load[width=nelts](x)

    fn store[nelts: Int](self, x: Int, val: SIMD[DType.float32, nelts]):
        return self.data.store[width=nelts](x, val)

    fn __getitem__(self, x: Int) -> Scalar[DType.float32]:
        return self.load[1](x)

    fn __setitem__(self, x: Int, val: Scalar[DType.float32]):
        self.store[1](x, val)

var score = Vector[corpus_size]() # error


I would appreciate any guidance or examples on how to properly initialize an SIMD vector at runtime. Your assistance in this matter would be highly valued.

Thank you for your time and support.
Was this page helpful?