Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
static_array.h326 linesDownload Raw Back to __mdspan
1/*2//@HEADER3// ************************************************************************4//5//                        Kokkos v. 2.06//              Copyright (2019) Sandia Corporation7//8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,9// the U.S. Government retains certain rights in this software.10//11// Redistribution and use in source and binary forms, with or without12// modification, are permitted provided that the following conditions are13// met:14//15// 1. Redistributions of source code must retain the above copyright16// notice, this list of conditions and the following disclaimer.17//18// 2. Redistributions in binary form must reproduce the above copyright19// notice, this list of conditions and the following disclaimer in the20// documentation and/or other materials provided with the distribution.21//22// 3. Neither the name of the Corporation nor the names of the23// contributors may be used to endorse or promote products derived from24// this software without specific prior written permission.25//26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.37//38// Questions? Contact Christian R. Trott (crtrott@sandia.gov)39//40// ************************************************************************41//@HEADER42*/43 44#ifndef _LIBCUDACXX___MDSPAN_STATIC_ARRAY_HPP45#define _LIBCUDACXX___MDSPAN_STATIC_ARRAY_HPP46 47#ifndef __cuda_std__48#include <__config>49#endif // __cuda_std__50 51#include "../__fwd/span.h" // dynamic_extent52#include "../__mdspan/dynamic_extent.h"53#include "../__mdspan/macros.h"54#include "../__mdspan/maybe_static_value.h"55#include "../__mdspan/standard_layout_static_array.h"56#include "../__mdspan/type_list.h"57#include "../__utility/integer_sequence.h"58#include "../array"59#include "../cstddef"60 61#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)62#  pragma GCC system_header63#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)64#  pragma clang system_header65#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)66#  pragma system_header67#endif // no system header68 69#if !__MDSPAN_PRESERVE_STANDARD_LAYOUT70 71_LIBCUDACXX_BEGIN_NAMESPACE_STD72 73#if _LIBCUDACXX_STD_VER > 1174 75namespace __detail {76 77//==============================================================================78 79template <class _Tp, _Tp _Val, bool _Mask> struct __mask_element {};80 81template <class _Tp, _Tp... _Result>82struct __mask_sequence_assign_op {83  template <_Tp _V>84  __mask_sequence_assign_op<_Tp, _Result..., _V>85  operator=(__mask_element<_Tp, _V, true>&&);86  template <_Tp _V>87  __mask_sequence_assign_op<_Tp, _Result...>88  operator=(__mask_element<_Tp, _V, false>&&);89  using __result = _CUDA_VSTD::integer_sequence<_Tp, _Result...>;90};91 92template <class _Seq, class _Mask>93struct __mask_sequence;94 95template <class _Tp, _Tp... _Vals, bool... _Masks>96struct __mask_sequence<_CUDA_VSTD::integer_sequence<_Tp, _Vals...>, _CUDA_VSTD::integer_sequence<bool, _Masks...>>97{98  using type = typename decltype(99    __MDSPAN_FOLD_ASSIGN_LEFT(100      __mask_sequence_assign_op<_Tp>{}, /* = ... = */ __mask_element<_Tp, _Vals, _Masks>{}101    )102  )::__result;103};104 105//==============================================================================106 107template <class _Tp, class _static_t, class _Vals, _static_t __sentinal,108          class _Idxs, class _IdxsDynamic, class _IdxsDynamicIdxs>109class __partially_static_array_impl;110 111template <112  class _Tp, class _static_t,113  _static_t... __values_or_sentinals, _static_t __sentinal,114  size_t... _Idxs,115  size_t... _IdxsDynamic,116  size_t... _IdxsDynamicIdxs117>118class __partially_static_array_impl<119  _Tp,120  _static_t,121  _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>,122  __sentinal,123  _CUDA_VSTD::integer_sequence<size_t, _Idxs...>,124  _CUDA_VSTD::integer_sequence<size_t, _IdxsDynamic...>,125  _CUDA_VSTD::integer_sequence<size_t, _IdxsDynamicIdxs...>126>127    : private __maybe_static_value<_Tp, _static_t, __values_or_sentinals, __sentinal,128                                   _Idxs>... {129private:130 131  template <size_t _Np>132  using __base_n = typename __type_at<_Np,133    __type_list<__maybe_static_value<_Tp, _static_t, __values_or_sentinals, __sentinal, _Idxs>...>134  >::type;135 136public:137 138  static constexpr auto __size = sizeof...(_Idxs);139  static constexpr auto __size_dynamic =140    __MDSPAN_FOLD_PLUS_RIGHT(static_cast<int>((__values_or_sentinals == __sentinal)), /* + ... + */ 0);141 142  //--------------------------------------------------------------------------143 144  __MDSPAN_INLINE_FUNCTION_DEFAULTED145  constexpr __partially_static_array_impl() = default;146  __MDSPAN_INLINE_FUNCTION_DEFAULTED147  constexpr __partially_static_array_impl(148      __partially_static_array_impl const &) noexcept = default;149  __MDSPAN_INLINE_FUNCTION_DEFAULTED150  constexpr __partially_static_array_impl(151      __partially_static_array_impl &&) noexcept = default;152  __MDSPAN_INLINE_FUNCTION_DEFAULTED153  __MDSPAN_CONSTEXPR_14_DEFAULTED __partially_static_array_impl &154  operator=(__partially_static_array_impl const &) noexcept = default;155  __MDSPAN_INLINE_FUNCTION_DEFAULTED156  __MDSPAN_CONSTEXPR_14_DEFAULTED __partially_static_array_impl &157  operator=(__partially_static_array_impl &&) noexcept = default;158  __MDSPAN_INLINE_FUNCTION_DEFAULTED159  ~__partially_static_array_impl() noexcept = default;160 161  __MDSPAN_INLINE_FUNCTION162  constexpr __partially_static_array_impl(163      __construct_psa_from_all_exts_values_tag_t,164      __repeated_with_idxs<_Idxs, _Tp> const &... __vals) noexcept165      : __base_n<_Idxs>(__base_n<_Idxs>{{__vals}})... {}166 167  __MDSPAN_INLINE_FUNCTION168  constexpr __partially_static_array_impl(169      __construct_psa_from_dynamic_exts_values_tag_t,170      __repeated_with_idxs<_IdxsDynamicIdxs, _Tp> const &... __vals) noexcept171      : __base_n<_IdxsDynamic>(__base_n<_IdxsDynamic>{{__vals}})... {}172 173  __MDSPAN_INLINE_FUNCTION constexpr explicit __partially_static_array_impl(174    _CUDA_VSTD::array<_Tp, sizeof...(_Idxs)> const& __vals) noexcept175    : __partially_static_array_impl(176        __construct_psa_from_all_exts_values_tag,177        _CUDA_VSTD::get<_Idxs>(__vals)...) {}178 179  // clang-format off180  __MDSPAN_FUNCTION_REQUIRES(181    (__MDSPAN_INLINE_FUNCTION constexpr explicit),182    __partially_static_array_impl,183    (_CUDA_VSTD::array<_Tp, __size_dynamic> const &__vals), noexcept,184    /* requires */185      (sizeof...(_Idxs) != __size_dynamic)186  ): __partially_static_array_impl(187       __construct_psa_from_dynamic_exts_values_tag,188       _CUDA_VSTD::get<_IdxsDynamicIdxs>(__vals)...) {}189  // clang-format on190 191  template <class _Up, class _static_u, class _UValsSeq, _static_u __u_sentinal, class _UIdxsSeq,192            class _UIdxsDynamicSeq, class _UIdxsDynamicIdxsSeq>193  __MDSPAN_INLINE_FUNCTION constexpr __partially_static_array_impl(194    __partially_static_array_impl<195      _Up, _static_u, _UValsSeq, __u_sentinal, _UIdxsSeq,196     _UIdxsDynamicSeq, _UIdxsDynamicIdxsSeq> const &__rhs) noexcept197    : __partially_static_array_impl(198        __construct_psa_from_all_exts_values_tag,199        __rhs.template __get_n<_Idxs>()...) {}200 201  //--------------------------------------------------------------------------202 203  // See comment in the previous partial specialization for why this is204  // necessary.  Or just trust me that it's messy.205  __MDSPAN_FORCE_INLINE_FUNCTION206  constexpr __partially_static_array_impl const &__enable_psa_conversion() const207  noexcept {208      return *this;209  }210 211  template <size_t _Ip>212  __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp __get_n() const noexcept {213    return static_cast<__base_n<_Ip> const*>(this)->__value();214  }215 216  template <class _Up, size_t _Ip>217  __MDSPAN_FORCE_INLINE_FUNCTION constexpr void __set_n(_Up&& __rhs) noexcept {218    static_cast<__base_n<_Ip>*>(this)->__set_value((_Up&&)__rhs);219  }220 221  template <size_t _Ip, _static_t __default = __sentinal>222  __MDSPAN_FORCE_INLINE_FUNCTION static constexpr _static_t223  __get_static_n() noexcept {224    return __base_n<_Ip>::__static_value == __sentinal ?225      __default : __base_n<_Ip>::__static_value;226  }227 228  __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp229  __get(size_t __n) const noexcept {230    return __MDSPAN_FOLD_PLUS_RIGHT(231      (_Tp(_Idxs == __n) * __get_n<_Idxs>()), /* + ... + */ _Tp(0)232    );233  }234 235};236 237//==============================================================================238 239template <class _Tp, class _static_t, class _ValSeq, _static_t __sentinal, class _Idxs = _CUDA_VSTD::make_index_sequence<_ValSeq::size()>>240struct __partially_static_array_impl_maker;241 242template <243  class _Tp, class _static_t,  _static_t... _Vals, _static_t __sentinal, size_t... _Idxs244>245struct __partially_static_array_impl_maker<246  _Tp, _static_t, _CUDA_VSTD::integer_sequence<_static_t, _Vals...>, __sentinal, _CUDA_VSTD::integer_sequence<size_t, _Idxs...>247>248{249  using __dynamic_idxs = typename __mask_sequence<250    _CUDA_VSTD::integer_sequence<size_t, _Idxs...>,251    _CUDA_VSTD::integer_sequence<bool, (_Vals == __sentinal)...>252  >::type;253  using __impl_base =254    __partially_static_array_impl<_Tp, _static_t,255      _CUDA_VSTD::integer_sequence<_static_t, _Vals...>,256      __sentinal, _CUDA_VSTD::integer_sequence<size_t, _Idxs...>,257      __dynamic_idxs,258      _CUDA_VSTD::make_index_sequence<__dynamic_idxs::size()>259    >;260};261 262template <class _Tp, class _static_t, class _ValsSeq, _static_t __sentinal = dynamic_extent>263class __partially_static_array_with_sentinal264  : public __partially_static_array_impl_maker<_Tp, _static_t, _ValsSeq, __sentinal>::__impl_base265{266private:267  using __base_t = typename __partially_static_array_impl_maker<_Tp, _static_t, _ValsSeq, __sentinal>::__impl_base;268public:269#if defined(_LIBCUDACXX_COMPILER_NVRTC) \270 || defined(_LIBCUDACXX_CUDACC_BELOW_11_3)271  constexpr __partially_static_array_with_sentinal() = default;272 273  template<class... _Args>274  __MDSPAN_FORCE_INLINE_FUNCTION constexpr275  __partially_static_array_with_sentinal(_Args&&... __args) noexcept(noexcept(__base_t(_CUDA_VSTD::declval<_Args>()...)))276      : __base_t(_CUDA_VSTD::forward<_Args>(__args)...)277  {}278#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv279  using __base_t::__base_t;280#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3281};282 283//==============================================================================284 285template <class T, class _static_t, _static_t... __values_or_sentinals>286struct __partially_static_sizes :287  __partially_static_array_with_sentinal<288    T, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>>289{290private:291  using __base_t = __partially_static_array_with_sentinal<292    T, _static_t, _CUDA_VSTD::integer_sequence<_static_t, __values_or_sentinals...>>;293public:294#if defined(_LIBCUDACXX_COMPILER_NVRTC) \295 || defined(_LIBCUDACXX_CUDACC_BELOW_11_3)296  constexpr __partially_static_sizes() = default;297 298  template<class... _Args>299  __MDSPAN_FORCE_INLINE_FUNCTION constexpr300  __partially_static_sizes(_Args&&... __args) noexcept(noexcept(__base_t(_CUDA_VSTD::declval<_Args>()...)))301      : __base_t(_CUDA_VSTD::forward<_Args>(__args)...)302  {}303#else // ^^^ _LIBCUDACXX_COMPILER_NVRTC || nvcc < 11.3 ^^^ / vvv !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3 vvv304  using __base_t::__base_t;305#endif // !_LIBCUDACXX_COMPILER_NVRTC || nvcc >= 11.3306  template <class _UTag>307  __MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_sizes<T, _static_t, __values_or_sentinals...>308  __with_tag() const noexcept {309    return *this;310  }311};312 313// Tags are needed for the standard layout version, but not here314template <class T, class _static_t, _static_t... __values_or_sentinals>315using __partially_static_sizes_tagged = __partially_static_sizes<T, _static_t, __values_or_sentinals...>;316 317} // end namespace __detail318 319#endif // _LIBCUDACXX_STD_VER > 11320 321_LIBCUDACXX_END_NAMESPACE_STD322 323#endif // !__MDSPAN_PRESERVE_STANDARD_LAYOUT324 325#endif // _LIBCUDACXX___MDSPAN_STATIC_ARRAY_HPP326 
codekingpro/portable-devtools · Team Ai