weixin_39866817
2020-12-29 17:23 阅读 0

Add variant of subview that lets users add traits

Add Kokkos::subview variant that lets users add traits (e.g., Atomic, MemoryUnmanaged, RandomRead) to the resulting type. This is particularly useful for creating an unmanaged subview of a managed View, since it would avoid the intermediate step of assigning from a managed to an unmanaged View (before taking the subview). It might look something like this:


auto X_unmanaged = Kokkos::subview_with_traits<memoryunmanaged> (X, std::make_pair (3, 10));
</memoryunmanaged>

The advantage is that users would not need to know the exact return type (which is tricky given different layouts and slices!), yet could still add traits to it.

该提问来源于开源项目:kokkos/kokkos

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

10条回答 默认 最新

  • weixin_39732316 weixin_39732316 2020-12-29 17:23

    Likely do-able simply as: auto x = subview< Traits >( ... );

    点赞 评论 复制链接分享
  • weixin_39732316 weixin_39732316 2020-12-29 17:23

    The refactored View will allow compatible subview construction as view_type y( ... );
    subview_type x( y , ...subview_args... );

    点赞 评论 复制链接分享
  • weixin_39866817 weixin_39866817 2020-12-29 17:23

    When you say "likely do-able," does that mean it works now, or that it's easy to make that work?

    点赞 评论 复制链接分享
  • weixin_39548740 weixin_39548740 2020-12-29 17:23

    That means we can add that without too much trouble.

    点赞 评论 复制链接分享
  • weixin_39732316 weixin_39732316 2020-12-29 17:23

    Putting this feature in the experimental view.

    
    View<...> primary( ...allocation_arguments... );
    View<...> subview( primary , ...subview_arguments... );
    </...></...>

    The constructor for subview performs a static_assert on whether the subview type, primary view type, and subview arguments are compatible.

    点赞 评论 复制链接分享
  • weixin_39548740 weixin_39548740 2020-12-29 17:23

    Ok that should be good enough for now. Btw your naming was a bit unfortunate took me a bit to get what you was saying better:

     C++
    View<...> a_view(...allocation_arguments...);
    View<...> a_sub_view(a_view, ... subview_arguments...);
    </...></...>

    Do we still want

     C++
    auto a_sub_view = subview<traits>(a_view, ...subview_arguments...);
    </traits>

    In the first scheme I need to know what the data_type, layout and memory space are, in the second I don't.

    点赞 评论 复制链接分享
  • weixin_39866817 weixin_39866817 2020-12-29 17:23

    I've already hacked up a bit of the "add traits" functionality in Tpetra, for ensuring that I get unmanaged Views, no matter what type of input View comes in. It would be nice if Kokkos provided that :-)

    点赞 评论 复制链接分享
  • weixin_39732316 weixin_39732316 2020-12-29 17:23

    Nearly trivial addition to experimental view:

    
    auto a_sub_view = subview< MemoryTraits >( a_view , ...subview_arguments... );
    

    Does a static_assert that MemoryTraits are really memory traits.

    点赞 评论 复制链接分享
  • weixin_39548740 weixin_39548740 2020-12-29 17:23

    Don't close until its in master.

    点赞 评论 复制链接分享
  • weixin_39548740 weixin_39548740 2020-12-29 17:23

    Pushed to master

    点赞 评论 复制链接分享

相关推荐