Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ jobs:

test-stdBLAS:
runs-on: ubuntu-latest
container:
image: amklinv/mdspan-dependencies:latest
needs: build-stdblas

steps:
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ option(LINALG_ENABLE_BLAS
"Assume that we are linking with a BLAS library."
${BLAS_FOUND})

find_package(TBB)
option(LINALG_ENABLE_TBB
"Enable TBB. Default: autodetect TBB installation."
${TBB_FOUND})
if(LINALG_ENABLE_TBB)
find_package(TBB REQUIRED)
endif()

find_package(KokkosKernels)
option(LINALG_ENABLE_KOKKOS
"Enable Kokkos-based implementation. Default: autodetect Kokkos installation."
Expand All @@ -144,6 +152,10 @@ add_library(std::linalg ALIAS linalg)

target_link_libraries(linalg INTERFACE std::mdspan)

if(LINALG_ENABLE_TBB)
target_link_libraries(linalg INTERFACE TBB::tbb)
endif()

if(LINALG_ENABLE_KOKKOS)
target_link_libraries(linalg INTERFACE Kokkos::kokkos)
target_link_libraries(linalg INTERFACE Kokkos::kokkoskernels)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Other compilers, including MSVC 2019, have been tested in the past.
- If you want to build examples, set LINALG_ENABLE_EXAMPLES=ON
- If you have a BLAS installation, set LINALG_ENABLE_BLAS=ON.
BLAS support is currently experimental.
- If you have a TBB installation, set LINALG_ENABLE_TBB=ON.
TBB support is currently experimental.
4. Build and install as usual
5. If you enabled tests, use "ctest" to run them

Expand Down
16 changes: 4 additions & 12 deletions examples/01_scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@

#include <iostream>

#if (! defined(__GNUC__)) || (__GNUC__ > 9)
# define MDSPAN_EXAMPLES_USE_EXECUTION_POLICIES 1
#endif

#ifdef MDSPAN_EXAMPLES_USE_EXECUTION_POLICIES
# include <execution>
#endif

// Make mdspan less verbose
using std::experimental::mdspan;
using std::experimental::extents;
using std::experimental::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;

int main(int argc, char* argv[]) {
std::cout << "Scale" << std::endl;
Expand All @@ -30,7 +22,7 @@ int main(int argc, char* argv[]) {

// Call linalg::scale x = 2.0*x;
std::experimental::linalg::scale(2.0, x);
#ifdef MDSPAN_EXAMPLES_USE_EXECUTION_POLICIES

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new macro is nicer; thank you! : - )

#ifdef LINALG_HAS_EXECUTION
std::experimental::linalg::scale(std::execution::par, 2.0, x);
#else
std::experimental::linalg::scale(2.0, x);
Expand Down
16 changes: 4 additions & 12 deletions examples/02_matrix_vector_product_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@

#include <iostream>

#if (! defined(__GNUC__)) || (__GNUC__ > 9)
# define MDSPAN_EXAMPLES_USE_EXECUTION_POLICIES 1
#endif

#ifdef MDSPAN_EXAMPLES_USE_EXECUTION_POLICIES
# include <execution>
#endif

// Make mdspan less verbose
using std::experimental::mdspan;
using std::experimental::extents;
using std::experimental::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;

int main(int argc, char* argv[]) {
std::cout << "Matrix Vector Product Basic" << std::endl;
Expand Down Expand Up @@ -41,7 +33,7 @@ int main(int argc, char* argv[]) {
std::experimental::linalg::matrix_vector_product(A, x, y);

// y = 0.5 * y + 2 * A * x
#ifdef MDSPAN_EXAMPLES_USE_EXECUTION_POLICIES
#ifdef LINALG_HAS_EXECUTION
std::experimental::linalg::matrix_vector_product(std::execution::par,
std::experimental::linalg::scaled(2.0, A), x,
std::experimental::linalg::scaled(0.5, y), y);
Expand Down
8 changes: 4 additions & 4 deletions examples/03_matrix_vector_product_mixedprec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include <iostream>

// Make mdspan less verbose
using std::experimental::mdspan;
using std::experimental::extents;
using std::experimental::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using std::experimental::submdspan;
using std::experimental::full_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent;

int main(int argc, char* argv[]) {
std::cout << "Matrix Vector Product MixedPrec" << std::endl;
Expand Down
1 change: 1 addition & 0 deletions include/experimental/__p1673_bits/linalg_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
#cmakedefine LINALG_ENABLE_CONCEPTS
#cmakedefine LINALG_ENABLE_KOKKOS
#cmakedefine LINALG_ENABLE_KOKKOS_DEFAULT
#cmakedefine LINALG_ENABLE_TBB
14 changes: 12 additions & 2 deletions include/experimental/__p1673_bits/linalg_execpolicy_mapper.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// For GCC 9 (< 10), <execution> unconditionally includes a TBB header file.
// If GCC < 10 was not built with TBB support, this causes a build error.
#if (! defined(__GNUC__)) || (__GNUC__ > 9)
#ifdef LINALG_HAS_EXECUTION
#include <execution>
#endif

Expand Down Expand Up @@ -39,7 +39,17 @@ namespace experimental {
inline namespace __p1673_version_0 {
namespace linalg {
template<class T>
auto execpolicy_mapper(T) { return std::experimental::linalg::impl::inline_exec_t(); }
auto execpolicy_mapper(const T) {
return std::experimental::linalg::impl::inline_exec_t();
}

#ifdef LINALG_HAS_EXECUTION
template<>
auto execpolicy_mapper(const std::execution::parallel_policy) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to fix this bit -- the return type of execpolicy_mapper must always differ from its input type. The idiomatic approach is to return a hidden implementation-only type.

return std::execution::par;
}
#endif

}
}
}
Expand Down
24 changes: 24 additions & 0 deletions include/experimental/__p1673_bits/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@
#ifndef LINALG_INCLUDE_EXPERIMENTAL___P1673_BITS_MACROS_HPP_
#define LINALG_INCLUDE_EXPERIMENTAL___P1673_BITS_MACROS_HPP_

#ifdef _MSVC_LANG

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea : - )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I stole it from Kokkos!

#define _LINALG_CPLUSPLUS _MSVC_LANG
#else
#define _LINALG_CPLUSPLUS __cplusplus
#endif

#define LINALG_CXX_STD_14 201402L
#define LINALG_CXX_STD_17 201703L
#define LINALG_CXX_STD_20 202002L

#define LINALG_HAS_CXX_14 (_LINALG_CPLUSPLUS >= LINALG_CXX_STD_14)
#define LINALG_HAS_CXX_17 (_LINALG_CPLUSPLUS >= LINALG_CXX_STD_17)
#define LINALG_HAS_CXX_20 (_LINALG_CPLUSPLUS >= LINALG_CXX_STD_20)

static_assert(_LINALG_CPLUSPLUS >= LINALG_CXX_STD_17, "stdBLAS requires C++17 or later.");

#if ! defined(__clang__) && ! defined(_MSC_VER) && defined(__GNUC__)
# if defined(LINALG_ENABLE_TBB)
# define LINALG_HAS_EXECUTION 1
# endif
#else
# define LINALG_HAS_EXECUTION 1
#endif

#define P1673_MATRIX_EXTENTS_TEMPLATE_PARAMETERS( MATRIX_NAME ) \
class SizeType_ ## MATRIX_NAME , \
::std::size_t numRows_ ## MATRIX_NAME , \
Expand Down
6 changes: 3 additions & 3 deletions tests/native/add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <vector>

namespace {
using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using std::experimental::linalg::add;

TEST(BLAS1_add, vector_double)
Expand Down
6 changes: 3 additions & 3 deletions tests/native/conjugate_transposed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <vector>

namespace {
using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using std::experimental::linalg::conjugate_transposed;

TEST(conjugate_transposed, mdspan_complex_double)
Expand Down
8 changes: 4 additions & 4 deletions tests/native/conjugated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include <vector>

namespace {
using std::experimental::dextents;
using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dextents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using std::experimental::linalg::conjugated;

template<class ValueType>
Expand Down
6 changes: 3 additions & 3 deletions tests/native/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <vector>

namespace {
using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using std::experimental::linalg::copy;

template<class Real>
Expand Down
6 changes: 3 additions & 3 deletions tests/native/dot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ double ddot_wrapper (const int N, const double* DX,
#endif // 0

namespace {
using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using std::experimental::linalg::dot;
using std::experimental::linalg::dotc;

Expand Down
8 changes: 4 additions & 4 deletions tests/native/gemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include <iostream>

namespace {
using std::experimental::mdspan;
using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::layout_left;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::layout_left;
using std::experimental::linalg::explicit_diagonal;
using std::experimental::linalg::implicit_unit_diagonal;
using std::experimental::linalg::lower_triangle;
Expand Down
8 changes: 4 additions & 4 deletions tests/native/gemv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include <iostream>

namespace {
using std::experimental::mdspan;
using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::layout_left;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::layout_left;
using std::experimental::linalg::matrix_vector_product;
using std::experimental::linalg::transposed;
using std::cout;
Expand Down
15 changes: 4 additions & 11 deletions tests/native/gemv_no_ambig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@
#include <vector>
#include <iostream>

#if (! defined(__GNUC__)) || (__GNUC__ > 9)
# define MDSPAN_EXAMPLES_USE_EXECUTION_POLICIES 1
#endif
#ifdef MDSPAN_EXAMPLES_USE_EXECUTION_POLICIES
# include <execution>
#endif

namespace {

using std::experimental::mdspan;
using std::experimental::extents;
using std::experimental::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using std::experimental::linalg::matrix_vector_product;
using std::experimental::linalg::scaled;

Expand Down Expand Up @@ -49,7 +42,7 @@ TEST(gemv, no_ambiguity)
scaled(2.0, A), x,
scaled(0.5, y), y);

#ifdef MDSPAN_EXAMPLES_USE_EXECUTION_POLICIES
#ifdef LINALG_HAS_EXECUTION
matrix_vector_product(std::execution::par,
scaled(2.0, A), x,
scaled(0.5, y), y);
Expand Down
6 changes: 3 additions & 3 deletions tests/native/givens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <vector>

namespace {
using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using std::experimental::linalg::givens_rotation_setup;
using std::experimental::linalg::givens_rotation_apply;

Expand Down
6 changes: 3 additions & 3 deletions tests/native/gtest_fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
#include <complex>
#include <vector>

using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using dbl_vector_t = mdspan<double, extents<std::size_t, dynamic_extent>>;
using cpx_vector_t = mdspan<std::complex<double>, extents<std::size_t, dynamic_extent>>;
constexpr ptrdiff_t NROWS(10);
Expand Down
8 changes: 4 additions & 4 deletions tests/native/hemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include <vector>

namespace {
using std::experimental::mdspan;
using std::experimental::dynamic_extent;
using std::experimental::extents;
using std::experimental::layout_left;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::layout_left;
using std::experimental::linalg::explicit_diagonal;
using std::experimental::linalg::implicit_unit_diagonal;
using std::experimental::linalg::lower_triangle;
Expand Down
14 changes: 7 additions & 7 deletions tests/native/idx_abs_max.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <vector>

namespace {

using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using std::experimental::linalg::idx_abs_max;

TEST_F(unsigned_double_vector, idx_abs_max)
Expand All @@ -26,17 +28,15 @@ namespace {

TEST(BLAS1_idx_abs_max, trivial_case)
{
namespace stdexp = std::experimental;

constexpr auto expected = std::numeric_limits<std::size_t>::max();

std::array<double, 0> arr;
using extents_type = stdexp::extents<std::size_t, stdexp::dynamic_extent>;
stdexp::mdspan<double, extents_type> a(arr.data(),0);
using extents_type = extents<std::size_t, dynamic_extent>;
mdspan<double, extents_type> a(arr.data(),0);
EXPECT_EQ(expected, idx_abs_max(a));

using extents_type2 = stdexp::extents<std::size_t, 0>;
stdexp::mdspan<double, extents_type2> b(arr.data());
using extents_type2 = extents<std::size_t, 0>;
mdspan<double, extents_type2> b(arr.data());
EXPECT_EQ(expected, idx_abs_max(b));
}

Expand Down
Loading