-
Notifications
You must be signed in to change notification settings - Fork 114
Feature: Device messages #1832
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
Open
bechols97
wants to merge
96
commits into
develop
Choose a base branch
from
feature/bechols97/device_messages
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,378
−45
Open
Feature: Device messages #1832
Changes from 62 commits
Commits
Show all changes
96 commits
Select commit
Hold shift + click to select a range
91812b9
Moves message handling to RAJA from Camp
bechols97 c88179c
Adds unit tests for message handler
bechols97 0096451
Adds additional assert's to tests
bechols97 028dd3b
Initial setup for queue view
bechols97 41172d8
Updates to separate functionality
bechols97 78aaa3d
Adds example and some comments
bechols97 9b7d615
Re-formats messaging code
bechols97 8a6d4b2
Fixes bug in example
bechols97 94114f8
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 3c1a73f
Adds factory functions and deduction guides for message_handler
bechols97 9f57022
Runs clang-format
bechols97 b875e20
Adds spsc queue policy
bechols97 3c0fb38
Adds a fixed sized string to example
bechols97 53a2a70
Fixes formatting with clang-format
bechols97 13abf53
Adds factory function to use default resource with execution policy
bechols97 8f24bf2
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 63da19f
Refactors storing messages to be more generic
bechols97 4afd67f
Fixes build with example
bechols97 b5bf8b0
Fixes message alignment issues
bechols97 72f4c42
Formats code
bechols97 4ff9f00
Merge branch 'develop' into feature/bechols97/device_messages
rhornung67 38f8ed5
Changes to message callbacks
bechols97 c816f67
Adds subscribe/unsubscribe functionality
bechols97 6962633
Adds tests for subscribe/unsubscribe member functions
bechols97 a1ac472
Fixes passing to callback list
bechols97 f388bcc
Removes extra size member variable
bechols97 c13d501
Supports getting a container of all messages
bechols97 a5688f7
Merge branch 'feature/bechols97/device_messages' of ssh://github.com/…
bechols97 3d6a37a
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 6c6776c
Formats code
bechols97 ae2e1e3
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 919ac58
Fixes for cuda build and formatting
bechols97 b808d23
Moves to CAS loop for atomic operation
bechols97 6a3196b
Fixes variable name
bechols97 3b322c4
Moves message headers to pattern folder and makes format
bechols97 9d60d99
Removes simd from example since not support with messages
bechols97 f6d4e76
Destroys message header after use
bechols97 5f4b397
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 faae0ff
Fixes include path
bechols97 bc1ca1b
Fixes warnings
bechols97 04445c0
Cleans up warnings
bechols97 87da925
Runs make style
bechols97 1241e57
Moves align to be under util directory and renames to align_sz
bechols97 7ff9dc2
Moves to use align_sz
bechols97 3c916fe
Adds missing header files
bechols97 809a09e
Merge branch 'develop' into feature/bechols97/device_messages
rhornung67 c4e3b56
Updates hashing for message callbacks
bechols97 825434c
Updates example to better describe and show different features
bechols97 3a7323d
De-duplicates function type traits
bechols97 318ec53
Merge branch 'feature/bechols97/device_messages' of ssh://github.com/…
bechols97 b04cf64
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 4d809f2
Fixes format
bechols97 7c99ac3
Adds documentation for RAJA::messages
bechols97 5a4cf02
Minor fixes to docs
bechols97 d9ca533
Expands on queue policies in documentation
bechols97 7b6c02b
More edits to documentation
bechols97 a811496
Apply suggestions to example from code review
bechols97 ffb0803
Updates host resource variable name to be more consistent
bechols97 d686051
Adds some considerations for applications
bechols97 4cb5fcb
Removes unused test
bechols97 83b2df5
Updates docs
bechols97 3de6af7
Updates comments on incomplete policies
bechols97 03313af
Formats code
bechols97 605e17b
Apply suggestions to documentation from code review
bechols97 5f5ec23
More documentation fixes based on feedback
bechols97 54c5808
Update comment in examples/messages-forall.cpp based on suggestion in PR
bechols97 55b6a40
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 4925666
Updates mapping of messages to callbacks to use a map instead of vector
bechols97 983e48a
Updates comments
bechols97 4762daa
Updates unsubscribe_all(msg_id) to erase entry
bechols97 583c726
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 bbb611d
Merge branch 'develop' into feature/bechols97/device_messages
rhornung67 0b31063
Adds optional allocator
bechols97 ee7735f
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 874a5d6
Fixes build
bechols97 225a7ae
Adds back placement new for creating object lifetime
bechols97 07a1ea4
Adds missing typename
bechols97 73f49b3
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 534097a
Update docs/sphinx/user_guide/feature/messages.rst
bechols97 da2a308
Updates to use camel case and fixes typename
bechols97 9eb95f1
Adjusts documentation
bechols97 d5fe17e
Fixes comparison operator
bechols97 20f9e33
Moves to one allocator and resource
bechols97 6f8ef8e
Fixes move assignment for propagation on move assignment
bechols97 4310d20
Updates documentation for custom allocator
bechols97 86572cf
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 c6c3769
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 72fab89
Apply suggestions from code review
bechols97 91eaabe
Adds ranges version of find_if
bechols97 40e609b
Reduces duplicate code
bechols97 cf19e8d
Adds non-const accessors
bechols97 0135fc3
Updates CAS loop to use generic atomic in RAJA
bechols97 adddc48
Adjusts to use long stored allocator
bechols97 4efd987
Moves hash_combine to detail namespace
bechols97 6f135db
Adds some functional tests for messages
bechols97 5d0c0d0
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| .. ## | ||
| .. ## Copyright (c) Lawrence Livermore National Security, LLC and other | ||
| .. ## RAJA Project Developers. See top-level LICENSE and COPYRIGHT | ||
| .. ## files for dates and other details. No copyright assignment is required | ||
| .. ## to contribute to RAJA. | ||
| .. ## | ||
| .. ## SPDX-License-Identifier: (BSD-3-Clause) | ||
| .. ## | ||
|
|
||
| .. _feat-message-label: | ||
|
|
||
| =============================== | ||
| Messages | ||
| =============================== | ||
|
|
||
| RAJA provides a portable interface and type-safe way to store function arguments that | ||
| passed to a function at a later time. For example, from a GPU, arguments can be stored | ||
| and passed to function that prints to a file on the CPU. | ||
|
|
||
| .. warning:: This capability is new and should be considered experimental. | ||
|
bechols97 marked this conversation as resolved.
Outdated
bechols97 marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| -------------------------- | ||
| How to manage messages? | ||
| -------------------------- | ||
| All messages are handled via the ``message_manager``, which is responsible for | ||
| storing callbacks and a list of messages. For the purposes of ``RAJA::messages``, | ||
| a single message can be thought of: | ||
|
|
||
| * ``msg_header``: helper data internal to ``RAJA`` | ||
| * ``msg_args``: a tuple of arguments needed to pass to the function | ||
|
|
||
| To create the ``message_manager``: | ||
|
|
||
| .. literalinclude:: ../../../../examples/messages-forall.cpp | ||
| :start-after: _raja_msg_manager_start | ||
| :end-before: _raja_msg_manager_end | ||
| :language: C++ | ||
|
|
||
| ``buf_sz`` is the size of the buffer that stores messages. ``res_host`` is the resource of the | ||
| execution policy, which determines what type of memory to store messages with. For GPU resources, | ||
|
bechols97 marked this conversation as resolved.
Outdated
|
||
| this is ``PINNED`` memory. | ||
|
|
||
| Subscribing callbacks | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| To create a specific message type, callbacks must subscribe first. This can be done in two ways: | ||
|
|
||
| * ``subscribe(Callable)``: Subscribing with just a callable will create a new type of message with the | ||
| type depending on the parameters. | ||
| * ``subscribe(msg_queue_id, Callable)``: Subscribing with ``msg_queue_id`` and a callable will append the new | ||
| callback to the already existing callback list. | ||
|
|
||
| As an example for subscribing with both methods: | ||
|
|
||
| .. literalinclude:: ../../../../examples/messages-forall.cpp | ||
| :start-after: _raja_msg_subscribe_start | ||
| :end-before: _raja_msg_subscribe_end | ||
| :language: C++ | ||
|
|
||
| Unsubscribing callbacks | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| If a particular callback no longer needs to be subscribed to a message type, then the callback can be | ||
| unsubcribed. This can be achieved in three ways: | ||
|
|
||
| * ``unsubscribe(msg_queue_id, Callable)``: Looks for a specific callback that is subscribed to a particular message. If | ||
| the callback is subscribed, remove from callback list. Otherwise, throws an exception. | ||
| * ``unsubscribe_all(msg_queue_id)``: Removes all callbacks subscribed to a particular message | ||
| * ``unsubscribe_all()``: Removes all callbacks and messages. | ||
|
|
||
| An example for unsubscribing a callback: | ||
|
|
||
| .. literalinclude:: ../../../../examples/messages-forall.cpp | ||
| :start-after: _raja_msg_unsubscribe_start | ||
| :end-before: _raja_msg_unsubscribe_end | ||
| :language: C++ | ||
|
|
||
|
|
||
| Publishing messages | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| Messages can be published/stored in a ``msg_queue``. These are non-owning adapters to the ``msg_bus``, which is | ||
| responsible for storing all messages. The ``msg_queue`` will contain additional type information as well as | ||
| the ``msg_queue_id``. A queue is created once a callback is subscribed to a new message type. Since ``msg_queue`` is | ||
| non-owning, these can be copied. | ||
|
|
||
| Here is how the ``msg_queue`` can be used to publish messages: | ||
|
|
||
| .. literalinclude:: ../../../../examples/messages-forall.cpp | ||
| :start-after: _raja_msg_k2_start | ||
| :end-before: _raja_msg_k2_end | ||
| :language: C++ | ||
|
|
||
| Handling messages | ||
| ^^^^^^^^^^^^^^^^^ | ||
| Lastly, there needs to be a way to "handle" messages. In others, direct the messages to the corresponding callback(s). | ||
|
bechols97 marked this conversation as resolved.
Outdated
|
||
| This is handled with the ``message_manager``, which forces a synchronize on the resource provided. | ||
|
|
||
| .. literalinclude:: ../../../../examples/messages-forall.cpp | ||
| :start-after: _raja_msg_wait_start | ||
| :end-before: _raja_msg_wait_end | ||
| :language: C++ | ||
|
|
||
| Handling messages with a GPU | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Here is a complete example using the ``RAJA::messages`` with a GPU kernel. | ||
|
|
||
| .. literalinclude:: ../../../../examples/messages-forall.cpp | ||
| :start-after: _raja_msg_gpu1_start | ||
| :end-before: _raja_msg_gpu1_end | ||
| :language: C++ | ||
|
|
||
| .. note:: | ||
| In this example, ``gpu_policy`` depends on the build (i.e., CUDA, HIP), ``res`` is the default resource for | ||
| ``gpu_policy``, and ``d_*`` arrays are allocated for the device. These are removed above from the example to just | ||
| show the ``RAJA::messages`` interface. | ||
|
|
||
| Handling messages across multiple streams | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Here is a complete example using the ``RAJA::messages`` with multiple resources. | ||
|
|
||
| .. literalinclude:: ../../../../examples/messages-forall.cpp | ||
| :start-after: _raja_msg_gpu2_start | ||
| :end-before: _raja_msg_gpu2_end | ||
| :language: C++ | ||
|
|
||
| .. note:: | ||
| In this example, ``res_gpu1`` and ``res_gpu2`` depend on the build (i.e., CUDA, HIP), ``EXEC_POLICY`` the | ||
| exeuction policy for the loops (also depends on the build), and ``d_*`` arrays are allocated for the device | ||
| while ``h_*`` are allocated for the host. These are removed from the example above to just show the | ||
| ``RAJA::messages`` interface. | ||
|
|
||
| Message queue policies | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| Message queues can support various policies depending on the requirements of that queue, such as | ||
| the number of producers/consumers or the type of atomic operations. | ||
|
|
||
| ======================= ============================ | ||
| Message queue Policies Brief description | ||
| ======================= ============================ | ||
| spsc Supports a single producer, | ||
| single consumer; i.e., no | ||
| atomic operations | ||
| mpsc Supports multiple producers, | ||
| a single consumer; i.e., | ||
| requires atomic operations. | ||
| Automiatically determines | ||
|
bechols97 marked this conversation as resolved.
Outdated
|
||
| which atomic operations to | ||
| use. | ||
| ======================= ============================ | ||
|
|
||
| .. note:: Producers and consumers can not operate at the same time | ||
|
|
||
| Building and running the example | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| The example ``examples/messages-forall.cpp`` is built from the RAJA source tree when: | ||
|
|
||
| * ``ENABLE_EXAMPLES=On`` | ||
|
|
||
| To run the example: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| ./bin/messages-forall | ||
|
|
||
| This example will show how callbacks can be subscribed to various types of messages as | ||
| well as how to publish messages on multiple different platforms. For the purposes of | ||
| this example, output for messages will be printed using ``std::cout``. | ||
|
|
||
| -------------------------- | ||
| Application considerations | ||
| -------------------------- | ||
|
|
||
| Things to consider when using ``RAJA::messages`` in an application. | ||
|
bechols97 marked this conversation as resolved.
Outdated
|
||
|
|
||
| * The ``msg_queue`` with the correct argument types is created when a callback subscribes. Certain | ||
| patterns will cause this storage to slowly grow overtime. For example, creating a new | ||
| ``msg_queue`` every function call within a loop. Therefore, applications that use this pattern | ||
| will want to unsubscribe at some point to avoid running out of memory. | ||
| * Upon creation of the ``message_manager``, the ``message_bus`` will be allocated with some size. This | ||
| can be resized; however, resizing will force a synchronize and will loss any messages currently stored. | ||
| Also, the allocation is done through the resource, which can be less performant depending on the resource. | ||
| * Since the ``msg_queue`` is a fixed size, there is a chance of lossing messages. The ``try_post_message`` function | ||
| will return a ``boolean``. This will be ``true`` if the message is successfully added to the queue; otherwise, this | ||
| is ``false``. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.