Skip to content
Open
Show file tree
Hide file tree
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 Apr 28, 2025
c88179c
Adds unit tests for message handler
bechols97 Apr 28, 2025
0096451
Adds additional assert's to tests
bechols97 May 12, 2025
028dd3b
Initial setup for queue view
bechols97 May 12, 2025
41172d8
Updates to separate functionality
bechols97 May 12, 2025
78aaa3d
Adds example and some comments
bechols97 May 13, 2025
9b7d615
Re-formats messaging code
bechols97 May 27, 2025
8a6d4b2
Fixes bug in example
bechols97 May 27, 2025
94114f8
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Jul 21, 2025
3c1a73f
Adds factory functions and deduction guides for message_handler
bechols97 Jul 21, 2025
9f57022
Runs clang-format
bechols97 Jul 21, 2025
b875e20
Adds spsc queue policy
bechols97 Aug 4, 2025
3c0fb38
Adds a fixed sized string to example
bechols97 Aug 4, 2025
53a2a70
Fixes formatting with clang-format
bechols97 Aug 4, 2025
13abf53
Adds factory function to use default resource with execution policy
bechols97 Aug 5, 2025
8f24bf2
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Nov 5, 2025
63da19f
Refactors storing messages to be more generic
bechols97 Nov 5, 2025
4afd67f
Fixes build with example
bechols97 Nov 5, 2025
b5bf8b0
Fixes message alignment issues
bechols97 Nov 11, 2025
72f4c42
Formats code
bechols97 Nov 11, 2025
4ff9f00
Merge branch 'develop' into feature/bechols97/device_messages
rhornung67 Dec 1, 2025
38f8ed5
Changes to message callbacks
bechols97 Jan 6, 2026
c816f67
Adds subscribe/unsubscribe functionality
bechols97 Jan 20, 2026
6962633
Adds tests for subscribe/unsubscribe member functions
bechols97 Jan 20, 2026
a1ac472
Fixes passing to callback list
bechols97 Jan 20, 2026
f388bcc
Removes extra size member variable
bechols97 Jan 20, 2026
c13d501
Supports getting a container of all messages
bechols97 Jan 20, 2026
a5688f7
Merge branch 'feature/bechols97/device_messages' of ssh://github.com/…
bechols97 Jan 20, 2026
3d6a37a
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Jan 20, 2026
6c6776c
Formats code
bechols97 Jan 20, 2026
ae2e1e3
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Feb 27, 2026
919ac58
Fixes for cuda build and formatting
bechols97 Feb 27, 2026
b808d23
Moves to CAS loop for atomic operation
bechols97 Mar 3, 2026
6a3196b
Fixes variable name
bechols97 Mar 3, 2026
3b322c4
Moves message headers to pattern folder and makes format
bechols97 Mar 10, 2026
9d60d99
Removes simd from example since not support with messages
bechols97 Mar 10, 2026
f6d4e76
Destroys message header after use
bechols97 Mar 10, 2026
5f4b397
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Mar 10, 2026
faae0ff
Fixes include path
bechols97 Mar 10, 2026
bc1ca1b
Fixes warnings
bechols97 Mar 10, 2026
04445c0
Cleans up warnings
bechols97 Mar 10, 2026
87da925
Runs make style
bechols97 Mar 11, 2026
1241e57
Moves align to be under util directory and renames to align_sz
bechols97 Mar 16, 2026
7ff9dc2
Moves to use align_sz
bechols97 Mar 16, 2026
3c916fe
Adds missing header files
bechols97 Mar 17, 2026
809a09e
Merge branch 'develop' into feature/bechols97/device_messages
rhornung67 Mar 24, 2026
c4e3b56
Updates hashing for message callbacks
bechols97 Apr 6, 2026
825434c
Updates example to better describe and show different features
bechols97 Apr 6, 2026
3a7323d
De-duplicates function type traits
bechols97 Apr 6, 2026
318ec53
Merge branch 'feature/bechols97/device_messages' of ssh://github.com/…
bechols97 Apr 6, 2026
b04cf64
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Apr 6, 2026
4d809f2
Fixes format
bechols97 Apr 6, 2026
7c99ac3
Adds documentation for RAJA::messages
bechols97 Apr 6, 2026
5a4cf02
Minor fixes to docs
bechols97 Apr 6, 2026
d9ca533
Expands on queue policies in documentation
bechols97 Apr 6, 2026
7b6c02b
More edits to documentation
bechols97 Apr 6, 2026
a811496
Apply suggestions to example from code review
bechols97 Apr 6, 2026
ffb0803
Updates host resource variable name to be more consistent
bechols97 Apr 6, 2026
d686051
Adds some considerations for applications
bechols97 Apr 7, 2026
4cb5fcb
Removes unused test
bechols97 Apr 7, 2026
83b2df5
Updates docs
bechols97 Apr 7, 2026
3de6af7
Updates comments on incomplete policies
bechols97 Apr 7, 2026
03313af
Formats code
bechols97 Apr 7, 2026
605e17b
Apply suggestions to documentation from code review
bechols97 Apr 7, 2026
5f5ec23
More documentation fixes based on feedback
bechols97 Apr 7, 2026
54c5808
Update comment in examples/messages-forall.cpp based on suggestion in PR
bechols97 Apr 7, 2026
55b6a40
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 May 7, 2026
4925666
Updates mapping of messages to callbacks to use a map instead of vector
bechols97 May 7, 2026
983e48a
Updates comments
bechols97 May 7, 2026
4762daa
Updates unsubscribe_all(msg_id) to erase entry
bechols97 May 7, 2026
583c726
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 May 12, 2026
bbb611d
Merge branch 'develop' into feature/bechols97/device_messages
rhornung67 May 21, 2026
0b31063
Adds optional allocator
bechols97 Jun 9, 2026
ee7735f
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Jun 9, 2026
874a5d6
Fixes build
bechols97 Jun 9, 2026
225a7ae
Adds back placement new for creating object lifetime
bechols97 Jun 9, 2026
07a1ea4
Adds missing typename
bechols97 Jun 9, 2026
73f49b3
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Jun 9, 2026
534097a
Update docs/sphinx/user_guide/feature/messages.rst
bechols97 Jun 15, 2026
da2a308
Updates to use camel case and fixes typename
bechols97 Jun 15, 2026
9eb95f1
Adjusts documentation
bechols97 Jun 15, 2026
d5fe17e
Fixes comparison operator
bechols97 Jun 15, 2026
20f9e33
Moves to one allocator and resource
bechols97 Jun 18, 2026
6f8ef8e
Fixes move assignment for propagation on move assignment
bechols97 Jun 25, 2026
4310d20
Updates documentation for custom allocator
bechols97 Jun 25, 2026
86572cf
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Jun 25, 2026
c6c3769
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Jul 1, 2026
72fab89
Apply suggestions from code review
bechols97 Jul 6, 2026
91eaabe
Adds ranges version of find_if
bechols97 Jul 6, 2026
40e609b
Reduces duplicate code
bechols97 Jul 6, 2026
cf19e8d
Adds non-const accessors
bechols97 Jul 6, 2026
0135fc3
Updates CAS loop to use generic atomic in RAJA
bechols97 Jul 6, 2026
adddc48
Adjusts to use long stored allocator
bechols97 Jul 6, 2026
4efd987
Moves hash_combine to detail namespace
bechols97 Jul 6, 2026
6f135db
Adds some functional tests for messages
bechols97 Jul 7, 2026
5d0c0d0
Merge branch 'develop' into feature/bechols97/device_messages
bechols97 Jul 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions docs/sphinx/user_guide/feature/messages.rst
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
Comment thread
bechols97 marked this conversation as resolved.
Outdated
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.
Comment thread
bechols97 marked this conversation as resolved.
Outdated
Comment thread
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,
Comment thread
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).
Comment thread
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
Comment thread
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.
Comment thread
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``.
1 change: 1 addition & 0 deletions docs/sphinx/user_guide/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ materials that provide detailed examples of usage.
feature/workgroup
feature/vectorization
feature/jit
feature/messages
feature/plugins
4 changes: 4 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ raja_add_executable(
NAME resource-forall
SOURCES resource-forall.cpp)

raja_add_executable(
NAME messages-forall
SOURCES messages-forall.cpp)

raja_add_executable(
NAME dynamic-forall
SOURCES dynamic-forall.cpp)
Expand Down
Loading
Loading