Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[do not merge] std::linalg accessors and transposed_layout #2962

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
dee9385
draft of scaled accessor
fbusato Nov 25, 2024
0a33496
add scaled unit test
fbusato Nov 26, 2024
fb03ff2
Merge branch 'main' into linalg-accessors
fbusato Nov 26, 2024
c5c6fa4
add conjugated accessor
fbusato Nov 26, 2024
ce2cc84
refined scaled accessor implementation
fbusato Nov 26, 2024
1bf05d0
add [[nodiscard]]
fbusato Nov 26, 2024
1a261ff
add transposed function
fbusato Nov 26, 2024
8db4036
add conjugate_transposed
fbusato Nov 26, 2024
f48792a
fix internal names
fbusato Nov 26, 2024
67c59f9
replace inline lambda with function object
fbusato Nov 26, 2024
9d913be
add tests
fbusato Nov 26, 2024
77c2d66
Merge branch 'main' into linalg-accessors
fbusato Nov 26, 2024
3d06282
fix c++20 requires clause
fbusato Nov 27, 2024
c3d1464
Merge branch 'main' into linalg-accessors
fbusato Nov 27, 2024
5390bd1
add __cccl_lib_mdspan check
fbusato Nov 27, 2024
626f63a
prevent to include headers if the compiler is not supported
fbusato Nov 27, 2024
baa26f6
skip double noexcept for old compilers
fbusato Nov 27, 2024
4cce6e6
avoid deduction guides to prevent errors with old gcc versions
fbusato Nov 27, 2024
5031fb6
fix #endif position
fbusato Nov 27, 2024
8d20f84
Merge branch 'main' into linalg-accessors
fbusato Nov 27, 2024
bdee5a3
fix clang9/gcc9 compatibility
fbusato Nov 27, 2024
10c0f0a
remove redundant header
fbusato Nov 27, 2024
feed72e
avoid deduction guides for conjugate_transposed
fbusato Nov 27, 2024
30cf216
fix variable shadowing
fbusato Nov 27, 2024
a39d27a
fix nvrtc header bug
fbusato Nov 27, 2024
9699ce5
Merge branch 'main' into linalg-accessors
fbusato Dec 2, 2024
2da684d
relax noexcept(noexcept()) compiler filtering
fbusato Dec 2, 2024
8746de6
adopt concept for conj_if_needed
fbusato Dec 2, 2024
6445b49
add documentation
fbusato Dec 2, 2024
cf34003
fix compiler identification macro
fbusato Dec 3, 2024
ad47459
Update libcudacxx/include/cuda/std/__linalg/conjugate_transposed.h
fbusato Dec 3, 2024
9c621a5
Update libcudacxx/include/cuda/std/__linalg/conjugated.h
fbusato Dec 3, 2024
6d521d8
Update libcudacxx/include/cuda/std/__linalg/conjugated.h
fbusato Dec 3, 2024
ea0038f
Update libcudacxx/include/cuda/std/__linalg/conjugated.h
fbusato Dec 3, 2024
6f18bee
Update libcudacxx/include/cuda/std/__linalg/conjugate_transposed.h
fbusato Dec 3, 2024
4411e5d
add linalg reference in docs
fbusato Dec 3, 2024
22c37f6
fix documentation
fbusato Dec 3, 2024
fe7d176
add linalg header
fbusato Dec 3, 2024
48483f4
change test header
fbusato Dec 3, 2024
7fb5d60
remove redundant namespace specifications
fbusato Dec 3, 2024
627d354
Merge branch 'main' into linalg-accessors
fbusato Dec 3, 2024
b565ad6
add operator!=
fbusato Dec 3, 2024
5af13ad
fix new linalg documentation position
fbusato Dec 3, 2024
103f1b6
fix c++20 require clause
fbusato Dec 3, 2024
377bf53
fix requires expression again
fbusato Dec 3, 2024
eef1e17
remove forward_like duplication in docs
fbusato Dec 4, 2024
de30054
license update
fbusato Dec 5, 2024
8093083
Merge branch 'main' into linalg-accessors
fbusato Dec 5, 2024
140c843
add `unreachable` in standard_api.rst
fbusato Dec 5, 2024
ec199d0
Merge branch 'main' into linalg-accessors
fbusato Dec 18, 2024
71c7211
add missing constexpr
fbusato Dec 18, 2024
7b529bd
remove duplicate line in docs
fbusato Dec 18, 2024
03e7387
split scaled accessor constructors
fbusato Dec 18, 2024
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
11 changes: 10 additions & 1 deletion docs/libcudacxx/standard_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,19 @@ Feature availability:
- ``mdspan`` is feature complete in C++17 onwards.
- ``mdspan`` on msvc is only supported in C++20 and onwards.

