Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ajpowelsnl
Copy link
Contributor

This PR is the first draft of API documentation for UniqueToken capability and is linked to the #5140 "catch all" Documentation issue.

Copy link
Contributor

@JBludau JBludau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a lot of whitespace in the c++ code that looks akward given the style we use in the rest of the documentation.

docs/source/API/core/parallel-dispatch/UniqueToken.md Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.md Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.md Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.md Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.md Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.md Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.md Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.md Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.md Outdated Show resolved Hide resolved
@crtrott
Copy link
Member

crtrott commented Nov 28, 2022

Document the extra constructor for UniqueTokenScope==Global as:

UniqueToken(size_type max_size, execution_space space = execution_space()) requires(TokenScope == Global);

@ajpowelsnl
Copy link
Contributor Author

Document the extra constructor for UniqueTokenScope==Global as:

UniqueToken(size_type max_size, execution_space space = execution_space()) requires(TokenScope == Global);

Done

Copy link
Contributor

@JBludau JBludau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the implementation I want to suggest some changes. But someone should verify.

docs/source/API/core/parallel-dispatch/UniqueToken.rst Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.rst Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.rst Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.rst Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.rst Outdated Show resolved Hide resolved
Comment on lines 55 to 58
int id = token . acquire ();
RandomGen gen = pool (id );
// Computation Body
token . release (id );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int id = token . acquire ();
RandomGen gen = pool (id );
// Computation Body
token . release (id );
auto id = token.acquire ();
RandomGen gen = pool (id );
// Computation Body
token.release (id );

docs/source/API/core/parallel-dispatch/UniqueToken.rst Outdated Show resolved Hide resolved
docs/source/API/core/parallel-dispatch/UniqueToken.rst Outdated Show resolved Hide resolved
@JBludau
Copy link
Contributor

JBludau commented Sep 7, 2024

Document the extra constructor for UniqueTokenScope==Global as:

UniqueToken(size_type max_size, execution_space space = execution_space()) requires(TokenScope == Global);

Shouldn't it be TokenScope == Instance for the ctor to take a max_size?

@ajpowelsnl
Copy link
Contributor Author

@JBludau - I used most of your suggestions. See what you think about the updates.

Copy link
Contributor

@JBludau JBludau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be saying "work item" instead of "iteration"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either formulation is fine : " ... each iterate" or " ... each work item"

* ``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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each ID is released following iteration.

I don't quite understand what this means.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworked for clarity.

Comment on lines 41 to 47
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not following what is the difference between the two.
Should that be interpreted as, regardless of whether TokenScope is instance or global, the constructor takes an integer argument and optionally an execution space trailing argument that defaults to the default exec space instance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think are right, the constructor that takes a max_size will instantiate UniqueToken<ExecutionSpace,UniqueTokenScope::Instance>.
The one with only the ExecutionSpace as argument does not restrict the scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes -- the main distinction is scope (instance or global).

Comment on lines 53 to 56
.. code-block:: cpp

UniqueToken(size_type max_size, ExecutionSpace execution_space=ExecutionSpace())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. code-block:: cpp
UniqueToken(size_type max_size, ExecutionSpace execution_space=ExecutionSpace())

presumably a copy pasta error


.. code-block:: cpp

size_type size()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we forget to define size_type?

.. code-block:: cpp

size_type size()
// Returns the size of the token pool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a dedicated syntax for return

Suggested change
// Returns the size of the token pool
:returns: the size of the token pool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:return: doesn't work (as a Sphinx directive) with .. code-block:: cpp or .. cpp:function::

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, code-block:: cpp (vs. cpp:function::) is being used

Copy link
Contributor

@JBludau JBludau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch by @dalg24, the ctor description is not correct

Comment on lines 39 to 47
.. 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. 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
.. code-block:: cpp
UniqueToken(size_type max_size, ExecutionSpace execution_space = ExecutionSpace{})
// Scope is instance
UniqueToken(ExecutionSpace execution_space = ExecutionSpace{})
// Scope can be instance or global

* ``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. A generated ID is released following iteration (see ``void release(size_t idx)`` below).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we need the note when we have the warning below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we kept the warning and ditched the note. The warning was very explicit about what users have to adhere to. The note makes it sound optional in my opinion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants