Skip to content

Commit

Permalink
Improvement after review
Browse files Browse the repository at this point in the history
Created hyperlinks to function from usage section
Ensured example compile without change
Moved Warning about namespace to the top of the file
  • Loading branch information
PaulGannay committed Jan 27, 2025
1 parent 3479a45 commit 27fd184
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions docs/source/API/containers/ScatterView.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

Header File: ``<Kokkos_ScatterView.hpp>``

.. warning::

Currently ``ScatterView`` is still in the namespace ``Kokkos::Experimental``


.. _parallelReduce: ../core/parallel-dispatch/parallel_reduce.html

.. |parallelReduce| replace:: :cpp:func:`parallel_reduce`
Expand All @@ -14,17 +19,22 @@ Header File: ``<Kokkos_ScatterView.hpp>``

.. |View| replace:: ``View``

.. |reset| replace:: ``reset()``

.. |access| replace:: ``access()``

.. |contribute| replace:: ``contribute()``

Usage
-----
A Kokkos ScatterView wraps a standard Kokkos::|View|_ and allow access to it either via Atomic or Data Replication based scatter algorithms, choosing the strategy that should be the fastest for the ScatterView Execution Space.

Construction of a ScatterView can be expensive, so you should try to reuse the same one if possible, in which case, you should call ``reset()`` between uses.
A Kokkos ScatterView wraps a standard Kokkos::|View|_ and allow access to it either via Atomic or Data Replication based scatter algorithms, choosing the strategy that should be the fastest for the ScatterView Execution Space.

ScatterView can not be addressed directly: each thread inside a parallel region needs to make a call to ``access()`` and access the underlying View through the return value of ``access()``.
Construction of a ScatterView can be expensive, so you should try to reuse the same one if possible, in which case, you should call |reset|_ between uses.

Following the parallel region, a call to the free function ``contribute`` should be made to perform the final reduction.
ScatterView can not be addressed directly: each thread inside a parallel region needs to make a call to |access|_ and access the underlying View through the return value of |access|_.

It is part of the Experimental namespace.
Following the parallel region, a call to the free function |contribute|_ should be made to perform the final reduction.

Interface
---------
Expand Down Expand Up @@ -119,6 +129,8 @@ Description
:return: true if the ``internal_view`` points to a valid memory location. This function works for both managed and unmanaged views. With the unmanaged view, there is no guarantee that referenced address is valid, only that it is a non-null pointer.

.. _access:

.. cppkokkos:function:: access() const
use within a kernel to return a ``ScatterAccess`` member; this member accumulates a given thread's contribution to the reduction.
Expand All @@ -131,6 +143,8 @@ Description
contribute ``ScatterView`` array's results into the input View ``dest``

.. _reset:

.. cppkokkos:function:: reset()
performs reset on destination array
Expand All @@ -156,6 +170,8 @@ Description

.. rubric:: Free Functions

.. _contribute:

.. cppkokkos:function:: contribute(View<DT1, VP...>& dest, Kokkos::Experimental::ScatterView<DT2, LY, ES, OP, CT, DP> const& src)
convenience function to perform final reduction of ScatterView
Expand All @@ -167,15 +183,23 @@ Example

.. code-block:: cpp
#include <Kokkos_Core.hpp>
#include <Kokkos_ScatterView.hpp>
KOKKOS_INLINE_FUNCTION int foo(int i) { return i; }
KOKKOS_INLINE_FUNCTION double bar(int i) { return i*i; }
Kokkos::View<double*> results("results", 1);
Kokkos::Experimental::ScatterView<double*> scatter(results);
Kokkos::parallel_for(1, KOKKOS_LAMBDA(int input_i) {
auto access = scatter.access();
auto result_i = foo(input_i);
auto contribution = bar(input_i);
access(result_i) += contribution;
});
Kokkos::Experimental::contribute(results, scatter);
int main (int argc, char* argv[]) {
Kokkos::ScopeGuard guard(argc, argv);
Kokkos::View<double*> results("results", 1);
Kokkos::Experimental::ScatterView<double*> scatter(results);
Kokkos::parallel_for(1, KOKKOS_LAMBDA(int input_i) {
auto access = scatter.access();
auto result_i = foo(input_i);
auto contribution = bar(input_i);
access(result_i) += contribution;
});
Kokkos::Experimental::contribute(results, scatter);
}

0 comments on commit 27fd184

Please sign in to comment.