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

[Feature Request] Align::[Adaptive/Element/Vector] mode and use std::array as FixedArray #5034

Open
jopadan opened this issue Dec 10, 2024 · 2 comments
Labels
type:Enhancement Improvement of existing methods or implementation

Comments

@jopadan
Copy link

jopadan commented Dec 10, 2024

Description

Add SIMD compatible alignment support to FixedArray based types and use std::array.

#include <bit>
#include <array>
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <cstddef>

enum class Align
{
Adaptive = 0,
Element  = 1,
Vector   = 2,
}

template<typename T, unsigned int VLength = 3, enum Align VAlign = Align::Adaptive, unsigned int VLengthPow2 = std::bit_ceil<unsigned int>(VLength)>
struct alignas(((VLength == VLengthPow2) && (VAlign != Align::Element)) || (VAlign == Align::Vector) ? VLengthPow2 * sizeof(T) : sizeof(T)) FixedArray : std::array<T, VLength>
{
};

FixedArray<float, 3>                 a = {1,2,3};
FixedArray<float, 3, Align::Vector>  b = {1,2,3};
FixedArray<float, 4, Align::Element> c = {1,2,3,4};
FixedArray<float, 4>                 d = {1,2,3,4};

printf("%02zu/%zu\n", alignof(a), sizeof(a));
printf("%02zu/%zu\n", alignof(b), sizeof(b));
printf("%02zu/%zu\n", alignof(c), sizeof(c));
printf("%02zu/%zu\n", alignof(d), sizeof(d));

Expected Behavior

 4/12
16/16
 4/16
16/16

Current behavior

Align::Element = alignas(sizeof(T))/(sizeof(T)*VLength);

Additional Information

@jopadan jopadan added the type:Enhancement Improvement of existing methods or implementation label Dec 10, 2024
Copy link

Thank you for contributing an issue! 🙏

Welcome to the ITK community! 🤗👋☀️

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜
Also, please check existing open issues and consider discussion on the ITK Discourse. 📖

This is an automatic message. Allow for time for the ITK community to be able to read the issue and comment on it.

@jopadan jopadan changed the title Align::[Adaptive/Element/Vector] mode and use std::array as FixedArray [Feature Request] Align::[Adaptive/Element/Vector] mode and use std::array as FixedArray Dec 10, 2024
@thewtex
Copy link
Member

thewtex commented Dec 10, 2024

@jopadan great idea! 💡

Backwards-compatible patches are welcome for ITK 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Enhancement Improvement of existing methods or implementation
Projects
None yet
Development

No branches or pull requests

2 participants