ORNL / cpp-proposals-pub

Collaborating on papers for the ISO C++ committee - public repo
26 stars 27 forks source link

LEWG Kona 11/2023 Padded Layouts Review #433

Open crtrott opened 1 year ago

crtrott commented 1 year ago

Padded Layouts

Compare memory storage of layout_left and layout_left_padded:

int data[] = {0, 1, 2, 3, 4, 5};
mdspan<int, dextents<int,2>, layout_left>
  m(data,extents(3,2));

for(int col=0; col<m.extents(0); col++) {
  for(int row =0; row<m.extents(1); row++) 
    std::cout << m[col,row] << " ";
  std::cout << std::endl;
}
// prints:
//  0 3
//. 1 4
//  2 5

// Want colums to be aligned to cache lines - i.e. pad with dummy values 
int data[] = {0, 1, 2, 999, 3, 4, 5, 999};
mdspan<int, dextents<int,2>, layout_left_padded<4>>
  m(data,extents(3,2));

for(int col=0; col<m.extents(0); col++) {
  for(int row =0; row<m.extents(1); row++) 
    std::cout << m[col,row] << " ";
  std::cout << std::endl;
}
// prints:
//  0 3
//. 1 4
//  2 5
using map_t = layout_left_padded<4>::mapping<dextents<int, 2>>;
map_t m(3,2); // => m.stride(1) == 4
map_t m(4,2); // => m.stride(1) == 4
map_t m(5,2); // => m.stride(1) == 8

Use cases:

Impact on existing elements in C++23/26 draft

mhoemmen commented 1 year ago

LEWG review 2023/11/09:

  1. Remove the new feature test macro, and instead, bump the existing submdspan macro __cpp_lib_submdspan
  2. Stray semicolon somewhere in the class declaration
  3. Constructor defined inline, so we can strike it from the wording below the class.