- C++26 ``std::dims`` is available in C++17.

- C++26 ``std::linalg`` accessors, transposed layout, and related functions are available in C++17.

- ``scaled()`` and ``scaled_accessor``
- ``conjugated()`` and ``conjugated_accessor``
- ``transposed()`` and ``layout_transpose``
- ``conjugate_transposed()``

- C++23 ``forward_like`` and ``to_underlying`` from ``<utility>`` are available in C++11.

- C++23 ``is_scoped_enum`` in ``<type_traits>`` is available in C++11.

- C++26 ``std::dims`` is available in C++17.
- C++23 ``to_underlying`` from ``<utility>`` is available in C++11.

fbusato marked this conversation as resolved.
Show resolved Hide resolved
- C++26 tuple protocol to ``complex`` is available in C++11.
1 change: 1 addition & 0 deletions docs/libcudacxx/standard_api/numerics_library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Numerics Library
numerics_library/bit
numerics_library/complex
numerics_library/numeric
numerics_library/linalg

Any Standard C++ header not listed below is omitted.

Expand Down
31 changes: 31 additions & 0 deletions docs/libcudacxx/standard_api/numerics_library/linalg.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. _libcudacxx-standard-api-numerics-linalg:

``<cuda/std/linalg>``
============================================

Provided functionalities
------------------------

- ``scaled()`` `std::linalg::scaled <https://en.cppreference.com/w/cpp/numeric/linalg/scaled>`_
- ``scaled_accessor`` `std::linalg::scaled_accessor <https://en.cppreference.com/w/cpp/numeric/linalg/scaled_accessor>`_
- ``conjugated()`` `std::linalg::conjugated <https://en.cppreference.com/w/cpp/numeric/linalg/conjugated>`_
- ``conjugated_accessor`` `std::linalg::conjugated_accessor <https://en.cppreference.com/w/cpp/numeric/linalg/conjugated_accessor>`_
- ``transposed()`` `std::linalg::transposed <https://en.cppreference.com/w/cpp/numeric/linalg/transposed>`_
- ``layout_transpose`` `std::linalg::layout_transpose <https://en.cppreference.com/w/cpp/numeric/linalg/layout_transpose>`_
- ``conjugate_transposed()`` `std::linalg::conjugate_transposed <https://en.cppreference.com/w/cpp/numeric/linalg/conjugate_transposed>`_

Extensions
----------

- C++26 ``std::linalg`` accessors, transposed layout, and related functions are available in C++17

Omissions
---------

- Currently we do not expose any BLAS functions and layouts.

Restrictions
------------

- On device no exceptions are thrown in case of a bad access.
- MSVC is only supported with C++20
106 changes: 106 additions & 0 deletions libcudacxx/include/cuda/std/__linalg/conj_if_needed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 2.0
// Copyright (2019) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software. //
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
//
// ************************************************************************
//@HEADER
*/
fbusato marked this conversation as resolved.
Show resolved Hide resolved
#ifndef _LIBCUDACXX___LINALG_CONJUGATE_IF_NEEDED_HPP
#define _LIBCUDACXX___LINALG_CONJUGATE_IF_NEEDED_HPP

