Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fixed size batch #809

Open
bernhardmgruber opened this issue Aug 24, 2022 · 4 comments
Open

Add a fixed size batch #809

bernhardmgruber opened this issue Aug 24, 2022 · 4 comments

Comments

@bernhardmgruber
Copy link

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!

@serge-sans-paille
Copy link
Contributor

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)

@Spilipp
Copy link

Spilipp commented Jul 15, 2023

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?

@serge-sans-paille
Copy link
Contributor

Example usage:

using batch4f = xsimd::make_sized_batch_t<float, 4>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants