-
Notifications
You must be signed in to change notification settings - Fork 51
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
UniqueToken.md: API documentation for UniqueToken.md #179
base: main
Are you sure you want to change the base?
Changes from 4 commits
d63ea5b
6910dff
d5f1d97
cc05ccc
25a2ef3
0156d10
39292ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,103 @@ | ||||||||||||||||||||||||||||||||||
``UniqueToken`` | ||||||||||||||||||||||||||||||||||
=============== | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Header File: ``Kokkos_Core.hpp`` | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Description | ||||||||||||||||||||||||||||||||||
------------ | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
``UniqueToken`` is a portable way to acquire a unique ID for a thread (``thread-id`` is not portable across execution environments). The unique ID is scoped by the ``UniqueTokenScope`` template parameter (defaults to ``Instance``, but can be set to ``Global``). | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Interface | ||||||||||||||||||||||||||||||||||
--------- | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. code-block:: cpp | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
template <class ExecutionSpace = DefaultExecutionSpace, UniqueTokenScope = UniqueTokenScope::Instance> UniqueToken | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Parameters | ||||||||||||||||||||||||||||||||||
----------- | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
* ``ExecutionSpace``: See `Execution Spaces <../execution_spaces.html>`_ | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
* ``UniqueTokenScope``: defaults to ``Instance``, and every instance is independent of another. In contrast, ``Global`` uses one set of unique IDs for all instances. | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. note:: | ||||||||||||||||||||||||||||||||||
In a parallel region, before the main computation, a pool of ``UniqueToken`` (integer) ID is generated, and each ID is released following iteration. | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. warning:: | ||||||||||||||||||||||||||||||||||
``UniqueToken <ExecutionSpace> token`` *can* be called inside a parallel region, *but* must be released at the end of *each* iteration. | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be saying "work item" instead of "iteration"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either formulation is fine : " ... each iterate" or " ... each work item" |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Constructors | ||||||||||||||||||||||||||||||||||
------------- | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. code-block:: cpp | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
UniqueToken(size_type max_size, ExecutionSpace execution_space = ExecutionSpace()) | ||||||||||||||||||||||||||||||||||
// Scope is instance | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. code-block:: cpp | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
UniqueToken(size_type max_size, ExecutionSpace execution_space = ExecutionSpace()) requires(TokenScope == Global); | ||||||||||||||||||||||||||||||||||
// Scope is global | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not following what is the difference between the two. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think are right, the constructor that takes a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes -- the main distinction is scope (instance or global). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Public Member Functions | ||||||||||||||||||||||||||||||||||
------------------------ | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. code-block:: cpp | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
UniqueToken(size_type max_size, ExecutionSpace execution_space=ExecutionSpace()) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
presumably a copy pasta error |
||||||||||||||||||||||||||||||||||
.. code-block:: cpp | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
size_type size() | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we forget to define |
||||||||||||||||||||||||||||||||||
// Returns the size of the token pool | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a dedicated syntax for return
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. code-block:: cpp | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
size_type acquire() | ||||||||||||||||||||||||||||||||||
// Returns the token for the executing tread | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. code-block:: cpp | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
void release(size_type idx) | ||||||||||||||||||||||||||||||||||
// Releases the passed token | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. warning:: | ||||||||||||||||||||||||||||||||||
Acquired tokens *must* be released at the end of the parallel region in which they were acquired | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Examples | ||||||||||||||||||||||||||||||||||
--------- | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
.. code-block:: cpp | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// UniqueToken on an Execution Space Instance | ||||||||||||||||||||||||||||||||||
UniqueToken < ExecutionSpace > token ; | ||||||||||||||||||||||||||||||||||
int number_of_uniqe_ids = token.size (); | ||||||||||||||||||||||||||||||||||
RandomGenPool pool ( number_of_unique_ids , seed ); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
parallel_for ("L", N, KOKKOS_LAMBDA ( int i) { | ||||||||||||||||||||||||||||||||||
auto id = token.acquire (); | ||||||||||||||||||||||||||||||||||
RandomGen gen = pool (id); | ||||||||||||||||||||||||||||||||||
// Computation Body | ||||||||||||||||||||||||||||||||||
token.release (id); | ||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// Submitting concurrent kernels to (e.g., CUDA) streams | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
void foo () { | ||||||||||||||||||||||||||||||||||
UniqueToken < ExecSpace , UniqueTokenScope :: Global > token_foo ; | ||||||||||||||||||||||||||||||||||
parallel_for ("L", RangePolicy < ExecSpace >( stream1 ,0,N), functor_a ( token_foo ));} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
void bar () { | ||||||||||||||||||||||||||||||||||
UniqueToken < ExecSpace , UniqueTokenScope :: Global > token_bar ; | ||||||||||||||||||||||||||||||||||
parallel_for ("L", RangePolicy < ExecSpace >( stream2,0,N), functor_b ( token_bar ));} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand what this means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess she meant to say that the token is released at the end of the iteration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reworked for clarity.