Skip to content

Commit d876be0

Browse files
committed
more refining of view documentation
1 parent 5c5c143 commit d876be0

File tree

2 files changed

+128
-124
lines changed

2 files changed

+128
-124
lines changed

docs/source/API/core/view/create_mirror.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Description
3636

3737
.. _View: view.html
3838

39-
.. |View| replace:: :cpp:func:`View`
39+
.. |View| replace:: :cpp:class:`View`
4040

4141
.. _ExecutionSpaceConcept: ../execution_spaces.html#executionspaceconcept
4242

docs/source/API/core/view/view.rst

Lines changed: 127 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Header File: ``<Kokkos_Core.hpp>``
164164
pointer to :cpp:type:`value_type`.
165165

166166

167-
.. rubric:: Other
167+
.. rubric:: Other Types
168168

169169
.. cpp:type:: array_layout
170170

@@ -187,21 +187,25 @@ Header File: ``<Kokkos_Core.hpp>``
187187

188188
.. cpp:function:: View()
189189

190-
Default Constructor. No allocations are made, no reference counting happens. All extents are zero and its data pointer is NULL.
190+
Default Constructor. No allocations are made, no reference counting happens. All extents are zero and its data pointer is :cpp:`nullptr`.
191191

192-
.. cpp:function:: View( const View<DT, Prop...>& rhs)
192+
.. cpp:function:: template<class DT, class... Prop> View( const View<DT, Prop...>& rhs)
193193

194194
Copy constructor with compatible view. Follows View assignment rules.
195195

196-
.. cpp:function:: View( View&& rhs)
196+
.. seealso:: :ref:`api-view-assignment`
197+
198+
.. cpp:function:: View(View&& rhs)
197199

198200
Move constructor
199201

200-
.. cpp:function:: View( const std::string& name, const IntType& ... extents)
202+
.. cpp:function:: template<class IntType> View( const std::string& name, const IntType& ... extents)
201203

202204
Standard allocating constructor. The initialization is executed on the default
203205
instance of the execution space corresponding to ``MemorySpace`` and fences it.
204206

207+
:tparam IntType: an integral type
208+
205209
:param name: a user provided label, which is used for profiling and debugging purposes. Names are not required to be unique,
206210

207211
:param extents: Extents of the :cpp:class:`View`.
@@ -304,7 +308,12 @@ Header File: ``<Kokkos_Core.hpp>``
304308

305309
.. cpp:function:: View( const View<DT, Prop...>& rhs, Args ... args)
306310

307-
Subview constructor. See ``subview`` function for arguments.
311+
:param rhs: the :cpp:class:`View` to take a subview of
312+
:param args...: the subview slices as specified in :cpp:func:`subview`
313+
314+
Subview constructor.
315+
316+
.. seealso:: :cpp:func:`subview`
308317

309318
.. cpp:function:: explicit(traits::is_managed) View( const NATURAL_MDSPAN_TYPE& mds )
310319

@@ -401,199 +410,196 @@ Header File: ``<Kokkos_Core.hpp>``
401410
It may also break code that was using the type of :cpp:func:`rank`.
402411
Furthermore, it appears that MSVC has issues with the implicit conversion to :cpp:`size_t` in certain constexpr contexts. Calling :cpp:func:`rank()` or :cpp:func:`rank_dynamic()` will work in those cases.
403412

404-
.. cpp:function:: constexpr array_layout layout() const
413+
.. cpp:function:: constexpr array_layout layout() const
405414

406-
:return: the layout object that can be used to to construct other views with the same dimensions.
415+
:return: the layout object that can be used to to construct other views with the same dimensions.
407416

408-
.. cpp:function:: template<class iType> constexpr size_t extent( const iType& dim) const
417+
.. cpp:function:: template<class iType> constexpr size_t extent( const iType& dim) const
409418

410-
:tparam iType: an integral type
411-
:param dim: the dimension to get the extent of
412-
:return: the extent of dimension :cpp:any:`dim`
419+
:tparam iType: an integral type
420+
:param dim: the dimension to get the extent of
421+
:return: the extent of dimension :cpp:any:`dim`
413422

414-
**Preconditions**
423+
**Preconditions**
415424

416-
- :cpp:any:`dim` must be smaller than :cpp:func:`rank`.
425+
- :cpp:any:`dim` must be smaller than :cpp:func:`rank`.
417426

418-
.. cpp:function:: template<class iType> constexpr int extent_int( const iType& dim) const
427+
.. cpp:function:: template<class iType> constexpr int extent_int( const iType& dim) const
419428

420-
:tparam iType: an integral type
421-
:param dim: the dimension to get the extent of
422-
:return: the extent of dimension :cpp:any:`dim` as an :cpp:`int`
429+
:tparam iType: an integral type
430+
:param dim: the dimension to get the extent of
431+
:return: the extent of dimension :cpp:any:`dim` as an :cpp:`int`
423432

424-
Compared to :cpp:func:`extent` this function can be
425-
useful on architectures where :cpp:`int` operations are more efficient than :cpp:`size_t`.
426-
It also may eliminate the need for type casts in applications which
427-
otherwise perform all index operations with :cpp:`int`.
433+
Compared to :cpp:func:`extent` this function can be
434+
useful on architectures where :cpp:`int` operations are more efficient than :cpp:`size_t`.
435+
It also may eliminate the need for type casts in applications which
436+
otherwise perform all index operations with :cpp:`int`.
428437

429-
**Preconditions**
438+
**Preconditions**
430439

431-
- :cpp:any:`dim` must be smaller than :cpp:func:`rank`.
440+
- :cpp:any:`dim` must be smaller than :cpp:func:`rank`.
432441

433-
.. cpp:function:: template<class iType> constexpr size_t stride(const iType& dim) const
442+
.. cpp:function:: template<class iType> constexpr size_t stride(const iType& dim) const
434443

435-
:tparam iType: an integral type
436-
:param dim: the dimension to get the stride of
437-
:return: the stride of dimension :cpp:any:`dim`
444+
:tparam iType: an integral type
445+
:param dim: the dimension to get the stride of
446+
:return: the stride of dimension :cpp:any:`dim`
438447

439-
Example: :cpp:expr:`a.stride(3) == (&a(i0,i1,i2,i3+1,i4)-&a(i0,i1,i2,i3,i4))`
448+
Example: :cpp:expr:`a.stride(3) == (&a(i0,i1,i2,i3+1,i4)-&a(i0,i1,i2,i3,i4))`
440449

441-
**Preconditions**
450+
**Preconditions**
442451

443-
- :cpp:any:`dim` must be smaller than :cpp:func:`rank`.
452+
- :cpp:any:`dim` must be smaller than :cpp:func:`rank`.
444453

445-
.. cpp:function:: constexpr size_t stride_0() const
454+
.. cpp:function:: constexpr size_t stride_0() const
446455

447-
:return: the stride of dimension 0.
456+
:return: the stride of dimension 0.
448457

449-
.. cpp:function:: constexpr size_t stride_1() const
458+
.. cpp:function:: constexpr size_t stride_1() const
450459

451-
:return: the stride of dimension 1.
460+
:return: the stride of dimension 1.
452461

453-
.. cpp:function:: constexpr size_t stride_2() const
462+
.. cpp:function:: constexpr size_t stride_2() const
454463

455-
:return: the stride of dimension 2.
464+
:return: the stride of dimension 2.
456465

457-
.. cpp:function:: constexpr size_t stride_3() const
466+
.. cpp:function:: constexpr size_t stride_3() const
458467

459-
:return: the stride of dimension 3.
468+
:return: the stride of dimension 3.
460469

461-
.. cpp:function:: constexpr size_t stride_4() const
470+
.. cpp:function:: constexpr size_t stride_4() const
462471

463-
:return: the stride of dimension 4.
472+
:return: the stride of dimension 4.
464473

465-
.. cpp:function:: constexpr size_t stride_5() const
474+
.. cpp:function:: constexpr size_t stride_5() const
466475

467-
:return: the stride of dimension 5.
476+
:return: the stride of dimension 5.
468477