#include <cuda/std/detail/__config>

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header

#include <cuda/std/version>

#if defined(__cccl_lib_mdspan) && _CCCL_STD_VER >= 2017

# include <cuda/std/__concepts/concept_macros.h>
# include <cuda/std/__type_traits/integral_constant.h>
# include <cuda/std/__type_traits/is_arithmetic.h>
# include <cuda/std/__type_traits/remove_const.h>
# include <cuda/std/__type_traits/void_t.h>
# include <cuda/std/__utility/declval.h>
# include <cuda/std/complex>

_LIBCUDACXX_BEGIN_NAMESPACE_STD

namespace linalg
{

_LIBCUDACXX_BEGIN_NAMESPACE_CPO(__conj_if_needed)

template <class _Type>
_CCCL_CONCEPT _HasConj = _CCCL_REQUIRES_EXPR((_Type), _Type __a)(static_cast<void>(_CUDA_VSTD::conj(__a)));

struct __conj_if_needed
{
template <class _Type>
_LIBCUDACXX_HIDE_FROM_ABI constexpr auto operator()(const _Type& __t) const
{
if constexpr (is_arithmetic_v<_Type> || !_HasConj<_Type>)
{
return __t;
}
else
{
return _CUDA_VSTD::conj(__t);
}
_CCCL_UNREACHABLE();
}
};

_LIBCUDACXX_END_NAMESPACE_CPO

inline namespace __cpo
{
_CCCL_GLOBAL_CONSTANT auto conj_if_needed = __conj_if_needed::__conj_if_needed{};

} // namespace __cpo
} // end namespace linalg

_LIBCUDACXX_END_NAMESPACE_STD

#endif // defined(__cccl_lib_mdspan) && _CCCL_STD_VER >= 2017
#endif // _LIBCUDACXX___LINALG_CONJUGATED_HPP
79 changes: 79 additions & 0 deletions libcudacxx/include/cuda/std/__linalg/conjugate_transposed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 2.0
// Copyright (2019) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software. //
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: I assume we have this license header because the implementation was taken over from Kokkos. But should we remove Christian Trott as contact for question nevertheless? I don't know whether he wants to answer to bugs in libcu++ :)

Copy link
Collaborator

@miscco miscco Nov 30, 2024

Choose a reason for hiding this comment

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

The mdspan implementation for llvm is licensed differently: https://github.com/llvm/llvm-project/blob/main/libcxx/include/__mdspan/mdspan.h

We should reach out to the kokkos project to see if they would agree to a similar license

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, Christian is fine with it

//
// ************************************************************************
//@HEADER
*/
#ifndef _LIBCUDACXX___LINALG_CONJUGATE_TRANSPOSED_HPP
#define _LIBCUDACXX___LINALG_CONJUGATE_TRANSPOSED_HPP

#include <cuda/std/detail/__config>

#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header

#include <cuda/std/version>

#if defined(__cccl_lib_mdspan) && _CCCL_STD_VER >= 2017

# include <cuda/std/__linalg/conjugated.h>
# include <cuda/std/__linalg/transposed.h>

_LIBCUDACXX_BEGIN_NAMESPACE_STD

namespace linalg
{

template <class _ElementType, class _Extents, class _Layout, class _Accessor>
_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI auto
conjugate_transposed(mdspan<_ElementType, _Extents, _Layout, _Accessor> __a)
fbusato marked this conversation as resolved.
Show resolved Hide resolved
{
return conjugated(transposed(__a));
}

} // end namespace linalg

_LIBCUDACXX_END_NAMESPACE_STD

#endif // defined(__cccl_lib_mdspan) && _CCCL_STD_VER >= 2017
#endif // _LIBCUDACXX___LINALG_CONJUGATE_TRANSPOSED_HPP
Loading
Loading