Skip to content

Add an ArrayBuffer that declares alignment#1720

Closed
gatesn wants to merge 6 commits into
developfrom
ngates/array-buffer
Closed

Add an ArrayBuffer that declares alignment#1720
gatesn wants to merge 6 commits into
developfrom
ngates/array-buffer

Conversation

@gatesn

@gatesn gatesn commented Dec 18, 2024

Copy link
Copy Markdown
Contributor

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 a10y and lwwmanning 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
Copy Markdown
Contributor

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

length: buffer.len() as u64,
padding,
// Buffer messages have no minimum alignment, the reader decides.
alignment_: 0,

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

Comment thread vortex-array/src/buffer.rs

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor

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?)

.vortex_expect("Invalid validity"),
}),
Some(buffer),
Some(ArrayBuffer::new_with_alignment(buffer, ptype.byte_width())),

Copy link
Copy Markdown
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
Copy Markdown
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

packed.len()
));
}
let packed = ArrayBuffer::new_with_alignment(packed, FASTLANES_ALIGNMENT);

Copy link
Copy Markdown
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.

length: buffer.len() as u64,
padding,
// Buffer messages have no minimum alignment, the reader decides.
alignment_: 0,

Copy link
Copy Markdown
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

.vortex_expect("Invalid validity"),
}),
Some(buffer),
Some(ArrayBuffer::new_with_alignment(buffer, ptype.byte_width())),

Copy link
Copy Markdown
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

Comment thread vortex-array/src/buffer.rs
self.buffer
}
}

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ScalarBuffer!

@gatesn

gatesn commented Dec 29, 2024

Copy link
Copy Markdown
Contributor Author

Closed for #1742

@gatesn gatesn closed this Dec 29, 2024
@robert3005 robert3005 deleted the ngates/array-buffer branch January 29, 2025 22:27
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