469-
.. cpp:function:: constexpr size_t stride_6() const
478+
.. cpp:function:: constexpr size_t stride_6() const
470479

471-
:return: the stride of dimension 6.
480+
:return: the stride of dimension 6.
472481

473-
.. cpp:function:: constexpr size_t stride_7() const
482+
.. cpp:function:: constexpr size_t stride_7() const
474483

475-
:return: the stride of dimension 7.
484+
:return: the stride of dimension 7.
476485

477-
.. cpp:function:: template<class iType> void stride(iType* strides) const
486+
.. cpp:function:: template<class iType> void stride(iType* strides) const
478487

479-
:tparam iType: an integral type
480-
:param strides: the output array of length :cpp:expr:`rank() + 1`
488+
:tparam iType: an integral type
489+
:param strides: the output array of length :cpp:expr:`rank() + 1`
481490

482-
Sets :cpp:expr:`strides[r]` to :cpp:expr:`stride(r)` for all :math:`r` with :math:`0 \le r \lt \texttt{rank()}`.
483-
Sets :cpp:expr:`strides[rank()]` to :cpp:func:`span()`.
491+
Sets :cpp:expr:`strides[r]` to :cpp:expr:`stride(r)` for all :math:`r` with :math:`0 \le r \lt \texttt{rank()}`.
492+
Sets :cpp:expr:`strides[rank()]` to :cpp:func:`span()`.
484493

485-
**Preconditions**
494+
**Preconditions**
486495

487-
- :cpp:any:`strides` must be an array of length :cpp:expr:`rank() + 1`
496+
- :cpp:any:`strides` must be an array of length :cpp:expr:`rank() + 1`
488497

489-
.. cpp:function:: constexpr size_t span() const
498+
.. cpp:function:: constexpr size_t span() const
490499

491-
:return: the size of the span of memory between the element with the lowest and highest address
500+
:return: the size of the span of memory between the element with the lowest and highest address
492501

493-
Obtains the memory span in elements between the element with the
494-
lowest and the highest address. This can be larger than the product
495-
of extents due to padding, and or non-contiguous data layout as for example :cpp:struct:`LayoutStride` allows.
502+
Obtains the memory span in elements between the element with the
503+
lowest and the highest address. This can be larger than the product
504+
of extents due to padding, and or non-contiguous data layout as for example :cpp:struct:`LayoutStride` allows.
496505

497-
.. cpp:function:: constexpr size_t size() const
506+
.. cpp:function:: constexpr size_t size() const
498507

499-
:return: the product of extents, i.e. the logical number of elements in the :cpp:class:`View`.
508+
:return: the product of extents, i.e. the logical number of elements in the :cpp:class:`View`.
500509

501-
.. cpp:function:: constexpr pointer_type data() const
510+
.. cpp:function:: constexpr pointer_type data() const
502511

503-
:return: the pointer to the underlying data allocation.
512+
:return: the pointer to the underlying data allocation.
504513

505-
.. warning::
506-
507-
Calling any function that manipulates the behavior of the memory (e.g. ``memAdvise``) on memory managed by Kokkos results in undefined behavior.
514+
.. warning::
515+
516+
Calling any function that manipulates the behavior of the memory (e.g. ``memAdvise``) on memory managed by Kokkos results in undefined behavior.
508517

509-
.. cpp:function:: bool span_is_contiguous() const
518+
.. cpp:function:: bool span_is_contiguous() const
510519

511-
:return: whether the span is contiguous (i.e. whether every memory location between in span belongs to the index space covered by the :cpp:class:`View`).
520+
:return: whether the span is contiguous (i.e. whether every memory location between in span belongs to the index space covered by the :cpp:class:`View`).
512521

