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 an ArrayBuffer that declares alignment #1720

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

gatesn
Copy link
Contributor

@gatesn gatesn commented Dec 18, 2024

This is so that the reader knows the minimum alignment required for a given array buffer.
This can help minimize copies during the read when buffers are already sufficiently aligned.

It also allows e.g. FastLanes to declare much wider alignment, for example 128 bytes.

@gatesn gatesn requested review from lwwmanning and a10y December 18, 2024 19:22
@gatesn gatesn mentioned this pull request Dec 18, 2024
// TODO(ngates): enforce 128 byte alignment once we have a ScalarBufferBuilder that can
// enforce custom alignments.
// let packed = ArrayBuffer::new_with_alignment(packed, FASTLANES_ALIGNMENT);
let packed = ArrayBuffer::new_with_alignment(packed, ptype.byte_width());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_with_alignment (and new) are weird names for a thing called ArrayBuffer, since I kind of expect them to allocate? a la Vec::new

@@ -128,6 +129,8 @@ impl MessageEncoder {
&fba::BufferArgs {
length: buffer.len() as u64,
padding,
// Buffer messages have no minimum alignment, the reader decides.
alignment_: 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is not a power of 2, will this cause a panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is flatbuffer default value. Reader must handle it

Copy link
Member

@lwwmanning lwwmanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if AlignedBuffer would be a better name for ArrayBuffer? and should it be in the vortex-buffer crate? (or like, should Buffer even be pub since we should presumably ~always be using this?)

@@ -60,7 +61,7 @@ impl PrimitiveArray {
.to_metadata(length)
.vortex_expect("Invalid validity"),
}),
Some(buffer),
Some(ArrayBuffer::new_with_alignment(buffer, ptype.byte_width())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should constructor just accept ArrayBuffer directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should accept a ScalarBuffer, and then the PType can be extracted. For now it's a bit annoying to take an ArrayBuffer and then make sure alignment matches when I'm about to change it anyway

@@ -87,6 +90,7 @@ impl BitPackedArray {
packed.len()
));
}
let packed = ArrayBuffer::new_with_alignment(packed, FASTLANES_ALIGNMENT);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I expect this will fail. I can fix this up in the PR to add ScalarBuffer by specifying a runtime alignment.

@@ -128,6 +129,8 @@ impl MessageEncoder {
&fba::BufferArgs {
length: buffer.len() as u64,
padding,
// Buffer messages have no minimum alignment, the reader decides.
alignment_: 0,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is flatbuffer default value. Reader must handle it

@@ -60,7 +61,7 @@ impl PrimitiveArray {
.to_metadata(length)
.vortex_expect("Invalid validity"),
}),
Some(buffer),
Some(ArrayBuffer::new_with_alignment(buffer, ptype.byte_width())),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should accept a ScalarBuffer, and then the PType can be extracted. For now it's a bit annoying to take an ArrayBuffer and then make sure alignment matches when I'm about to change it anyway

vortex-array/src/buffer.rs Show resolved Hide resolved
self.buffer
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be nice to offer a way to get a slice of T out of this where we check the alignment of T at runtime

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScalarBuffer!

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

Successfully merging this pull request may close these issues.

3 participants