Coder Social home page Coder Social logo

mdspan's Introduction

Kokkos

Kokkos: Core Libraries

Kokkos Core implements a programming model in C++ for writing performance portable applications targeting all major HPC platforms. For that purpose it provides abstractions for both parallel execution of code and data management. Kokkos is designed to target complex node architectures with N-level memory hierarchies and multiple types of execution resources. It currently can use CUDA, HIP, SYCL, HPX, OpenMP and C++ threads as backend programming models with several other backends in development.

Kokkos Core is part of the Kokkos C++ Performance Portability Programming Ecosystem.

Kokkos is a Linux Foundation project.

Learning about Kokkos

To start learning about Kokkos:

Obtaining Kokkos

The latest release of Kokkos can be obtained from the GitHub releases page.

The current release is 4.3.00.

curl -OJ -L https://github.com/kokkos/kokkos/archive/refs/tags/4.3.00.tar.gz
# Or with wget
wget https://github.com/kokkos/kokkos/archive/refs/tags/4.3.00.tar.gz

To clone the latest development version of Kokkos from GitHub:

git clone -b develop  https://github.com/kokkos/kokkos.git

Building Kokkos

To build Kokkos, you will need to have a C++ compiler that supports C++17 or later. All requirements including minimum and primary tested compiler versions can be found here.

Building and installation instructions are described here.

You can also install Kokkos using Spack: spack install kokkos. Available configuration options can be displayed using spack info kokkos.

For the complete documentation: kokkos.org/kokkos-core-wiki/

Support

For questions find us on Slack: https://kokkosteam.slack.com or open a GitHub issue.

For non-public questions send an email to: crtrott(at)sandia.gov

Contributing

Please see this page for details on how to contribute.

Citing Kokkos

Please see the following page.

License

License

Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains certain rights in this software.

The full license statement used in all headers is available here or here.

mdspan's People

Contributors

adah1972 avatar amklinv-nnl avatar brycelelbach avatar burnpanck avatar clausklein avatar crtrott avatar dalg24 avatar ehntoo avatar ghost-lzw avatar hcho3 avatar j-meyers avatar jbigot avatar kinetictheory avatar masterleinad avatar mattja avatar mhoemmen avatar nliber avatar nmm0 avatar oliverlee avatar pauleonix avatar r-burns avatar rafal-c avatar rscohn2 avatar stephanlachnit avatar tobiashienzsch avatar tpadioleau avatar trivialfis avatar wmaxey avatar xvitaly avatar youyu3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mdspan's Issues

Lack of begin() and end()

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2374r1.html

