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

LEWG Kona 11/2023 mdarray #434

Open
crtrott opened this issue Nov 9, 2023 · 0 comments
Open

LEWG Kona 11/2023 mdarray #434

crtrott opened this issue Nov 9, 2023 · 0 comments

Comments

@crtrott
Copy link
Collaborator

crtrott commented Nov 9, 2023

Super Brief mdarray introduction

Why we want mdarray

Creating a simple 2D array with mdspan requires multiple steps because mdspan is non-owning.

// Create a mapping:
layout_left map(extents(N,M));

// Create an allocation
vector<int> data(map.required_span_size());

// Create mdspan:
mdspan a(data.data(), map);

mdarray is a multidimensional array with value-semantics and makes the above simpler

// default layout
mdarray a(N,M);
// other layout
mdarray b(layout_left(extents(N,M))); 

What aspects of mdspan does mdarray have

mdarray has the

  • element_type,
  • extents and
  • layout policy aspects of mdspan

The accessor policy is replaced by a container type.

template<class ElementType, class Extents, class Layout, class Accessor>
class mdspan {
   public:
   ...
     template<class ... Indices>
     reference operator [] (Indices ... idx) const { return acc_.access(ptr_, map_(idx...)); }
   private:
     typename Accessor::data_handle_type ptr_;
     Layout::mapping<Extents> map_;
     Accessor acc_;
};

template<class ElementType, class Extents, class Layout, class Container>
class mdarray {
   public:
   ...
     template<class ... Indices>
     reference operator [] (Indices ... idx) { return ctr_[map_(idx...)]); }

   private:
     Layout::mapping<Extents> map_;
     Container ctr_;
};

This means mdarray does not have the kind of access modality customization point functionality of mdspan, but that functionality is anyway intended for local specialization of accesses, and thus more suited for the view-like class.

Constructors

  • have constructors similar to mdspan
    • indicies
    • extents
    • mapping
  • Combine those with copy from container, and move from container
  • Combine all of those with add optional allocator

Move behavior

  • relies on containers move behavior
  • preconditions on problematic functions to check that container size is larger or equal to required_span_size()
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

1 participant