-
Notifications
You must be signed in to change notification settings - Fork 32
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
base: develop
Are you sure you want to change the base?
Conversation
// 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()); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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())), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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())), |
There was a problem hiding this comment.
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
self.buffer | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ScalarBuffer!
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.