xsimd icon indicating copy to clipboard operation
xsimd copied to clipboard

Add a fixed size batch

Open bernhardmgruber opened this issue 3 years ago • 4 comments

As someone who has worked with Vc and std::experimental::simd before, I miss the equivalent of a fixed size SIMD array in xsimd. This would be a version of xsimd::batch where I can specify the length at compile time and this length is then subdivided and mapped to the available SIMD register sizes. In Vc and std::experimental::simd, this is solved with an additional ABI tag. The equivalence in xsimd would be the architecture type argument A in xsimd::batch<T, A>.

As an example, a xsimd::batch<float, fixed_size<12>> may use 3 SSE registers internally when compiled for SSE, or 1 AVX and 1 SSE register when compiled with AVX. A xsimd::batch<float, fixed_size<5>> would use an SSE register and a scalar. Etc.

Such a construct is very handy when the algorithm dictates a vector length. Or when I need to mix element types of different sizes, e.g. a loop over arrays with float and double. In the latter case I could use xsimd::batch<float> and xsimd::batch<double, fixed_size<xsimd::batch<float>::size>> to ensure that both batches have the same number of elements.

Would it be possible to add such a construct? Thank you!

bernhardmgruber avatar Aug 24 '22 13:08 bernhardmgruber

Some random thoughts: this would slightly overlap with xtensor, we probably need a dedicated type to achieve that, we already have support for fixed size array but it's very limited (only works if the size directly maps to a supported register size)

serge-sans-paille avatar Aug 25 '22 09:08 serge-sans-paille

I'm also looking for fixed size batches. I have a specific use case with rgba pixels in an array of structures and I need to access them out of order. Structure of arrays is not an option in this specific case.

So a) if a pixel does not fit a register size it still needs to be fully loaded and processed. And b) storing may not overwrite neighbouring pixels.

Serge. You say xsimd has "support for fixed size array". I'm not sure what you mean. Could you please elaborate so I can see if that could help me?

Spilipp avatar Jul 15 '23 23:07 Spilipp

https://xsimd.readthedocs.io/en/latest/api/xsimd_batch.html#_CPPv4I0_NSt6size_tEEN5xsimd16make_sized_batchE

serge-sans-paille avatar Jul 16 '23 18:07 serge-sans-paille

Example usage: https://github.com/xtensor-stack/xsimd/blob/e6fa5aca6320d6ccaf24c123ab2af9b0f2f09cc1/test/test_arch.cpp#L141

serge-sans-paille avatar Jul 16 '23 18:07 serge-sans-paille