MUDA
Loading...
Searching...
No Matches
aosoa_sub_field.inl
1namespace muda
2{
3MUDA_INLINE void SubFieldImpl<FieldEntryLayout::AoSoA>::build_impl()
4{
5 auto min_alignment = build_options().min_alignment;
6 auto max_alignment = build_options().max_alignment;
7 // eg: innermost array size = 4
8 // a "Struct" is something like the following, where M/V/S are 3 different entries, has type of matrix/vector/scalar
9 //tex:
10 // $$
11 // \begin{bmatrix}
12 // M_{11} & M_{11} & M_{11} & M_{11}\\
13 // M_{21} & M_{21} & M_{21} & M_{21}\\
14 // M_{12} & M_{12} & M_{12} & M_{12}\\
15 // M_{22} & M_{22} & M_{22} & M_{22}\\
16 // V_x & V_x & V_x & V_x\\
17 // V_y & V_y & V_y & V_y\\
18 // V_z & V_z & V_z & V_z\\
19 // S & S & S & S \\
20 // \end{bmatrix}
21 // $$
22 uint32_t struct_stride = 0; // the stride of the "Struct"
23 for(auto& e : m_entries) // in an entry, the elem type is the same (e.g. float/int/double...)
24 {
25 // elem type = float/double/int ... or User Type
26 auto elem_byte_size = e->elem_byte_size();
27 // innermost array size: most of time the size = 32 (warp size)
28 auto inner_array_size = e->layout_info().innermost_array_size();
29 // total elem count in innermost array:
30 // scalar=1 vector3 = 3, vector4 = 4, matrix3x3 = 9, matrix4x4 = 16, and so on
31
32 struct_stride = align(struct_stride, elem_byte_size, min_alignment, max_alignment);
33 // now struct_stride is the offset of the entry in the "Struct"
34 e->m_core.m_info.offset_in_struct = struct_stride;
35
36 auto total_elem_count_in_innermost_array = e->shape().x * e->shape().y * inner_array_size;
37 struct_stride += elem_byte_size * total_elem_count_in_innermost_array;
38 }
39 // the final stride of the "Struct" >= struct size
40 m_struct_stride = align(struct_stride, struct_stride, min_alignment, max_alignment);
41
42 for(auto& e : m_entries)
43 {
44 e->m_core.m_info.struct_stride = m_struct_stride;
45 }
46}
47
48MUDA_INLINE size_t SubFieldImpl<FieldEntryLayout::AoSoA>::require_total_buffer_byte_size(size_t element_count)
49{
50 size_t outer_size = round_up(element_count, m_layout_info.innermost_array_size());
51 return outer_size * m_struct_stride;
52}
53} // namespace muda