I was thinking in cpp23 you could use views::cartesian_product to make mdspan into a range. You could convert the extents to a views::iota (0...extent(0) and pass those to views::cartesian_product. The result would be a tuple of coordinates. That we could use to read the value. Maybe we could have a function convert that tuple to a reference to the value. Could maybe wrap the views::cartesian_product with views::transform to get the references if you want that.

I'm not 100% sure on the syntax. I'm not a pro programmer.

CI system setup

To be really production-oriented, we should have a CI system set up and use it as a requirement for merging pull requests.

Could std::extents<> be iterable?

I don't know whether this is the right place for such comments, please let me know if I should move this discussion elsewhere.

I believe it would make a lot of sense to have std::extents be iterable and yield valid nd indices for a basic_mdspan using this extent.

Typically, one would write (with my_span a potentially multi-D mdspan):

std::mdspan<...> my_span(...);
for (auto&& ii: my_span.extents() ) {
  do_something_with(my_span[ii]);
}

From a usability point of view, this would be a huge plus, but maybe this could not be such from a performance point of view:

  • extents<>::iterator should include all but the last boundary in addition to the iterator itself in order to be able to yield a valid std::array<size_t, ...> making it a potentially bloated type,
  • the compilers might not be able to analyze this as good as a set of nested for loops.

Has there been any investigation regarding this or not?

`submdspan` conventions

Is there a reason to use [begin, end[ when taking a submdspan with pairs ? It is a different convention from subspan in std::span that uses the pair (offset, count).

I also noticed that it is a free function whereas in std::span it is a member function.

Thomas P.

Question: Initializing a mdspan with a variadic number of arguments

I have written a simple template class in order to create multidimensional grids with mdspan:

template<typename type, const size_t dimension>
class GridnD
{
public:
  GridnD(typename std::vector<type>::iterator& begin_data,
         typename std::vector<type>::iterator& end_data)
    : data_(begin_data, end_data)
    , grid_(data_.data(), 2, 3, dimension)
    {
      //...
    }

private:
  std::vector<type> data_;
  dynamic_mdspan_of_rank<type, dim + 1> grid_;
};

The dynamic_mdspan_of_rank idea is taken from https://github.com/kokkos/mdspan/issues/32.
My question is, whether there is a possibility to pass a variadic amount of data to grid_.
My goal is to be able to write something along the lines of:

template<typename type, const size_t dimension>
class GridnD
{
public:
  GridnD(typename std::vector<type>::iterator& begin_data,
         typename std::vector<type>::iterator& end_data,
         std::array<int, dimension>& arr)
    : data_(begin_data, end_data)
    , grid_(data_.data(), arr, dimension)
    {
      //...
    }

private:
//...
};

Where arr in this case would be std::array<int, 2> = {2, 3}

Compilation failure with NVCC 11.1.

Errors:
trait_backports.hpp:62 i.e. _MDSPAN_BACKPORT_TRAIT(is_assignable)
1- Constexpr is not valid here.
2- Declaration is incompatible with variable template "std::is_assignable_v"

Attempt to fix: NVCC probably defines these already. Undefine backports before including anything else and see if it goes away.

#include <experimental/__p0009_bits/config.hpp>
#undef _MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS
#include <experimental/mdspan>

Problem gone.

New errors:
fixed_layout_impl.hpp:89 i.e. constexpr /* implicit */ stride_storage_impl(extents_type const& __exts) noexcept : __base_t(__base_t{__exts})
1- Template instantiation resulted in unexpected function type of "std::integral_constant<__nv_bool, true> (std::true_type, std::integer_sequence<ptrdiff_t, -1LL, -1LL, -1LL>, std::integer_sequence<ptrdiff_t, -1LL, -1LL, -1LL>)" (the meaning of a name may have changed since the template declaration -- the type of the template is "std::integral_constant<__nv_bool, > (std::true_type, std::integer_sequence<ptrdiff_t, Extents...>, std::integer_sequence<ptrdiff_t, OtherExtents...>)")

Attempt to fix: CMake appears to have problems with Cuda 11 and recognizing C++17 in NVCC according to an unrelated StackOverflow post. Update CMake from 3.17 to 3.19.
Problem gone.

New errors:
subspan.hpp and layout_right.hpp are throwing a whole bunch of template errors now. Logs:

1>grid_test.cu
1>host_defines.h is an internal header file and must not be used directly.  This file will be removed in a future CUDA release.  Please use cuda_runtime_api.h or cuda_runtime.h instead.
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(95): error C3867: 'std::experimental::detail::fixed_layout_common_impl<std::experimental::extents<-1,-1,-1>,std::integer_sequence<unsigned __int64,0,1,2>,std::experimental::detail::layout_right_idx_conditional>::extents': non-standard syntax; use '&' to create a pointer to member
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\type_traits(636): note: see reference to class template instantiation 'std::experimental::detail::layout_right_impl<std::experimental::extents<-1,-1,-1>>' being compiled
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental/__p0009_bits/basic_mdspan.hpp(135): note: see reference to variable template 'const bool is_constructible_v<std::experimental::detail::layout_right_impl<std::experimental::extents<-1,-1,-1> >,std::experimental::extents<-1,-1,-1> >' being compiled
1>D:/root/source/particle_tracer/tests/grid_test.cu(10): note: see reference to class template instantiation 'std::experimental::basic_mdspan<type,std::experimental::extents<-1,-1,-1>,std::experimental::layout_right,std::experimental::accessor_basic<type>>' being compiled
1>        with
1>        [
1>            type=float
1>        ]
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(95): error C2446: '<': no conversion from 'ptrdiff_t' to 'std::experimental::extents<-1,-1,-1> (__cdecl std::experimental::detail::fixed_layout_common_impl<std::experimental::extents<-1,-1,-1>,std::integer_sequence<unsigned __int64,0,1,2>,std::experimental::detail::layout_right_idx_conditional>::* )(void) noexcept const'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental/__p0009_bits/basic_mdspan.hpp(338): note: There are no conversions from integral values to pointer-to-member values
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(76): error C2974: 'std::experimental::detail::fixed_layout_common_impl': invalid template argument for '<unnamed-symbol>', type expected
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\fixed_layout_impl.hpp(122): note: see declaration of 'std::experimental::detail::fixed_layout_common_impl'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(76): error C2143: syntax error: missing ';' before ','
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(95): error C2059: syntax error: ','
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(95): error C2238: unexpected token(s) preceding ';'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(95): error C2977: 'std::experimental::detail::layout_right_impl': too many template arguments
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(67): note: see declaration of 'std::experimental::detail::layout_right_impl'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C3867: 'std::experimental::detail::fixed_layout_common_impl<std::experimental::extents<-1,-1,-1>,std::integer_sequence<unsigned __int64,0,1,2>,std::experimental::detail::layout_right_idx_conditional>::extents': non-standard syntax; use '&' to create a pointer to member
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2446: '<': no conversion from 'ptrdiff_t' to 'std::experimental::extents<-1,-1,-1> (__cdecl std::experimental::detail::fixed_layout_common_impl<std::experimental::extents<-1,-1,-1>,std::integer_sequence<unsigned __int64,0,1,2>,std::experimental::detail::layout_right_idx_conditional>::* )(void) noexcept const'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental/__p0009_bits/basic_mdspan.hpp(338): note: There are no conversions from integral values to pointer-to-member values
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2977: 'std::experimental::detail::layout_right_impl': too many template arguments
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(67): note: see declaration of 'std::experimental::detail::layout_right_impl'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(86): error C2955: 'std::experimental::detail::layout_right_impl': use of class template requires template argument list
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(67): note: see declaration of 'std::experimental::detail::layout_right_impl'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(86): error C2143: syntax error: missing ')' before '>'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2955: 'std::experimental::detail::layout_right_impl': use of class template requires template argument list
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(67): note: see declaration of 'std::experimental::detail::layout_right_impl'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2059: syntax error: '>'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(86): error C2059: syntax error: '>'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2059: syntax error: 'noexcept'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2238: unexpected token(s) preceding ';'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(87): error C2955: 'std::experimental::detail::layout_right_impl': use of class template requires template argument list
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(67): note: see declaration of 'std::experimental::detail::layout_right_impl'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(87): error C2143: syntax error: missing ')' before '>'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2535: 'std::experimental::detail::layout_right_impl<std::experimental::extents<-1,-1,-1>>::layout_right_impl(const std::experimental::detail::layout_right_impl)': member function already defined or declared
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(86): note: see declaration of 'std::experimental::detail::layout_right_impl<std::experimental::extents<-1,-1,-1>>::layout_right_impl'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(87): error C2059: syntax error: '>'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(88): error C2059: syntax error: '>'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(89): error C2059: syntax error: '>'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(92): error C2974: 'std::experimental::detail::fixed_layout_common_impl': invalid template argument for '<unnamed-symbol>', type expected
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\fixed_layout_impl.hpp(122): note: see declaration of 'std::experimental::detail::fixed_layout_common_impl'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(92): error C2059: syntax error: '>'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(92): error C2039: 'fixed_layout_common_impl': is not a member of '`global namespace''
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2977: 'std::is_convertible_v': too many template arguments
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\type_traits(473): note: see declaration of 'std::is_convertible_v'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2993: 'unknown-type': illegal type for non-type template parameter '_Test'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(95): error C2955: 'std::enable_if': use of class template requires template argument list
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xtr1common(46): note: see declaration of 'std::enable_if'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(95): error C2993: 'std::enable_if': illegal type for non-type template parameter '__formal'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(95): error C2039: 'type': is not a member of '`global namespace''
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2988: unrecognizable template declaration/definition
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2059: syntax error: '<end Parse>'
1>D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\experimental\__p0009_bits\layout_right.hpp(139): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
1>D:/root/source/particle_tracer/tests/grid_test.cu(7): fatal error C1075: '{': no matching token found
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 11.1.targets(785,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX64\x64" -x cu   -ID:\root\source\particle_tracer\include -ID:\root\source\particle_tracer\build -I"D:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.1.216\windows\mpi\intel64\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include" -I"D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include" -I"D:\root\source\particle_tracer\build\vcpkg\installed\x64-windows\include\eigen3" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include"     --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile -cudart static --extended-lambda --expt-relaxed-constexpr -std=c++17 -Xcompiler="/EHsc -Zi -Ob0" -g  -use_fast_math -D_WINDOWS -DNOMINMAX -DPT_DISTRIBUTED_DEVICE=PT_DISTRIBUTED_DEVICE_MPI -DPT_SHARED_DEVICE=PT_SHARED_DEVICE_CUDA -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA -DH5_BUILT_AS_DYNAMIC_LIB -D"CMAKE_INTDIR=\"Debug\"" -DWIN32 -D_WINDOWS -DNOMINMAX -DPT_DISTRIBUTED_DEVICE=PT_DISTRIBUTED_DEVICE_MPI -DPT_SHARED_DEVICE=PT_SHARED_DEVICE_CUDA -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA -DH5_BUILT_AS_DYNAMIC_LIB -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W1 /nologo /Od /Fdgrid_test.dir\Debug\vc142.pdb /FS /Zi /RTC1 /MDd /GR" -o grid_test.dir\Debug\grid_test.obj "D:\root\source\particle_tracer\tests\grid_test.cu"" exited with code 2.
1>Done building project "grid_test.vcxproj" -- FAILED.

Attempt to fix: No clue.

More tests

A lot of the code is still not tested in the tests.

Internal compiler error with Intel 17?

The following "bad pointer" error is obtained when attempting to compile mdspan with Intel 17.0.4:

experimental/__p0009_bits/basic_mdspan.hpp(124): internal error: bad pointer
    MDSPAN_TEMPLATE_REQUIRES(
    ^

Line 124 corresponds to the following code:

  MDSPAN_TEMPLATE_REQUIRES(
    class... IndexType,
    /* requires */ (
      _MDSPAN_FOLD_AND(_MDSPAN_TRAIT(is_convertible, IndexType, index_type) /* && ... */) &&
      (sizeof...(IndexType) == extents_type::rank_dynamic()) &&
      _MDSPAN_TRAIT(is_constructible, mapping_type, extents_type) &&
      _MDSPAN_TRAIT(is_default_constructible, accessor_type)
    )
  )

The compiler flags are:

C FLAGS: -w1 -vec-report0 -diag-disable remark -shared-intel -no-ftz -fma -diag-disable 11060 
     -xHost -qopenmp -g -O0 -inline-level=0 -ftrapuv -check=uninit -fp-model precise -fp-speculation 
     -debug inline-debug-info -fno-omit-frame-pointer -DDEBUG 
CXX FLAGS: -w1 -vec-report0 -diag-disable remark -shared-intel -no-ftz -fma -diag-disable 11060 
     -qopenmp -g -O0 -inline-level=0 -ftrapuv -check=uninit -fp-model precise -fp-speculation safe 
     inline-debug-info -fno-omit-frame-pointer -DDEBUG -early-template-check

Any information on a fix or workaround is much appreciated.

Assigning to a mdspan to const

The snippet below does not seem to compile

namespace stdex = std::experimental;
std::vector<double> v(10);
stdex::mdspan<double, stdex::dynamic_extent> a(v.data(), v.size());
stdex::mdspan<double const, stdex::dynamic_extent> b = a; // This currently does not compile

The compilation error seems to come from the accessor_basic that is not convertible from accessor_basic<double> to accessor_basic<double const>.

I think one might expect to be able to assign a mdspan to a mdspan to const as it is the case for std::span.

A fix could be to add a conversion operator like this one

MDSPAN_INLINE_FUNCTION
constexpr operator accessor_basic<std::add_const_t<ElementType>>() const noexcept {
  return {};
}

Compilation bug regarding `extents`

Bug report

Steps to reproduce

Compile the following snippet.

/// main.cpp
#include <experimental/mdspan>

namespace stdex = std::experimental;

int
main( int argc, char** argv )
{
  constexpr stdex::extents< stdex::dynamic_extent, stdex::dynamic_extent > ext1( 1ul, 1ul );

  constexpr stdex::extents< stdex::dynamic_extent >  ext2( std::array< std::size_t, 1 >{1ul} );

  return 0;
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.21)

project(bug-report LANGUAGES CUDA CXX)

find_package(mdspan CONFIG REQUIRED)

add_executable(bug-report main.cpp)
target_link_libraries(bug-report PUBLIC std::mdspan)
target_compile_features(bug-report PUBLIC cxx_std_17 cuda_std_17)
set_source_files_properties(main.cpp PROPERTIES LANGUAGE CUDA)

Environment

  • mdspan/0.1-0.2
  • nvcc/11.4.48
  • g++/9.2.0
  • cmake/3.21
  • cmake options: CMAKE_CUDA_ARCHITECTURES=70
  • need to disable no_unique_adress feature to avoid problem mentionned in #97 and #65

Expected result

Successful compilation

Actual result

/gpfs/users/tpadioleau/cmake-3.21.3-linux-x86_64/bin/cmake -S/gpfs/users/tpadioleau/bug-report -B/gpfs/users/tpadioleau/bug-report/build --check-build-system CMakeFiles/Makefile.cmake 0
/gpfs/users/tpadioleau/cmake-3.21.3-linux-x86_64/bin/cmake -E cmake_progress_start /gpfs/users/tpadioleau/bug-report/build/CMakeFiles /gpfs/users/tpadioleau/bug-report/build//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1] : on entre dans le rรฉpertoire ยซ /gpfs/users/tpadioleau/bug-report/build ยป
make  -f CMakeFiles/bug-report.dir/build.make CMakeFiles/bug-report.dir/depend
make[2] : on entre dans le rรฉpertoire ยซ /gpfs/users/tpadioleau/bug-report/build ยป
cd /gpfs/users/tpadioleau/bug-report/build && /gpfs/users/tpadioleau/cmake-3.21.3-linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /gpfs/users/tpadioleau/bug-report /gpfs/users/tpadioleau/bug-report /gpfs/users/tpadioleau/bug-report/build /gpfs/users/tpadioleau/bug-report/build /gpfs/users/tpadioleau/bug-report/build/CMakeFiles/bug-report.dir/DependInfo.cmake --color=
make[2] : on quitte le rรฉpertoire ยซ /gpfs/users/tpadioleau/bug-report/build ยป
make  -f CMakeFiles/bug-report.dir/build.make CMakeFiles/bug-report.dir/build
make[2] : on entre dans le rรฉpertoire ยซ /gpfs/users/tpadioleau/bug-report/build ยป
[ 50%] Building CUDA object CMakeFiles/bug-report.dir/main.cpp.o
/gpfs/softs/spack/opt/spack/linux-centos7-cascadelake/gcc-9.2.0/cuda-11.4.0-tqftpmxbgstj4pkv3oeejmc57us33nq2/bin/nvcc -forward-unknown-to-host-compiler  -isystem=/gpfs/users/tpadioleau/opt/include --generate-code=arch=compute_70,code=[compute_70,sm_70] -std=c++17 -MD -MT CMakeFiles/bug-report.dir/main.cpp.o -MF CMakeFiles/bug-report.dir/main.cpp.o.d -x cu -c /gpfs/users/tpadioleau/bug-report/main.cpp -o CMakeFiles/bug-report.dir/main.cpp.o
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/default_accessor.hpp(61): warning: __host__ annotation is ignored on a function("default_accessor") that is explicitly defaulted on its first declaration

/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/default_accessor.hpp(61): warning: __device__ annotation is ignored on a function("default_accessor") that is explicitly defaulted on its first declaration

/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/standard_layout_static_array.hpp(542): warning: __host__ annotation is ignored on a function("__partially_static_sizes_tagged") that is explicitly defaulted on its first declaration

/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/standard_layout_static_array.hpp(542): warning: __device__ annotation is ignored on a function("__partially_static_sizes_tagged") that is explicitly defaulted on its first declaration

/gpfs/users/tpadioleau/bug-report/main.cpp(8): warning: variable "ext1" was declared but never referenced

/gpfs/users/tpadioleau/bug-report/main.cpp(10): warning: variable "ext2" was declared but never referenced

/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/default_accessor.hpp(61): warning: __host__ annotation is ignored on a function("default_accessor") that is explicitly defaulted on its first declaration

/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/default_accessor.hpp(61): warning: __device__ annotation is ignored on a function("default_accessor") that is explicitly defaulted on its first declaration

/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/standard_layout_static_array.hpp(542): warning: __host__ annotation is ignored on a function("__partially_static_sizes_tagged") that is explicitly defaulted on its first declaration

/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/standard_layout_static_array.hpp(542): warning: __device__ annotation is ignored on a function("__partially_static_sizes_tagged") that is explicitly defaulted on its first declaration

/gpfs/users/tpadioleau/bug-report/main.cpp: In function 'int main(int, char**)':
/gpfs/users/tpadioleau/bug-report/main.cpp:10:117: error: no matching function for call to 'std::experimental::extents<18446744073709551615>::extents(std::array<long unsigned int, 1>)'
   10 |   constexpr stdex::extents< stdex::dynamic_extent >  ext2( std::array< std::size_t, 1 >{1ul} );
      |                                                                                                                     ^
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:273:20: note: candidate: 'constexpr std::experimental::extents<Extents>::extents(const __storage_t&) [with long unsigned int ...Extents = {18446744073709551615}; std::experimental::extents<Extents>::__storage_t = std::experimental::detail::__partially_static_sizes_tagged<std::experimental::detail::__extents_tag, 18446744073709551615>]'
  273 |   extents(__storage_t const& sto ) noexcept
      |                    ^~~~~~~
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:273:47: note:   no known conversion for argument 1 from 'std::array<long unsigned int, 1>' to 'const __storage_t&' {aka 'const std::experimental::detail::__partially_static_sizes_tagged<std::experimental::detail::__extents_tag, 18446744073709551615>&'}
  273 |   extents(__storage_t const& sto ) noexcept
      |                            ~~~~~~~~~~~~~~~~   ^  
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:252:1: note: candidate: 'template<class SizeType, long unsigned int N, typename std::enable_if<(((N == std::experimental::extents<18446744073709551615, 18446744073709551615>::rank()) || (N == std::experimental::extents<18446744073709551615, 18446744073709551615>::rank_dynamic())) && is_convertible_v<SizeType, long unsigned int>), int>::type <anonymous> > constexpr std::experimental::extents<Extents>::extents(const std::array<_U, _N>&)'
  252 |   extents(std::array<SizeType, N> const& exts) noexcept
      | ^ ~~~~~
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:252:1: note:   template argument deduction/substitution failed:
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:242:209: error: no type named 'type' in 'struct std::enable_if<false, int>'
  242 |   MDSPAN_TEMPLATE_REQUIRES(
      |                                                                                                                                                                                                                 ^
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:224:1: note: candidate: 'template<class ... Integral, typename std::enable_if<((is_convertible_v<Integral, long unsigned int> && ...) && ((sizeof... (Integral) == std::experimental::extents<18446744073709551615, 18446744073709551615>::rank_dynamic()) || (sizeof... (Integral) == std::experimental::extents<18446744073709551615, 18446744073709551615>::rank()))), int>::type <anonymous> > constexpr std::experimental::extents<Extents>::extents(Integral ...)'
  224 |   explicit constexpr extents(Integral... exts) noexcept
      | ^ ~~~~~
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:224:1: note:   template argument deduction/substitution failed:
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:215:248: error: no type named 'type' in 'struct std::enable_if<false, int>'
  215 |   MDSPAN_TEMPLATE_REQUIRES(
      |                                                                                                                                                                                                                                                        ^
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:200:1: note: candidate: 'template<long unsigned int ...OtherExtents, typename std::enable_if<decltype (std::experimental::detail::_check_compatible_extents(std::integral_constant<bool, (1 == sizeof... (OtherExtents))>{}, std::integer_sequence<long unsigned int, 18446744073709551615>{}, std::integer_sequence<long unsigned int, _Idx ...>{}))::value, int>::type <anonymous> > constexpr std::experimental::extents<Extents>::extents(const std::experimental::extents<OtherExtents ...>&)'
  200 |   constexpr extents(const extents<OtherExtents...>& __other)
      | ^ ~~~~~
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:200:1: note:   template argument deduction/substitution failed:
/gpfs/users/tpadioleau/bug-report/main.cpp:10:117: note:   'std::array<long unsigned int, 1>' is not derived from 'const std::experimental::extents<ExtentsPack ...>'
   10 |   constexpr stdex::extents< stdex::dynamic_extent >  ext2( std::array< std::size_t, 1 >{1ul} );
      |                                                                                                                     ^
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:182:11: note: candidate: 'constexpr std::experimental::extents<Extents>::extents(std::experimental::extents<Extents>&&) [with long unsigned int ...Extents = {18446744073709551615}]'
  182 |   MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents(extents&&) noexcept = default;
      |           ^~~~~~~
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:182:19: note:   no known conversion for argument 1 from 'std::array<long unsigned int, 1>' to 'std::experimental::extents<18446744073709551615>&&'
  182 |   MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents(extents&&) noexcept = default;
      |                   ^~~~~~~~~~
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:181:11: note: candidate: 'constexpr std::experimental::extents<Extents>::extents(const std::experimental::extents<Extents>&) [with long unsigned int ...Extents = {18446744073709551615}]'
  181 |   MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents(extents const&) noexcept = default;
      |           ^~~~~~~
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:181:19: note:   no known conversion for argument 1 from 'std::array<long unsigned int, 1>' to 'const std::experimental::extents<18446744073709551615>&'
  181 |   MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents(extents const&) noexcept = default;
      |                   ^~~~~~~~~~~~~~~
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:180:11: note: candidate: 'std::experimental::extents<Extents>::extents() [with long unsigned int ...Extents = {18446744073709551615}]'
  180 |   MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents() noexcept = default;
      |           ^~~~~~~
/gpfs/users/tpadioleau/opt/include/experimental/__p0009_bits/extents.hpp:180:11: note:   candidate expects 0 arguments, 1 provided
make[2]: *** [CMakeFiles/bug-report.dir/main.cpp.o] Erreur 1
make[2] : on quitte le rรฉpertoire ยซ /gpfs/users/tpadioleau/bug-report/build ยป
make[1]: *** [CMakeFiles/bug-report.dir/all] Erreur 2
make[1] : on quitte le rรฉpertoire ยซ /gpfs/users/tpadioleau/bug-report/build ยป
make: *** [all] Erreur 2

Comments

  • The compiler fails at finding a suitable constructor. More specifically, for ext2 (of type std::experimental::extents<18446744073709551615>) the SFINAE fails at N == std::experimental::extents<18446744073709551615, 18446744073709551615>::rank(), for some reason the compiler seems to be mixing the two classes.

  • If I manually inline the calls to rank() and rank_dynamic() it compiles fine.

  • Fortunately the compiler succeeds to compile if only one of the two extents (ext1 or ext2) is defined.

  • It compiles fine using nvcc/11.4.48 and g++/10.3.0.

gcc-8.1 compilation issue after #19 merged

After #19 was merged, we are seeing the following gcc-8.1 compile error:

In file included from /home/kellyt/draco/src/experimental/mdspan:72,
                 from /home/kellyt/draco/src/experimental/test/tst_mdspan.cc:12:
/home/kellyt/draco/src/experimental/__p0009_bits/layout_stride.hpp:206:1: error: embedding a directive within macro arguments is not portable [-Werror]
 #if defined(__INTEL_COMPILER)
 ^
/home/kellyt/draco/src/experimental/__p0009_bits/layout_stride.hpp:209:1: error: embedding a directive within macro arguments is not portable [-Werror]
 #else
 ^
/home/kellyt/draco/src/experimental/__p0009_bits/layout_stride.hpp:211:1: error: embedding a directive within macro arguments is not portable [-Werror]
 #endif
 ^
  • On a positive note, #19 resolved a fatal build error when we attempt to use intel-17.0.4.

cc: @brryan

Example tiling layout

Could you provide as an example of how to create user defined layouts a simple tiling layout class?

Failed to replicate an example with dynamic extents

Hi! I am developing LAPACK, a library with template implementations of BLAS and LAPACK: https://github.com/tlapack/tlapack/. There is an issue there (tlapack/tlapack#6) where we are discussing the use of mdspan as an abstraction for our multidimensional arrays.

I faild to reproduce your examples with dynamic extents. Please, see here:
https://github.com/tlapack/tlapack/blob/a11034061331343f85fbd1cac1a7af69b19e20a5/include/blas/gemv.hpp#L91-L92
and here:
https://github.com/tlapack/tlapack/blob/a11034061331343f85fbd1cac1a7af69b19e20a5/include/blas/utils.hpp#L24
https://github.com/tlapack/tlapack/blob/a11034061331343f85fbd1cac1a7af69b19e20a5/include/blas/utils.hpp#L50-L52
where I load your library (5694f21).

The code doesn't compile on my Ubuntu 20.04 using GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0. The error message is:

[build] /home/pereiraw/storage/tlapack/include/blas/gemv.hpp:92:15: error: no matching function for call to โ€˜std::experimental::mdspan<float, std::experimental::extents<18446744073709551615, 18446744073709551615>, std::experimental::layout_right, std::experimental::default_accessor<float> >::mdspan(const float*&, blas::size_t&, blas::size_t&)โ€™
[build]    92 |     auto _A = span_2d_dynamic(A, lda, n);
[build]       |               ^~~~~~~~~~~~~~~~~~~~~~~~~~

It is probably something easy to solve. I was trying to mimic the examples here:
https://github.com/kokkos/mdspan/wiki/A-Gentle-Introduction-to-mdspan
and here:
https://github.com/kokkos/mdspan/tree/stable/examples

I would appreciate some help here. Thanks!

Submdspan issue

I am trying the submdspan function and I have unexpected results. Here is my test

#include <array>
#include <cstdint>
#include <experimental/mdspan>
#include <iostream>

using namespace std::experimental;

template <class ET, class EP, class LP, class AP>
void print_layout(mdspan<ET, EP, LP, AP> const &t) {
  if constexpr (std::is_same_v<LP, layout_left>) {
    std::cout << "layout=left";
  } else if constexpr (std::is_same_v<LP, layout_right>) {
    std::cout << "layout=right";
  } else if constexpr (std::is_same_v<LP, layout_stride>) {
    std::cout << "layout=stride";
  }
}

int main(int argc, char **argv) {
  std::array<double, 100> raw{};
  mdspan<double, dextents<2>, layout_right> s(raw.data(), 10, 10);

  std::cout << "Expected: layout=right, strides=[10,1], extents=[10,10]\n";
  std::cout << "Result: ";
  print_layout(s);
  std::cout << ", strides=[" << s.stride(0) << "," << s.stride(1) << "]";
  std::cout << ", extents=[" << s.extent(0) << "," << s.extent(1) << "]" << std::endl;
  std::cout << std::endl;

  auto s1 = submdspan(s, full_extent, std::pair(3ul, 7ul));
  std::cout << "Expected: layout=stride, strides=[10,1], extents=[10,4]\n";
  std::cout << "Result: ";
  print_layout(s1);
  std::cout << ", strides=[" << s1.stride(0) << "," << s1.stride(1) << "]";
  std::cout << ", extents=[" << s1.extent(0) << "," << s1.extent(1) << "]" << std::endl;

  std::cout << std::endl;
  auto s2 = submdspan(s, std::pair(3ul, 7ul), full_extent);
  std::cout << "Expected: layout=right, strides=[10,1], extents=[4,10]\n";
  std::cout << "Result: ";
  print_layout(s2);
  std::cout << ", strides=[" << s2.stride(0) << "," << s2.stride(1) << "]";
  std::cout << ", extents=[" << s2.extent(0) << "," << s2.extent(1) << "]" << std::endl;

  return 0;
}

The output is the following where I print my expectation and the result:

Expected: layout=right, strides=[10,1], extents=[10,10]
Result: layout=right, strides=[10,1], extents=[10,10]

Expected: layout=stride, strides=[10,1], extents=[10,4]
Result: layout=right, strides=[4,1], extents=[10,4]

Expected: layout=right, strides=[10,1], extents=[4,10]
Result: layout=stride, strides=[10,1], extents=[4,10]

Am I missing something ?

Internal compiler error with nvcc + gcc

Hi everyone,

I'm getting a compilation error with nvcc when using gcc as a host compiler. Using clang as a host compiler works, as does a CPU-only compilation. Godbolt link: https://godbolt.org/z/zrhP5zY9W.

Is this a bug, or am I misusing something here?

Thanks alot for your mdspan efforts! Really liking it so far.

Structured bindings for `extents`

The extents class could provide support for structured bindings to improve its usability. This way, we could transform your example from:

  stdex::mdspan m{d.data(), stdex::extents{3, 3}};
  for (std::size_t i = 0; i < m.extent(0); ++i)
    for (std::size_t j = 0; j < m.extent(1); ++j) // was m.extent(0)

to:

  stdex::mdspan m{d.data(), stdex::extents{3, 3}};
  const auto [rows, cols] = m.extents();
  for (std::size_t i = 0; i < rows; ++i)
    for (std::size_t j = 0; j < cols; ++j)

See your modified example: https://godbolt.org/z/enYcvbG8a

It's not a huge improvement, but with increasing rank, it can save some redundant mentioning of m.extents(...). Or prevent accidentially passing the wrong index ;)
It also helps when I pass an instance of extents around without its surrounding mdspan. Then instead of:

const auto x = e.extent(0);
const auto y = e.extent(1);
const auto z = e.extent(2);

I can write:

const auto [x, y, z] = e;

Wrong behavior in seemingly simple test

Hi, this is probably my mistake but while using the (awfully convenient) mdspan I encountered unexpected functionality in my program.

I managed to get a minimal reproduction of the bug:

void test() {
	using Grid =
	    stdex::mdspan<int, stdex::dynamic_extent, stdex::dynamic_extent>;

	// We want a 5x5 grid...
	size_t           width = 5, height = 5;
	std::vector<int> vec(width * height, 0);
	// ...but in C++ array indices start from 0
	Grid grid(vec.data(), width - 1, height - 1);

	for (int i = 0; i <= width; ++i) {
		for (int j = 0; j <= height; ++j) { std::cout << grid(i, j) << ' '; }
		std::cout << '\n';
	}

	std::cout << '\n';
	grid(1, 0) = 1;

	for (int i = 0; i <= width; ++i) {
		for (int j = 0; j <= height; ++j) { std::cout << grid(i, j) << ' '; }
		std::cout << '\n';
	}
}

Running test() produces the following output:

0 0 0 0 0 0 
0 0 0 0 0 0 
0 0 0 0 0 0 
0 0 0 0 0 0 
0 0 0 0 0 0 
0 0 0 0 0 0 

0 0 0 0 1 0 
1 0 0 0 0 0 
0 0 0 0 0 0 
0 0 0 0 0 0 
0 0 0 0 0 0 
0 0 0 0 0 0 

First of all, there's an extra 1 I never set, and in my more complex program this has been happening with some squares in a 5x5 grid (but not all of them). Am I doing something wrong?

Second of all, is the default indexing here row-major or column-major? I'm confused.

I was under the impression that [1, 0] meant "go one along the X axis, and then zero along the Y axis" (I believe this is row-major indexing?) but the results show that it's the opposite - "one along the Y axis and then zero along the X axis". So which one is it in this case?

Sorry for the beginner questions, and thanks in advance.

Issues with Clang 6.0 on Linux when using '-std=c++14 -stdlib=libc++'

On Linux, when using Clang++ 6.0 with the compile options -std=c++14 -stdlib=libc++, the CPP macros __cpp_lib_* used in config.hpp are not available. I needed to copy the logic used for _MDSPAN_COMPILER_APPLECLANG to allow this implementation to work.

In layout_right.hpp, I also needed to avoid a double inline

truct layout_right_idx_conditional {
  MDSPAN_INLINE_FUNCTION_DEFAULTED
  constexpr layout_right_idx_conditional() noexcept = default;
  MDSPAN_FORCE_INLINE_FUNCTION
-   constexpr inline bool operator()(size_t Idx, size_t N) const noexcept {
+   constexpr /*inline*/ bool operator()(size_t Idx, size_t N) const noexcept {
    return Idx > N;
  };
};

and in macros.hpp, I needed to change an #if to an #ifdef

//==============================================================================
// <editor-fold desc="inline variables"> {{{1

-#if _MDSPAN_USE_INLINE_VARIABLES
+#ifdef _MDSPAN_USE_INLINE_VARIABLES
#define _MDSPAN_INLINE_VARIABLE inline
#else
#define _MDSPAN_INLINE_VARIABLE
#endif

Compile failures with clang-cl version 9 (MSVC 2019).

FYI, I can't compile the current version of mdspan when using clang-cl.exe that ships with Visual Studio 2019 (LLVM clang version 9.0). The first couple of build errors are shown below.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\Llvm\bin\clang-cl.exe /c /Z7 /nologo /W0 /WX- /diagnostics:column /FS /Od /D WIN32 /D _WINDOWS /D _CRT_SECURE_NO_DEPRECATE /D _SCL_SECURE_NO_DEPRECATE /D _SECURE_SCL=0 /D DEBUG /D _DEBUG/MDd /D _DEBUG /D _HAS_ITERATOR_DEBUGGING=0 /D __STDC_CONSTANT_MACROS /D _POSIX_C_SOURCE=200112 /D _XOPEN_SOURCE=600 /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /EHa /MDd /GS /Gy /fp:precise /std:c++14 /Fo"Ut_experimental_tst_mdspan_exe.dir\Debug\\" /Gd /TP -m64   /Zc:__cplusplus C:\work\KineticTheory\Draco\src\experimental\test\tst_mdspan.cc
           In file included from C:\work\KineticTheory\Draco\src\experimental\test\tst_mdspan.cc:12:
           In file included from C:\work\KineticTheory\Draco\src\experimental/mdspan:61:
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\array_workaround.hpp(112,3): error : too many arguments provided to function-like macro invocation 
         C:\work\KineticTheory\Draco\src\experimental/__p0009_bits/macros.hpp(150,3): message : expanded from macro 'MDSPAN_FUNCTION_REQUIRES' [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
         C:\work\KineticTheory\Draco\src\experimental/__p0009_bits/macros.hpp(158,17): message : expanded from macro 'MDSPAN_TEMPLATE_REQUIRES' [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
         C:\work\KineticTheory\Draco\src\experimental/__p0009_bits/macros.hpp(124,29): message : expanded from macro 'MDSPAN_PP_CAT' [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
           note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
         (107,1): message : expanded from here [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
         C:\work\KineticTheory\Draco\src\experimental/__p0009_bits/macros.hpp(170,17): message : expanded from macro 'MDSPAN_TEMPLATE_REQUIRES_2' [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
         C:\work\KineticTheory\Draco\src\experimental/__p0009_bits/macros.hpp(147,35): message : expanded from macro 'MDSPAN_CLOSE_ANGLE_REQUIRES' [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
         C:\work\KineticTheory\Draco\src\experimental/__p0009_bits/macros.hpp(123,9): message : macro 'MDSPAN_PP_CAT_IMPL' defined here [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
           In file included from C:\work\KineticTheory\Draco\src\experimental\test\tst_mdspan.cc:12:
           In file included from C:\work\KineticTheory\Draco\src\experimental/mdspan:61:
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\array_workaround.hpp(112,3): error : unknown type name 'MDSPAN_PP_CAT_IMPL' 
         C:\work\KineticTheory\Draco\src\experimental/__p0009_bits/macros.hpp(150,3): message : expanded from macro 'MDSPAN_FUNCTION_REQUIRES' [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
         C:\work\KineticTheory\Draco\src\experimental/__p0009_bits/macros.hpp(158,3): message : expanded from macro 'MDSPAN_TEMPLATE_REQUIRES' [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
         C:\work\KineticTheory\Draco\src\experimental/__p0009_bits/macros.hpp(124,29): message : expanded from macro 'MDSPAN_PP_CAT' [C:\work\vs2019-x64-Clang-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
           In file included from C:\work\KineticTheory\Draco\src\experimental\test\tst_mdspan.cc:12:
           In file included from C:\work\KineticTheory\Draco\src\experimental/mdspan:61:

does not build on osx

os: 10.14.6
clang: Apple LLVM version 10.0.1 (clang-1001.0.46.4)

MacBook-Pro-3:build daniel$ VERBOSE=1 make
/usr/local/Cellar/cmake/3.14.5/bin/cmake -S/Users/daniel/Documents/git/yagol/submodules/mdspan -B/Users/daniel/Documents/git/yagol/submodules/mdspan/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_progress_start /Users/daniel/Documents/git/yagol/submodules/mdspan/build/CMakeFiles /Users/daniel/Documents/git/yagol/submodules/mdspan/build/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f examples/dot_product/CMakeFiles/dot_product.dir/build.make examples/dot_product/CMakeFiles/dot_product.dir/depend
cd /Users/daniel/Documents/git/yagol/submodules/mdspan/build && /usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_depends "Unix Makefiles" /Users/daniel/Documents/git/yagol/submodules/mdspan /Users/daniel/Documents/git/yagol/submodules/mdspan/examples/dot_product /Users/daniel/Documents/git/yagol/submodules/mdspan/build /Users/daniel/Documents/git/yagol/submodules/mdspan/build/examples/dot_product /Users/daniel/Documents/git/yagol/submodules/mdspan/build/examples/dot_product/CMakeFiles/dot_product.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f examples/dot_product/CMakeFiles/dot_product.dir/build.make examples/dot_product/CMakeFiles/dot_product.dir/build
[ 25%] Building CXX object examples/dot_product/CMakeFiles/dot_product.dir/dot_product.cpp.o
cd /Users/daniel/Documents/git/yagol/submodules/mdspan/build/examples/dot_product && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang   -I/Users/daniel/Documents/git/yagol/submodules/mdspan/include  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk   -std=gnu++1z -o CMakeFiles/dot_product.dir/dot_product.cpp.o -c /Users/daniel/Documents/git/yagol/submodules/mdspan/examples/dot_product/dot_product.cpp
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/examples/dot_product/dot_product.cpp:44:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/mdspan:48:
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:89:27: error: reference to 'integer_sequence' is ambiguous
struct __array_impl<T, N, integer_sequence<size_t, Idxs...>>
                          ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/trait_backports.hpp:89:8: note: candidate found by name lookup is 'std::integer_sequence'
struct integer_sequence {
       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:861:29: note: candidate found by name lookup is 'std::__1::integer_sequence'
struct _LIBCPP_TEMPLATE_VIS integer_sequence
                            ^
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/examples/dot_product/dot_product.cpp:44:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/mdspan:48:
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:89:43: error: expected '>'
struct __array_impl<T, N, integer_sequence<size_t, Idxs...>>
                                          ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:89:56: error: expected ';' at end of declaration
struct __array_impl<T, N, integer_sequence<size_t, Idxs...>>
                                                       ^
                                                       ;
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:89:59: error: expected unqualified-id
struct __array_impl<T, N, integer_sequence<size_t, Idxs...>>
                                                          ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:160:37: error: reference to 'make_index_sequence' is ambiguous
struct __array : __array_impl<T, N, make_index_sequence<N>>
                                    ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/trait_backports.hpp:120:1: note: candidate found by name lookup is 'std::make_index_sequence'
using make_index_sequence = typename __detail::__make_int_seq_impl<size_t, N, 0, integer_sequence<size_t>>::type;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:906:5: note: candidate found by name lookup is 'std::__1::make_index_sequence'
    using make_index_sequence = make_integer_sequence<size_t, _Np>;
    ^
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/examples/dot_product/dot_product.cpp:44:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/mdspan:48:
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:160:56: error: expected '>'
struct __array : __array_impl<T, N, make_index_sequence<N>>
                                                       ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:160:56: error: expected class name
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:162:37: error: reference to 'make_index_sequence' is ambiguous
  using base_t = __array_impl<T, N, make_index_sequence<N>>;
                                    ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/trait_backports.hpp:120:1: note: candidate found by name lookup is 'std::make_index_sequence'
using make_index_sequence = typename __detail::__make_int_seq_impl<size_t, N, 0, integer_sequence<size_t>>::type;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:906:5: note: candidate found by name lookup is 'std::__1::make_index_sequence'
    using make_index_sequence = make_integer_sequence<size_t, _Np>;
    ^
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/examples/dot_product/dot_product.cpp:44:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/mdspan:48:
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:162:56: error: expected '>'
  using base_t = __array_impl<T, N, make_index_sequence<N>>;
                                                       ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:162:56: error: expected ';' after alias declaration
  using base_t = __array_impl<T, N, make_index_sequence<N>>;
                                                       ^
                                                       ;
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/array_workaround.hpp:163:9: error: use of undeclared identifier 'base_t'
  using base_t::base_t;
        ^
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/examples/dot_product/dot_product.cpp:44:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/mdspan:49:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/basic_mdspan.hpp:48:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/layout_right.hpp:47:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:46:
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:60:40: error: no template named 'make_index_sequence'; did you mean '__make_integer_sequence'?
template <class SizesSeq, class, class=make_index_sequence<SizesSeq::size()>>
                                       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:879:1: note: '__make_integer_sequence' declared here
using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>;
^
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/examples/dot_product/dot_product.cpp:44:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/mdspan:49:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/basic_mdspan.hpp:48:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/layout_right.hpp:47:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:46:
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:69:3: error: reference to 'integer_sequence' is ambiguous
  integer_sequence<ptrdiff_t, Sizes...>,
  ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/trait_backports.hpp:89:8: note: candidate found by name lookup is 'std::integer_sequence'
struct integer_sequence {
       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:861:29: note: candidate found by name lookup is 'std::__1::integer_sequence'
struct _LIBCPP_TEMPLATE_VIS integer_sequence
                            ^
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/examples/dot_product/dot_product.cpp:44:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/mdspan:49:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/basic_mdspan.hpp:48:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/layout_right.hpp:47:
In file included from /Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:46:
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:69:19: error: expected '>'
  integer_sequence<ptrdiff_t, Sizes...>,
                  ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:64:16: error: template parameter pack must be the last template parameter
  ptrdiff_t... Sizes,
               ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:65:16: error: template parameter pack must be the last template parameter
  ptrdiff_t... DynamicOffsets,
               ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:69:36: error: expected ';' at end of declaration
  integer_sequence<ptrdiff_t, Sizes...>,
                                   ^
                                   ;
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:69:39: error: expected unqualified-id
  integer_sequence<ptrdiff_t, Sizes...>,
                                      ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:200:35: error: reference to 'integer_sequence' is ambiguous
struct _make_mixed_impl_helper<N, integer_sequence<size_t, Idxs...>, integer_sequence<ptrdiff_t, Sizes...>> {
                                  ^
/Users/daniel/Documents/git/yagol/submodules/mdspan/include/experimental/__p0009_bits/trait_backports.hpp:89:8: note: candidate found by name lookup is 'std::integer_sequence'
struct integer_sequence {
       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:861:29: note: candidate found by name lookup is 'std::__1::integer_sequence'
struct _LIBCPP_TEMPLATE_VIS integer_sequence
                            ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [examples/dot_product/CMakeFiles/dot_product.dir/dot_product.cpp.o] Error 1
make[1]: *** [examples/dot_product/CMakeFiles/dot_product.dir/all] Error 2
make: *** [all] Error 2

Consuming mdspan as dependency

I would like to use mdspan in some of my cmake-based projects as a dependency. I found a conan package here. I did not find a package for spack or vcpkg.

Do you have any plans for creating/maintaining packages for the aforementioned package managers?

From a quick look at the CMakeLists.txt, it also looks like one could include mdspan via add_subdirectory. I have not tried it though. Is this a supported/recommended way consuming mdspan in a downstream project? What would you recommend?

Thank you!

Choice of std::size_t for subscripts?

The C++ Core Guidelines recommends signed integers for subscripts (ES.107). Given the need for mdspan in scientific computing, it seems like a signed integer for subscripts would be more appropriate. Also for calling BLAS.

Compilation failure with clang++ and icpx

I cannot compile with clang++ or icpx using submdspan. Is this expected to work?

#include <mdspan>

namespace stdex = std::experimental;

using Cube = stdex::mdspan<float, stdex::dextents<3>>;

void show_tile(float *f) {
    // View it as a 3d array
  Cube cube(f, 4, 4, 4);

    // Slice the cube into 2d tiles
    for (int t = 0; t < cube.extent(0); t++) {
      auto tile = stdex::submdspan(cube, t, stdex::full_extent, stdex::full_extent);
    }
}
rscohn1@vs-sycl-3:3d$ clang++-13 -I /home/rscohn1/local/Projects/dds/dds/repos/mdspan/include/experimental -c simple.cpp -std=gnu++2b
In file included from simple.cpp:2:
In file included from /home/rscohn1/local/Projects/dds/dds/repos/mdspan/include/experimental/mdspan:48:
In file included from /home/rscohn1/local/Projects/dds/dds/repos/mdspan/include/experimental/__p0009_bits/mdspan.hpp:48:
/home/rscohn1/local/Projects/dds/dds/repos/mdspan/include/experimental/__p0009_bits/layout_right.hpp:209:61: error: non-type template argument
      is not a constant expression
      return __get_stride<N>(__extents, make_index_sequence<__extents.rank()>());
                                                            ^~~~~~~~~~~~~~~~
/home/rscohn1/local/Projects/dds/dds/repos/mdspan/include/experimental/__p0009_bits/submdspan.hpp:392:32: note: in instantiation of function
      template specialization 'std::experimental::layout_right::mapping<std::experimental::extents<18446744073709551615, 18446744073709551615,       18446744073709551615>>::__stride<0UL>' requested here
        src.mapping().template __stride<Idxs>()
                               ^
/home/rscohn1/local/Projects/dds/dds/repos/mdspan/include/experimental/__p0009_bits/submdspan.hpp:494:15: note: in instantiation of function
      template specialization 'std::experimental::detail::_submdspan_impl<float, 18446744073709551615UL, 18446744073709551615UL,
      18446744073709551615UL, std::experimental::layout_right, std::experimental::default_accessor<float>, int &,
      std::experimental::full_extent_t &, std::experimental::full_extent_t &, 0UL, 1UL, 2UL>' requested here
      detail::_submdspan_impl(std::make_index_sequence<sizeof...(SliceSpecs)>{}, src, slices...) /*;*/
              ^
simple.cpp:44:28: note: in instantiation of function template specialization 'std::experimental::submdspan<float, 18446744073709551615UL,
      18446744073709551615UL, 18446744073709551615UL, std::experimental::layout_right, std::experimental::default_accessor<float>, int,
      std::experimental::full_extent_t, std::experimental::full_extent_t>' requested here
        auto tile = stdex::submdspan(cube, t, stdex::full_extent, stdex::full_extent);
                           ^
/home/rscohn1/local/Projects/dds/dds/repos/mdspan/include/experimental/__p0009_bits/layout_right.hpp:209:61: note: implicit use of 'this'
      pointer is only allowed within the evaluation of a call to a 'constexpr' member function
      return __get_stride<N>(__extents, make_index_sequence<__extents.rank()>());
                                                            ^
/home/rscohn1/local/Projects/dds/dds/repos/mdspan/include/experimental/__p0009_bits/layout_right.hpp:209:61: error: non-type template argument
      is not a constant expression
      return __get_stride<N>(__extents, make_index_sequence<__extents.rank()>());

preprocessor directives in a macro argument list is UB

The use of preprocessor directives within the macro argument list in lines 206-211 of layout_stride.hpp is undefined behavior. Please consider applying the following patch, which wraps the entirety of the MDSPAN_FUNCTION_REQUIRES macro invocation inside the #if/#else clauses:

--- layout_stride.hpp-orig      2020-04-23 14:59:54.000000000 -0400
+++ layout_stride.hpp   2020-04-23 15:02:54.000000000 -0400
@@ -198,19 +198,27 @@

   // TODO @proposal-bug @proposal-extension layout stride needs this constructor
   // clang-format off
+#if defined(__INTEL_COMPILER)
   MDSPAN_FUNCTION_REQUIRES(
     (MDSPAN_INLINE_FUNCTION constexpr explicit),
     layout_stride_impl, (std::experimental::extents<Exts...> const& e), noexcept,
     /* requires */ (
       // remember that this also covers the zero strides case because an && fold on an empty pack is true
-#if defined(__INTEL_COMPILER)
       // Work-around for an ICE. layout_stride won't properly SFINAE with ICC, but oh well
       true
+    )
+  )
 #else
+  MDSPAN_FUNCTION_REQUIRES(
+    (MDSPAN_INLINE_FUNCTION constexpr explicit),
+    layout_stride_impl, (std::experimental::extents<Exts...> const& e), noexcept,
+    /* requires */ (
+      // remember that this also covers the zero strides case because an && fold on an empty pack is true
       _MDSPAN_FOLD_AND(Strides != dynamic_extent /* && ... */)
-#endif
     )
-  ) : __base_t(__base_t{__member_pair_t(e, __strides_storage_t())})
+  )
+#endif
+  : __base_t(__base_t{__member_pair_t(e, __strides_storage_t())})
   { }
   // clang-format on

@@ -323,4 +331,4 @@
 };

 } // end namespace experimental
-} // end namespace std
\ No newline at end of file
+} // end namespace std

Bugs to fix for P0009R13

@crtrott I compared the current P0009 draft and the mdspan implementation, and found the following inconsistencies and issues.

default_accessor:

  Spec:
    constexpr typename offset_policy::pointer
        offset(pointer p, size_t i) const noexcept;

  impl:
    constexpr pointer
    offset(pointer p, size_t i) const noexcept {
      return p + i;
    }

extents:

  In implementation, not in spec:

  MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents(extents&&) noexcept = default;
  MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED extents& operator=(extents&&) noexcept = default;
  MDSPAN_INLINE_FUNCTION_DEFAULTED ~extents() noexcept = default;

  // in spec; impl claims this should be explicit
  template<class SizeType>
    constexpr extents(const array<SizeType, rank_dynamic()>&) noexcept;

  // impl has operator!=, but spec does not;
  // should be unnecessary due to synthesis of operator!= from operator==

  // impl has CTAD for extents; spec does not
  #if defined(_MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION)
  template <class... SizeTypes>
  extents(SizeTypes...)
    -> extents<detail::__make_dynamic_extent<SizeTypes>()...>;
  #endif

layout_*:

  Spec mapping: missing move constructor and move assignment operator
  Do we want to add move version of OtherExtents constructor?  Not in impl.

  Impl has operator== and operator!=; spec only has operator==

mdspan:

  Spec: using element_type = typename accessor_type::element_type;
  Impl: using element_type = ElementType;

  // noexcept in impl, not in spec
  template<class... SizeTypes>
  explicit constexpr mdspan(pointer p, SizeTypes... dynamic_extents);

  // noexcept in impl, not in spec
  template<class SizeType, size_t N>
  explicit constexpr mdspan(pointer p, const array<SizeType, N>& dynamic_extents);

  // TODO @proposal-bug This is missing from the proposal.
  explicit constexpr mdspan(pointer p, const extents_type& exts)
    noexcept
    : __members(p, __map_acc_pair_t(mapping_type(exts), accessor_type()))
  { }

  // Do the following need noexcept specifications in the spec?
  constexpr mdspan(pointer p, const mapping_type& m);
  constexpr mdspan(pointer p, const mapping_type& m, const accessor_type& a);
  template<class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class OtherAccessorPolicy>
    constexpr mdspan(
      const mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessorPolicy>& other);
  
  // TODO @proposal-bug The proposal is missing constexpr here
  MDSPAN_INLINE_FUNCTION constexpr
  accessor_type accessor() const { return __accessor_ref(); };

  // Spec still has this!  Should we remove it?
  constexpr span<element_type> span() const noexcept;

  // Consistent in both spec and impl,
  // but should this be noexcept in spec?
  // Does the layout mapping not promise that stride is noexcept?
  constexpr size_type stride(size_t r) const { return map_.stride(r); }

mdspan deduction guides:

  // Spec writes layout_type; impl writes layout.  The "TODO" in the implementation's comment is done.

  template <class ElementType, class MappingType>
  mdspan(ElementType*, const MappingType&)
    -> mdspan<ElementType, typename MappingType::extents_type, typename MappingType::layout>;

  template <class ElementType, class MappingType, class AccessorType>
  mdspan(ElementType*, const MappingType&, const AccessorType&)
    -> mdspan<ElementType, typename MappingType::extents_type, typename MappingType::layout, AccessorType>;

Compile error when using `is_contiguous()` on subspan

Using is_contiguous() on a subspan will result in a compile error. Consider following example:

namespace stdex = std::experimental;

std::array<int, 3 * 3> buf;

const stdex::mdspan<int, stdex::dynamic_extent, stdex::dynamic_extent> span(buf.data(),3,3);
const auto subspan = stdex::subspan(span, std::pair(1, 2), std::pair(1, 2));

subspan.is_contiguous(); // will cause build error

The relevant lines in the list of traces msvc is spitting out are the following:

D:\...\mdspan\include\experimental\__p0009_bits\layout_stride.hpp(245): warning C4553: '==': result of expression not used; did you intend '='?
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.29.30129\include\xutility(5637): error C2451: a conditional expression of type 'void' is not valid

The error is caused by a missing return statement in a predicate in the is_contiguous() implementation in layout_stride.hpp:

auto next_idx_iter = std::find_if(
  rem.begin(), rem.end(),
  [&](ptrdiff_t i) { this->stride(i) == 1;  }
  //                ^-- missing return
);

constructing extents from array fails at compile time

My attempts to use the following constructor failed at build time with GCC-10.2.1 configured for C++-17 support in cmake:

template<ptrdiff_t... Extents>
class extents {
  //...
  template<class IndexType>
    constexpr extents(const array<IndexType, rank_dynamic()>&) noexcept;
};

The error is:

In file included from /mdspan_test/vendor/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:50,
                 from /mdspan_test/vendor/mdspan/include/experimental/__p0009_bits/layout_right.hpp:47,
                 from /mdspan_test/vendor/mdspan/include/experimental/__p0009_bits/basic_mdspan.hpp:48,
                 from /mdspan_test/vendor/mdspan/include/experimental/mdspan:48,
                 from /mdspan_test/mdspan_test.cpp:2:
/mdspan_test/vendor/mdspan/include/experimental/__p0009_bits/extents.hpp: In instantiation of โ€˜constexpr std::experimental::extents<Extents>::extents(const std::array<IndexType, std::experimental::extents<Extents>::rank_dynamic()>&) [with IndexType = long unsigned int; typename std::enable_if<is_convertible_v<IndexType, long int>, int>::type <anonymous> = 0; long int ...Extents = {-1, -1, -1}]โ€™:
/mdspan_test/mdspan_test.cpp:11:85:   required from here
/mdspan_test/vendor/mdspan/include/experimental/__p0009_bits/extents.hpp:208:69: error: no type named โ€˜stored_typeโ€™ in โ€˜struct std::experimental::detail::__no_unique_address_emulation<std::experimental::detail::__partially_static_sizes_tagged<std::experimental::detail::__extents_tag, -1, -1, -1>, 0, void>โ€™
  208 |         detail::__construct_psa_from_dynamic_values_tag_t<>{}, dyn}})
      |                                                                     ^

More info including a complete example and the build log can be found at https://github.com/jbigot/mdspan_test

Did I make a mistake in using this constructor?

Backport of no_unique_address

Right now, on non-C++20 compilers, mdspan and other parts of the implementation are space inefficient because the [[no_unique_address]] (written as _MDSPAN_NO_UNIQUE_ADDRESS) does nothing. We need to find a way to backport to the EBO version of no_unique_address without introducing overhead on the newer compilers (and without going crazy with bifurcating the implementation using #ifdefs).

`extents::operator[]`

Allowing some extents to be compile time constants in the extents class is super useful. I generally regard the extents class as an array of compile and runtime indices. As such, I would also like to treat it more like an array and e.g. be allowed to subscript it. So instead of:

  const auto e = stdex::extents{3, 3};
  for (std::size_t i = 0; i < e.extent(0); ++i)
    for (std::size_t j = 0; j < e.extent(1); ++j)

I could write:

  const auto e = stdex::extents{3, 3};
  for (std::size_t i = 0; i < e[0]; ++i)
    for (std::size_t j = 0; j < e[1]; ++j)

Is there a specific reason for not providing operator[] on extents? It would improve its usability a bit.

Shortcut for dynamic multidimensional spans of size S.

Hello,

I had the use case of pairing a linear container and a (dynamic) mdspan to create a basic grid like this:

template <typename type, std::size_t size>
class regular_grid
{
public:
  // Some methods, interpolate etc.

protected:
  thrust::device_vector<type> container_;
  std::experimental::mdspan<type, size> span_; // Bummer! Requires a variadic list of ptrdiff_ts unlike what one would expect.
}

Hence I created (excuse the naming):

template<std::size_t index>
class wrapper
{
  constexpr static auto value = std::experimental::dynamic_extent;
};

template<typename type, std::size_t size, typename = std::make_index_sequence<size>>
struct expander;
template<typename type, std::size_t size, std::size_t... indices>
struct expander<type, size, std::index_sequence<indices...>>
{
  using type = std::experimental::mdspan<type, wrapper<indices>::value...>;
};

template<typename type, std::size_t size>
using dynamic_mdspan_of_rank = typename expander<type, size>::type;

which allows e.g. dynamic_mdspan_of_rank<float, 3> instead of mdspan<float, std::dynamic_extent, std::dynamic_extent, std::dynamic_extent>. The code above is based on a bunch of stackoverflow template expansion posts and the naming is based on dsharlet/array (which I was using prior to mdspan).

Note how this was necessary for a multidimensional struct specified by a type and a number of dimensions to be able to contain a mdspan. I believe this is a common use case. Perhaps you consider a more generalized version into the library.

Edit: Obviously having the regular_grid accept a type and variadic extents is also possible without all this. It however doesn't feel conventional. Perhaps I used boost/multi_array too long.

Conan support

Hi, it would be great to have your library in Conan to simplify its usage by a wider audience. I can help you with that. But first, it would be great to have some official release (0.1.0?) done as it seems that the library is still on 0.0.1 with no release up to now.

inkonsistent cmake config package export

this file should be installed in <prefix>/lib/cmake/MDSpan/

and in a consistent manner: MDSpan*.cmake:

clausklein$ tree /usr/local/cmake/
/usr/local/cmake/
โ”œโ”€โ”€ MDSpanConfig.cmake
โ”œโ”€โ”€ MDSpanConfigVersion.cmake
โ””โ”€โ”€ mdspanTargets.cmake

0 directories, 3 files
clausklein$ 

P0009: noexcept? conditional noexcept?

#69 talks a bit about noexcept specifications. We do not require noexcept for layout mapping or accessor policies. Should we consider conditional noexcept on mdspan methods?

NVIDIA NVCC ICE-1

  • branch: https://github.com/crtrott/mdspan/tree/cuda-ICE-1
  • SHA: f083b6d
  • cmake command:
    cmake -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_CUDA=ON -DMDSPAN_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD=17 -DCMAKE_CUDA_FLAGS="--expt-relaxed-constexpr" ../
  • Version: cmake 3.21.1, GCC 9.2.0, NVCC 11.1, 11.4[from nvhpc] (didn't test others yet)

Error 11.1:

 make
[  5%] Building CXX object tests/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 10%] Linking CXX static library ../../../lib/libgtest.a
[ 10%] Built target gtest
[ 15%] Building CXX object tests/googletest-build/googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 20%] Linking CXX static library ../../../lib/libgtest_main.a
[ 20%] Built target gtest_main
[ 25%] Building CUDA object tests/CMakeFiles/test_mdspan_conversion.dir/test_mdspan_conversion.cpp.o
/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/default_accessor.hpp(61): warning: __host__ annotation is ignored on a function("default_accessor") that is explicitly defaulted on its first declaration

/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/default_accessor.hpp(61): warning: __device__ annotation is ignored on a function("default_accessor") that is explicitly defaulted on its first declaration

/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/standard_layout_static_array.hpp(542): warning: __host__ annotation is ignored on a function("__partially_static_sizes_tagged") that is explicitly defaulted on its first declaration

/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/standard_layout_static_array.hpp(542): warning: __device__ annotation is ignored on a function("__partially_static_sizes_tagged") that is explicitly defaulted on its first declaration

/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/compressed_pair.hpp(59): error: Internal Compiler Error (codegen): "internal error during structure layout!"

make[2]: *** [tests/CMakeFiles/test_mdspan_conversion.dir/test_mdspan_conversion.cpp.o] Error 2
make[1]: *** [tests/CMakeFiles/test_mdspan_conversion.dir/all] Error 2
make: *** [all] Error 2

Error 11.4:

[ 25%] Building CUDA object tests/CMakeFiles/test_mdspan_conversion.dir/test_mdspan_conversion.cpp.o
/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/default_accessor.hpp(61): warning: __host__ annotation is ignored on a function("default_accessor") that is explicitly defaulted on its first declaration

/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/default_accessor.hpp(61): warning: __device__ annotation is ignored on a function("default_accessor") that is explicitly defaulted on its first declaration

/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/standard_layout_static_array.hpp(542): warning: __host__ annotation is ignored on a function("__partially_static_sizes_tagged") that is explicitly defaulted on its first declaration

/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/standard_layout_static_array.hpp(542): warning: __device__ annotation is ignored on a function("__partially_static_sizes_tagged") that is explicitly defaulted on its first declaration

/ascldap/users/crtrott/Kokkos/mdspan/include/experimental/__p0009_bits/compressed_pair.hpp(59): error: Internal Compiler Error (codegen): "internal error during structure layout!"

make[2]: *** [tests/CMakeFiles/test_mdspan_conversion.dir/test_mdspan_conversion.cpp.o] Error 2
make[1]: *** [tests/CMakeFiles/test_mdspan_conversion.dir/all] Error 2

ICE with VisualStudio 16.5.4

#include <experimental/mdspan> in an otherwise empty source file yields the following set of error messages and an ICE:

1>------ Build started: Project: lin_alg_test, Configuration: Debug x64 ------
1>pch.cpp
1>D:\Repos\wg21\linear_algebra\code\extsrc\mdspan\include\experimental\__p0009_bits\trait_backports.hpp(64,1): error C2371: 'std::is_assignable_v': redefinition; different basic types
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\type_traits(683): message : see declaration of 'std::is_assignable_v'
1>D:\Repos\wg21\linear_algebra\code\extsrc\mdspan\include\experimental\__p0009_bits\trait_backports.hpp(65,1): error C2371: 'std::is_constructible_v': redefinition; different basic types
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\type_traits(636): message : see declaration of 'std::is_constructible_v'
1>D:\Repos\wg21\linear_algebra\code\extsrc\mdspan\include\experimental\__p0009_bits\trait_backports.hpp(66,1): error C2371: 'std::is_convertible_v': redefinition; different basic types
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\type_traits(473): message : see declaration of 'std::is_convertible_v'
1>D:\Repos\wg21\linear_algebra\code\extsrc\mdspan\include\experimental\__p0009_bits\trait_backports.hpp(67,1): error C2371: 'std::is_default_constructible_v': redefinition; different basic types
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\type_traits(654): message : see declaration of 'std::is_default_constructible_v'
1>D:\Repos\wg21\linear_algebra\code\extsrc\mdspan\include\experimental\__p0009_bits\trait_backports.hpp(68,1): error C2371: 'std::is_trivially_destructible_v': redefinition; different basic types
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\type_traits(822): message : see declaration of 'std::is_trivially_destructible_v'
1>D:\Repos\wg21\linear_algebra\code\extsrc\mdspan\include\experimental\__p0009_bits\trait_backports.hpp(69,1): error C2371: 'std::is_same_v': redefinition; different basic types
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\xtr1common(79): message : see declaration of 'std::is_same_v'
1>D:\Repos\wg21\linear_algebra\code\extsrc\mdspan\include\experimental\__p0009_bits\trait_backports.hpp(70,1): error C2371: 'std::is_empty_v': redefinition; different basic types
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\type_traits(536): message : see declaration of 'std::is_empty_v'
1>D:\Repos\wg21\linear_algebra\code\extsrc\mdspan\include\experimental\__p0009_bits\trait_backports.hpp(71,1): error C2371: 'std::is_void_v': redefinition; different basic types
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\type_traits(156): message : see declaration of 'std::is_void_v'
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\xstring(4246,5): error C2976: 'std::_Compressed_pair': too few template arguments
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\xmemory(1319): message : see declaration of 'std::_Compressed_pair'
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\xstring(4555): message : see reference to class template instantiation 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' being compiled
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\xstring(4246,3): error C2955: 'std::_Compressed_pair': use of class template requires template argument list
1>C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\include\xmemory(1319): message : see declaration of 'std::_Compressed_pair'
1>D:\Repos\wg21\linear_algebra\code\extsrc\mdspan\include\experimental\__p0009_bits\basic_mdspan.hpp(264,1): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>INTERNAL COMPILER ERROR in 'C:\DevTools\VisualStudio\2019\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\CL.exe'
1>    Please choose the Technical Support command on the Visual C++
1>    Help menu, or open the Technical Support help file for more information
1>Done building project "lin_alg_test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Removed template method used

Get this error when compile benchmarks:
../include/experimental/__p0009_bits/basic_mdspan.hpp(284): error: class "std::integer_sequence<std::size_t, 0UL, 1UL, 2UL>" has no member "__size"

In line basic_mdspan.hpp:103:
using __impl = make_index_sequence<sizeof...(Exts)>;
however std::index_sequence has no member __size

This was a workaround in 76fecc6:
// Can't use defaulted parameter in the __impl_impl template because of a bug in MSVC warning C4348.

Current Plans

Items in order of priority:

  • working on implementing all the changes in P0009R14.
    • Please excuse the churn - naming the branch "stable" was a bit aspirational ...
    • Note we hope that R14 will get full design approval for inclusion in C++23 fingers crossed
    • if that happens we will will tag another release implementing that approved version
  • proper (and tested support) within the context of CUDA, HIP and SYCL
    • we are at the same time working on replacing the guts of Kokkos Core View with mdspan, that will give us indirect testing after the corresponding Kokkos release in millions of lines of code, besides the rather robust Kokkos Core test suite itesle
    • we plan on adding PR testing for mdspan which will build Kokkos Core
  • More comprehensive testing in the mdspan repo itself

Building with MSVC 2019 fails

The commit "Fix building mdspan tests as CUDA code" (6930871) seems to break building with MSVC 2019:

D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(243,1): error C2121: '#': invalid character: possibly the result of a macro expansion
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(277,1): error C2121: '#': invalid character: possibly the result of a macro expansion
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(228,1): error C2760: syntax error: unexpected token 'identifier', expected ')'
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(385): message : see reference to class template instantiation 'std::experimental::extents<Extents...>' being compiled
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(228,1): error C2059: syntax error: ')'
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(228,1): error C2988: unrecognizable template declaration/definition
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(228,1): error C2143: syntax error: missing ';' before '&&'
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(228,1): error C2238: unexpected token(s) preceding ';'
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(228,1): error C2059: syntax error: '&&'
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(249,1): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
D:\a\1\s\build_deps\mdspan-src\include\experimental__p0009_bits\extents.hpp(385,1): fatal error C1903: unable to recover from previous error(s); stopping compilation

Building with GCC and Clang works.

Not compatible with std::vector<bool>

Consider the following code-snippet:

std::vector<bool> boolVec{1,2.3,4,5,6,7,8,9,10,11,12,13,14,15,16};
std::experimental::mdspan m{v.data(),std::experimental::extents{2,4}};

Obviously I'm trying to create a mdspan of a std::vector<bool>, but the following error occurs with CLang 12.0.1:

No viable constructor or deduction guide for deduction of template arguments of 'mdspan'

MacOS Include Order Issue

First of all thanks for the great implementation of mdspan! This is currently used as a dependency in the official repository for the wg21 proposal P1385 for Linear Algebra as based on feedback from the meeting mdspan was seen as the correct abstraction for matrix access.

However, we are unfortunately experiencing some issue with our MacOS build as a result of mdspan relying on the <version> header. The issue it seems is not the fault of mdspan, but the result of Apple-Clang shipping with 2 headers which define the same include guards. Both <version> and <__cxx_version> are declared with:

#ifndef _LIBCPP_VERSIONH
#define _LIBCPP_VERSIONH
...
#endif _LIBCPP_VERSIONH

The upshot of this if you include the wrong header before mdspan, then you accidentally pull in <__cxx_version> first, then when mdspan uses <version> its skips the contents of the file, causing mdspan to unnecessarily define _MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS, causing the build to then fail due to ambiguity around the being multiple definitions of is_empty_v. Here is an example of the build error we see: https://travis-ci.org/github/BobSteagall/wg21/jobs/687745555.

A minimal reproduction case for the error can be produced as such:

main.cpp

#include <iostream>  // <-- causes <__cxx_version> to be included before mdspan
#include <experimental/mdspan>

int main()
{

}

CMakeLists.txt

cmake_minimum_required(VERSION 3.14)

project(mdspan_test)

include(FetchContent)
FetchContent_Declare(mdspan GIT_REPOSITORY https://github.com/kokkos/mdspan.git)
FetchContent_MakeAvailable(mdspan)

add_executable(mdspan_test main.cpp)
target_link_libraries(mdspan_test
    PRIVATE
        std::mdspan
)

set_target_properties(mdspan_test PROPERTIES
    CXX_STANDARD 20
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
)

Anyway, as mentioned this is really an issue with Apple-Clang, but I wanted to bring this to your attention because the unfortunate interaction means users of mdspan have to work around this by ensure mdspan is included first, which is somewhat brittle

Put it on Godbolt

Y'all already have a script for making a single header - it'd be nice to include that single header in the repo (so people can URL include it on Godbolt) or just put this on Godbolt proper through their library support.

`no_unique_address` emulation is broken with GCC 11

[14:15:39]:wash@voyager:/home/wash/development/standards/mdspan/build:127:$ ./config.bash 
-- The CXX compiler identification is GNU 11.1.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++-11 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detected support for C++20 standard
-- Performing Test COMPILER_SUPPORTS_FCONCEPTS
-- Performing Test COMPILER_SUPPORTS_FCONCEPTS - Success
-- Using "-fconcepts" to enable concepts support
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wash/development/standards/mdspan/build/tests/googletest-download
[ 11%] Performing update step for 'googletest'
[ 22%] No patch step for 'googletest'
[ 33%] No configure step for 'googletest'
[ 44%] No build step for 'googletest'
[ 55%] No install step for 'googletest'
[ 66%] No test step for 'googletest'
[ 77%] Completed 'googletest'
[100%] Built target googletest
-- The C compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Python: /usr/bin/python3.9 (found version "3.9.0") found components: Interpreter 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wash/development/standards/mdspan/build
[14:15:42]:wash@voyager:/home/wash/development/standards/mdspan/build:0:$ ./build.bash test_conversion
[ 33%] Built target gtest
[ 66%] Built target gtest_main
Scanning dependencies of target test_conversion
[ 83%] Building CXX object tests/CMakeFiles/test_conversion.dir/test_conversion.cpp.o
[100%] Linking CXX executable test_conversion
/usr/bin/ld: CMakeFiles/test_conversion.dir/test_conversion.cpp.o: in function `std::experimental::detail::stride_storage_impl<std::experimental::extents<2ul, 3ul>, std::integer_sequence<unsigned long, 0ul, 1ul>, std::experimental::detail::layout_right_idx_conditional>::stride_storage_impl(std::experimental::extents<2ul, 3ul> const&)':
test_conversion.cpp:(.text._ZNSt12experimental6detail19stride_storage_implINS_7extentsIJLm2ELm3EEEESt16integer_sequenceImJLm0ELm1EEENS0_28layout_right_idx_conditionalEEC2ERKS3_[_ZNSt12experimental6detail19stride_storage_implINS_7extentsIJLm2ELm3EEEESt16integer_sequenceImJLm0ELm1EEENS0_28layout_right_idx_conditionalEEC2ERKS3_]+0x1f): undefined reference to `std::experimental::detail::__no_unique_address_emulation<std::experimental::extents<2ul, 3ul>, 0ul, void>::__no_unique_address_emulation(std::experimental::extents<2ul, 3ul> const&)'
collect2: error: ld returned 1 exit status
make[3]: *** [tests/CMakeFiles/test_conversion.dir/build.make:105: tests/test_conversion] Error 1
make[2]: *** [CMakeFiles/Makefile2:252: tests/CMakeFiles/test_conversion.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:259: tests/CMakeFiles/test_conversion.dir/rule] Error 2
make: *** [Makefile:207: test_conversion] Error 2
[14:15:49]:wash@voyager:/home/wash/development/standards/mdspan/build:0:$ git show HEAD
commit 96d786a90f2835254157e2e48378b21339af3b8b (HEAD -> stable, origin/stable, origin/HEAD, brycelelbach/stable)
Merge: 690c52c 099da35
Author: Christian Trott <[email protected]>
Date:   Mon Jun 7 22:59:48 2021 -0600

    Merge pull request #53 from brycelelbach/brycelelbach/P0009R12
    
    Explicit constructor fixes, deduction guides, and list initialization/CTAD tests

No clue what's going on here.

Merged pull request #19 breaks Visual Studio 2019 build (x64)

I am attempting to use master after PR #19 was merged in Visual Studio 2019 (The CXX compiler identification is MSVC 19.26.28720.3). There seem to be serious issues with this version.

The first few errors are listed below:

C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\trait_backports.hpp(64,1): error C2371: 'std::is_assignable_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\type_traits(685): message : see declaration of 'std::is_assignable_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\trait_backports.hpp(65,1): error C2371: 'std::is_constructible_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\type_traits(638): message : see declaration of 'std::is_constructible_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\trait_backports.hpp(66,1): error C2371: 'std::is_convertible_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\type_traits(473): message : see declaration of 'std::is_convertible_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\trait_backports.hpp(67,1): error C2371: 'std::is_default_constructible_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\type_traits(656): message : see declaration of 'std::is_default_constructible_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\trait_backports.hpp(68,1): error C2371: 'std::is_trivially_destructible_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\type_traits(824): message : see declaration of 'std::is_trivially_destructible_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\trait_backports.hpp(69,1): error C2371: 'std::is_same_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\xtr1common(79): message : see declaration of 'std::is_same_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\trait_backports.hpp(70,1): error C2371: 'std::is_empty_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\type_traits(536): message : see declaration of 'std::is_empty_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\trait_backports.hpp(71,1): error C2371: 'std::is_void_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\type_traits(156): message : see declaration of 'std::is_void_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\KineticTheory\Draco\src\experimental\__p0009_bits\subspan.hpp(482,1): error C3546: '...': there are no parameter packs available to expand 
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\xstring(4342,5): error C2976: 'std::_Compressed_pair': too few template arguments 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\xmemory(1319): message : see declaration of 'std::_Compressed_pair' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28720\include\xstring(4659): message : see reference to class template instantiation 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' being compiled [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]

Still cannot build mdspan under MSVC 2019

@dhollman In the conclusion to our discussion related to issue #22, you expressed that you have a version of mdspan (master?) working in Visual Studio. You expressed the need to set the compiler option /Zc:__cplusplus, which I have done. Can you provide details concerning the working setup that you are using? I am still unable to build mdspan from Visual Studio 2019.

I am using Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28804.1 for x64 under Visual Studio 2019 v. 16.6.0 Preview 4.0.

  • We are limited to the C++14 standard (CMAKE_CXX_STANDARD 14).
  • CXX FLAGS are /Gy /fp:precise /DWIN32 /D_WINDOWS /MP /wd4251 /arch:AVX2 /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /EHa /Zc:__cplusplus -openmp /W4

The error I see is:

C:\work\kinetictheory\draco\src\experimental\__p0009_bits\trait_backports.hpp(64,1): error C2371: 'std::is_assignable_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\type_traits(685): message : see declaration of 'std::is_assignable_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\kinetictheory\draco\src\experimental\__p0009_bits\trait_backports.hpp(65,1): error C2371: 'std::is_constructible_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\type_traits(638): message : see declaration of 'std::is_constructible_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\kinetictheory\draco\src\experimental\__p0009_bits\trait_backports.hpp(66,1): error C2371: 'std::is_convertible_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\type_traits(473): message : see declaration of 'std::is_convertible_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\kinetictheory\draco\src\experimental\__p0009_bits\trait_backports.hpp(67,1): error C2371: 'std::is_default_constructible_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\type_traits(656): message : see declaration of 'std::is_default_constructible_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\kinetictheory\draco\src\experimental\__p0009_bits\trait_backports.hpp(68,1): error C2371: 'std::is_trivially_destructible_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\type_traits(824): message : see declaration of 'std::is_trivially_destructible_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\kinetictheory\draco\src\experimental\__p0009_bits\trait_backports.hpp(69,1): error C2371: 'std::is_same_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\xtr1common(79): message : see declaration of 'std::is_same_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\kinetictheory\draco\src\experimental\__p0009_bits\trait_backports.hpp(70,1): error C2371: 'std::is_empty_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\type_traits(536): message : see declaration of 'std::is_empty_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\kinetictheory\draco\src\experimental\__p0009_bits\trait_backports.hpp(71,1): error C2371: 'std::is_void_v': redefinition; different basic types 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\type_traits(156): message : see declaration of 'std::is_void_v' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]
C:\work\kinetictheory\draco\src\experimental\__p0009_bits\subspan.hpp(484,1): error C3546: '...': there are no parameter packs available to expand 
    tstFunction_Traits.cc
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\xstring(4342,5): error C2976: 'std::_Compressed_pair': too few template arguments 
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\include\xmemory(1319): message : see declaration of 'std::_Compressed_pair' [C:\work\vs2019-x64-Debug\draco\src\experimental\test\Ut_experimental_tst_mdspan_exe.vcxproj]

I also attempted to build the examples provided in the mdspan repository. Using the attached CMakeSettings.json for option x64-Debug, I ran into the following errors:

CMakeSettings.json.txt

    Checking Build System
    ctest_extents_ctors.vcxproj -> C:\work\vs2019-x64-Debug\mdspan\compilation_tests\Debug\ctest_extents_ctors.exe
    ctest_constexpr_layouts.vcxproj -> C:\work\vs2019-x64-Debug\mdspan\compilation_tests\Debug\ctest_constexpr_layouts.exe
    ctest_constructor_sfinae.vcxproj -> C:\work\vs2019-x64-Debug\mdspan\compilation_tests\Debug\ctest_constructor_sfinae.exe
    Building Custom Rule C:/work/vs2019-x64-Debug/mdspan/tests/googletest-src/googletest/CMakeLists.txt
    ctest_constexpr_subspan.cpp
    ctest_standard_layout.cpp
    ctest_constexpr_dereference.cpp
    ctest_no_unique_address.cpp
    gtest.vcxproj -> C:\work\vs2019-x64-Debug\mdspan\lib\Debug\gtestd.lib
C:\work\kinetictheory\mdspan\compilation_tests\ctest_constexpr_dereference.cpp(80,1): fatal error C1001: Internal compiler error. 
    (compiler file 'msc1.cpp', line 1533)
     To work around this problem, try simplifying or changing the program near the locations listed above.
    If possible please provide a repro here: https://developercommunity.visualstudio.com
    Please choose the Technical Support command on the Visual C++
     Help menu, or open the Technical Support help file for more information
  C:\work\kinetictheory\mdspan\compilation_tests\ctest_constexpr_dereference.cpp(77,1): message : while evaluating constexpr function 'simple_static_sum_test_1' [C:\work\vs2019-x64-Debug\mdspan\compilation_tests\ctest_constexpr_dereference.vcxproj]
    INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\CL.exe'
        Please choose the Technical Support command on the Visual C++
        Help menu, or open the Technical Support help file for more information

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.