-
When making a struct, are there any guarantees about struct layout? Will the struct pick the most efficient packing, or will it be C-style? Personally, I would prefer something Rust-like, where it picks the best layout by default, but adding a decorator like |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
We haven't discussed this, but I agree with you that an opt-in decorator that specifies layout is the right way to go. It seems good for the compiler to be able to reorder fields (e.g. eliminate internal padding) to allow programmers to not have to worry about this, but people putting bits on a wire or dealing with c compatibility should be able to get that. We will need to properly design this out |
Beta Was this translation helpful? Give feedback.
-
Consider (also) adding an SOA / AOS data structure like Zig's https://zig.news/kristoff/struct-of-arrays-soa-in-zig-easy-in-userland-40m0 |
Beta Was this translation helpful? Give feedback.
-
A more generalized solution is provided by Kokkos:
Source - Kokkos: Enabling manycore performance portability through polymorphic memory access patterns Basically, it automatically chooses what data layout to use depending on what is optimal for the given hardware. This sounds like something autotuning is meant for. Kokkos' programming model makes programs generic over any hardware:
Another PL I hope Mojo takes inspiration from is Halide:
Source - Halide: Decoupling Algorithms from Schedules for High-Performance Image Processing
Source - Learning to Optimize Halide with Tree Search and Random Programs
Source - decoupling algorithms from schedules for easy optimization of image processing pipelines Separating algorithm from scheduling in all use cases (not just the 1 or 2 use cases of DSLs like Halide) would massively boost developer productivity. |
Beta Was this translation helpful? Give feedback.
We haven't discussed this, but I agree with you that an opt-in decorator that specifies layout is the right way to go. It seems good for the compiler to be able to reorder fields (e.g. eliminate internal padding) to allow programmers to not have to worry about this, but people putting bits on a wire or dealing with c compatibility should be able to get that. We will need to properly design this out