513-
.. cpp:function:: static constexpr size_t required_allocation_size(size_t N0=0, size_t N1=0, \
514-
size_t N2=0, size_t N3=0, \
515-
size_t N4=0, size_t N5=0, \
516-
size_t N6=0, size_t N7=0, size_t N8 = 0);
517-
518-
:param N0, N1, N2, N3, N4, N5, N6, N7, N8: the dimensions to query
519-
:return: the number of bytes necessary for an unmanaged :cpp:class:`View` of the provided dimensions.
520-
521-
**Requirements**
522-
523-
- :cpp:expr:`array_layout::is_regular == true`.
522+
.. cpp:function:: static constexpr size_t required_allocation_size(size_t N0=0, size_t N1=0, \
523+
size_t N2=0, size_t N3=0, \
524+
size_t N4=0, size_t N5=0, \
525+
size_t N6=0, size_t N7=0, size_t N8 = 0);
526+
527+
:param N0, N1, N2, N3, N4, N5, N6, N7, N8: the dimensions to query
528+
:return: the number of bytes necessary for an unmanaged :cpp:class:`View` of the provided dimensions.
529+
530+
**Requirements**
531+
532+
- :cpp:expr:`array_layout::is_regular == true`.
524533

525-
.. cpp:function:: static constexpr size_t required_allocation_size(const array_layout& layout);
534+
.. cpp:function:: static constexpr size_t required_allocation_size(const array_layout& layout);
526535

527-
:param layout: the layout to query
528-
:return: the number of bytes necessary for an unmanaged :cpp:class:`View` of the provided layout.
536+
:param layout: the layout to query
537+
:return: the number of bytes necessary for an unmanaged :cpp:class:`View` of the provided layout.
529538

530-
Other
531-
~~~~~
539+
.. rubric:: Other Utility Methods
532540

533-
.. cpp:function:: int use_count() const;
541+
.. cpp:function:: int use_count() const;
534542

535-
Returns the current reference count of the underlying allocation.
543+
:return: the current reference count of the underlying allocation.
536544

537-
.. cpp:function:: const std::string label() const;
545+
.. cpp:function:: const std::string label() const;
538546

539-
Returns the label of the View.
547+
:return: the label of the View.
540548

541-
.. cpp:function:: const bool is_assignable(const View<DT, Prop...>& rhs);
549+
.. cpp:function:: const bool is_assignable(const View<DT, Prop...>& rhs);
542550

543-
Returns true if the View can be assigned to rhs. See below for assignment rules.
551+
:return: true if the View can be assigned to rhs.
544552

545-
.. cpp:function:: void assign_data(pointer_type arg_data);
553+
.. seealso:: :ref:`api-view-assignment`
546554

547-
Decrement reference count of previously assigned data and set the underlying pointer to arg_data.
548-
Note that the effective result of this operation is that the view
549-
is now an unmanaged view; thus, the deallocation of memory associated with
550-
arg_data is not linked in anyway to the deallocation of the view.
555+
.. cpp:function:: void assign_data(pointer_type arg_data);
551556

552-
.. cpp:function:: constexpr bool is_allocated() const;
557+
:param arg_data: the pointer to set the underlying :cpp:class:`View` data pointer to
553558

554-
Returns true if the view points to a valid memory location.
555-
This function works for both managed and unmanaged views.
556-
With the unmanaged view, there is no guarantee that referenced
557-
address is valid, only that it is a non-null pointer.
559+
Decrement reference count of previously assigned data and set the underlying pointer to arg_data.
560+
Note that the effective result of this operation is that the view is now an unmanaged view; thus, the deallocation of memory associated with arg_data is not linked in anyway to the deallocation of the view.
558561

559-
Conversion to mdspan
560-
~~~~~~~~~~~~~~~~~~~~
562+
.. cpp:function:: constexpr bool is_allocated() const;
561563

562-
.. cpp:function:: template <class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class OtherAccessor> constexpr operator mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor>()
564+
:return: true if the view points to a valid memory location.
563565

564-
:tparam OtherElementType: the target mdspan element type
565-
:tparam OtherExtents: the target mdspan extents
566-
:tparam OtherLayoutPolicy: the target mdspan layout
567-
:tparam OtherAccessor: the target mdspan accessor
566+
This function works for both managed and unmanaged views.
567+
With the unmanaged view, there is no guarantee that referenced address is valid, only that it is a non-null pointer.
568568

