ORNL / ORNL/cpp-proposals-pub

mdspan revision

Open
#389 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
29
Forks
26
PR merge metrics
No merged PRs in 30d

Description

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_;
};

Design issues left at last time

  • Which constructors do we want?
  • What is mdarrays move behavior
  • Do we want to support moving out (extracting) the container

Constructor

  • multiple options for how to design overload set
    • complicated

Overview Table

The following table gives an overview of the three approaches.
In this table we use these shorthands:

  • mda_t: a specialization of mdarray
  • c_t: the container_type of mda_t
  • e: an extents object
  • m: a layout mapping object
  • me: a extents object or a layout mapping object
  • c: an instance of c_t
  • a: an allocator object
  • v: a value (something convertible to mda_t::value_type
  • mda: an mdarray object, not necessarily the same type as mda_t
  • mds: an mdspan obejct, not necessarily the same as returned by mda_t::to_mdspan
Arguments Current Minimal Variadic
`default` `mda_t()` `mda_t()` `mda_t()`
integrals `mda_t(10, 10)` `mda_t(10, 10)` `mda_t(10, 10)`
mapping/extents `mda_t(me)` `mda_t(me)` `mda_t(me)`
container + integrals `mda_t(extents{10, 10}, c)` `mda_t(extents{10, 10}, c)` `mda_t(extents{10, 10}, c)`
move container + integrals `mda_t(extents{10, 10}, move(c))` `mda_t(extents{10, 10}, move(c))` `mda_t(extents{10, 10}, move(c))`
container + mapping/extents `mda_t(me, c)` `mda_t(me, c)` `mda_t(me, c)`
move container + mapping `mda_t(me, move(c))` `mda_t(me, move(c))` `mda_t(me, move(c))`
container + alloc + mapping/extents `mda_t(me, c, a)` `mda_t(me, c_t(c,a))` `mda_t(me, c, a)`
move container + alloc + mapping `mda_t(me, move(c), a)` `mda_t(me, c_t(move(c),a))` `mda_t(me, move(c), a)`
extents + value `mda_t(e, v)` `mda_t(e, c_t(map_t(e).required_span_size(), v))` `mda_t(e, v)`
mapping + value `mda_t(m, v)` `mda_t(m, c_t(m.required_span_size(), v))` `mda_t(m, v)`
mapping + custom container size `mda_t(m, c_t(s))` `mda_t(m, c_t(s))` `mda_t(m, c_t(s))` or `mda_t(m, s)` for integrals not convertible to `value_type`
mapping + custom container size + value `mda_t(m, c_t(s, v))` `mda_t(m, c_t(s, v))` `mda_t(m, s, v)`
extents + value + alloc `mda_t(e, v, a)` `mda_t(e, c_t(map_t(e).required_span_size(), v, a)))` `mda_t(e, v , a)`
mapping + value + alloc `mda_t(m, v, a)` `mda_t(m, move(c_t(m.required_span_size(), v, a)))` `mda_t(m, v, a)`
mapping + custom container size + alloc `mda_t(m, c_t(s, a))` `mda_t(m, c_t(s, a))` `mda_t(m, c_t(s, a))` or `mda_t(m, s, a)` for integrals not convertible to `value_type`
mapping + custom container size + value + alloc `mda_t(m, c_t(s, v, a))` `mda_t(m, c_t(s, v, a))` `mda_t(m, s, v, a)`
iterators `mda_t(m, c_t(begin, end))` `mda_t(m, c_t(begin, end))` `mda_t(m, begin, end)`
range `mda_t(m, c_t(r))` `mda_t(m, c_t(r))` `mda_t(m, r)`
converting mdarray `mda_t(mda)` `mda_t(mda)` `mda_t(mda)`
compatible mdspan `mda_t(mds)` `mda_t(mds)` `mda_t(mds)`
compatible mdspan + allocator `mda_t(mds, a)` `mda_t(mds, a)` `mda_t(mds, a)`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files or tests are named. Start by reviewing the constructor overview and the listed design questions for mdarray, then identify the project’s relevant implementation and test locations. Done means reaching an agreed design for constructors, move behavior, and container extraction, rather than making a narrowly scoped edit.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.