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

Question about alignment #27

Open
yamt opened this issue Jul 15, 2022 · 5 comments
Open

Question about alignment #27

yamt opened this issue Jul 15, 2022 · 5 comments

Comments

@yamt
Copy link

yamt commented Jul 15, 2022

tensor-data is list<u8>.
but i suppose that its actual contents are eg. f32.
does wit/interface-types/etc provide a large enough alignment?

@abrown
Copy link
Collaborator

abrown commented Jul 18, 2022

does wit/interface-types/etc provide a large enough alignment?

I guess my question would "large enough" for what? There's a couple of directions this could go but I'm not exactly sure what you mean?

@yamt
Copy link
Author

yamt commented Jul 19, 2022

does wit/interface-types/etc provide a large enough alignment?

I guess my question would "large enough" for what? There's a couple of directions this could go but I'm not exactly sure what you mean?

i meant large enough for the actual contents. eg. f32.
(i expect no alignment for u8 and 4 byte alignment for f32.)

@geekbeast
Copy link
Contributor

WITX is a view over guest slice, WIT is a copy. Alignment has the potential to be an issue, but everything will likely work fine on Linux and Windows due to the default behavior of allocator (i.e if it uses malloc).

On Ubuntu, many other linux systems malloc, and windows returns a pointer aligned to either 8 or 16 bytes:

So whether alignment will be an issue will depend on the allocator used by the wasm host and the underlying platform.

@geekbeast
Copy link
Contributor

Additional quick follow up here is that most C compilers adhering to the standard allow casting between any valid pointer types, so everything should be fine unless there's a use case where alignment greater than 16 bytes is required (in some case 8 bytes emscripten-core/emscripten#5996 and emscripten-core/emscripten#10072).

This mainly seems to be AVX or AVX512, but if the use case does present itself it can be handled on host side.

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