569-
:constraints: :cpp:class:`View`\ 's :ref:`natural mdspan <api-view-natural-mdspans>` must be assignable to :cpp:`mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor>`
569+
.. rubric:: Conversion to mdspan
570570

571-
:returns: an mdspan with extents and a layout converted from the :cpp:class:`View`'s *natural mdspan*.
571+
.. cpp:function:: template <class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class OtherAccessor> constexpr operator mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor>()
572572

573-
.. cpp:function:: template <class OtherAccessorType = Kokkos::default_accessor<typename traits::value_type>> constexpr auto to_mdspan(const OtherAccessorType& other_accessor = OtherAccessorType{})
573+
:tparam OtherElementType: the target mdspan element type
574+
:tparam OtherExtents: the target mdspan extents
575+
:tparam OtherLayoutPolicy: the target mdspan layout
576+
:tparam OtherAccessor: the target mdspan accessor
574577

575-
:tparam OtherAccessor: the target mdspan accessor
578+
:constraints: :cpp:class:`View`\ 's :ref:`natural mdspan <api-view-natural-mdspans>` must be assignable to :cpp:`mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor>`
576579

577-
:constraints: :cpp:`typename OtherAccessorType::data_handle_type` must be assignable to :cpp:`value_type*`
580+
:returns: an mdspan with extents and a layout converted from the :cpp:class:`View`'s *natural mdspan*.
578581

579-
:returns: :cpp:class:`View`\ 's :ref:`natural mdspan <api-view-natural-mdspans>`, but with an accessor policy constructed from :cpp:any:`other_accessor`
582+
.. cpp:function:: template <class OtherAccessorType = Kokkos::default_accessor<typename traits::value_type>> constexpr auto to_mdspan(const OtherAccessorType& other_accessor = OtherAccessorType{})
580583

584+
:tparam OtherAccessor: the target mdspan accessor
581585

582-
NonMember Functions
583-
-------------------
586+
:constraints: :cpp:`typename OtherAccessorType::data_handle_type` must be assignable to :cpp:`value_type*`
587+
588+
:returns: :cpp:class:`View`\ 's :ref:`natural mdspan <api-view-natural-mdspans>`, but with an accessor policy constructed from :cpp:any:`other_accessor`
589+
590+
591+
Non-Member Functions
592+
--------------------
584593

585594
.. cpp:function:: template<class ViewDst, class ViewSrc> bool operator==(ViewDst, ViewSrc);
586595

587-
Returns true if ``value_type``, ``array_layout``, ``memory_space``, ``rank``, ``data()`` and ``extent(r)``, for ``0<=r<rank``, match.
596+
:return: :cpp:`true` if :cpp:type:`~View::value_type`, :cpp:type:`~View::array_layout`, :cpp:type:`~View::memory_space`, :cpp:func:`~View::rank()`, :cpp:func:`~View::data()` and :cpp:expr:`extent(r)`, for :math:`0 \le r \lt \texttt{rank()}`, match.
588597

589598
.. cpp:function:: template<class ViewDst, class ViewSrc> bool operator!=(ViewDst, ViewSrc);
590599

591600
Returns true if any of ``value_type``, ``array_layout``, ``memory_space``, ``rank``, ``data()`` and ``extent(r)``, for ``0<=r<rank`` don't match.
592601

593-
.. _api-view-datatype:
594-
595-
:cpp:class:`View` DataType
596-
--------------------------
602+
.. _api-view-assignment:
597603

598604
Assignment Rules
599605
----------------
@@ -632,10 +638,8 @@ These rules only cover cases where both layouts are one of ``LayoutLeft``, ``Lay
632638

633639
- For each dimension ``k`` it must hold that ``dst_view.extent(k) == src_view.extent(k)``
634640

635-
Assignment Examples
636-
~~~~~~~~~~~~~~~~~~~
637-
638641
.. code-block:: cpp
642+
:caption: Assignment Examples
639643
640644
View<int*> a1 = View<int*>("A1",N); // OK
641645
View<int**> a2 = View<int*[10]>("A2",N); // OK

0 commit comments

Comments
 (0)