2025-05-13 16:26:28 -04:00
.. meta ::
2025-05-21 16:59:00 -04:00
:description: Information on how to compile and run rocSHMEM applications.
2025-05-13 16:26:28 -04:00
:keywords: rocSHMEM, ROCm, library, API, compile, link, hipcc
2025-05-08 13:39:28 -04:00
2025-05-21 16:59:00 -04:00
.. _running-applications:
2025-05-13 16:26:28 -04:00
--------------------------------------------------
2025-05-21 16:59:00 -04:00
Compiling and running rocSHMEM applications
2025-05-13 16:26:28 -04:00
--------------------------------------------------
2025-05-21 16:59:00 -04:00
This topic explains how to compile and run rocSHMEM applications.
2025-05-13 16:26:28 -04:00
Compiling and linking with rocSHMEM
2025-05-08 13:39:28 -04:00
-----------------------------------
2025-05-13 16:26:28 -04:00
rocSHMEM is a library that can be statically linked to your application during compilation with ``hipcc`` . For more information, see :doc: `HIPCC <hipcc:index>` .
2025-05-08 13:39:28 -04:00
2025-09-25 10:24:59 -04:00
When compiling your application with ``hipcc`` , you must include the rocSHMEM header files and the rocSHMEM library.
2025-05-21 16:59:00 -04:00
Because rocSHMEM depends on MPI (Message Passing Interface), you must manually add the arguments for MPI linkage instead of using ``mpicc`` .
2025-05-08 13:39:28 -04:00
2025-09-25 10:24:59 -04:00
When using ``hipcc`` directly without a build system, it's recommended to perform the compilation and linking steps separately.
2025-05-08 13:39:28 -04:00
2025-05-13 16:26:28 -04:00
Example compile and link commands are provided at the top of the example files in the ``examples`` directory:
2025-05-08 13:39:28 -04:00
.. code-block :: bash
# Compile
hipcc -c -fgpu-rdc -x hip rocshmem_allreduce_test.cc \
-I/opt/rocm/include \
-I$ROCSHMEM_INSTALL_DIR /include \
-I$OPENMPI_UCX_INSTALL_DIR /include/
# Link
hipcc -fgpu-rdc --hip-link rocshmem_allreduce_test.o -o rocshmem_allreduce_test \
$ROCSHMEM_INSTALL_DIR /lib/librocshmem.a \
$OPENMPI_UCX_INSTALL_DIR /lib/libmpi.so \
-L/opt/rocm/lib -lamdhip64 -lhsa-runtime64
2025-09-25 10:24:59 -04:00
If your project uses CMake, see
2025-05-08 13:39:28 -04:00
`Using CMake with AMD ROCm <https://rocmdocs.amd.com/en/latest/conceptual/cmake-packages.html> `_ .
2025-05-21 16:59:00 -04:00
Running a rocSHMEM application
2025-05-08 13:39:28 -04:00
--------------------------
2025-09-25 10:24:59 -04:00
Applications using rocSHMEM typically deploy multiple processes, usually one per GPU.
2025-05-13 16:26:28 -04:00
The MPI launcher, for example, ``mpiexec`` with Open MPI, is used to start the required number
of processes. For example, to launch two ``getmem`` example processes (available when compiled from source):
2025-05-08 13:39:28 -04:00
.. code-block :: bash
mpiexec --map-by numa --mca pml ucx --mca osc ucx -np 2 ./build/examples/rocshmem_getmem_test
2025-05-13 16:26:28 -04:00
See the `Open MPI documentation <https://docs.open-mpi.org/en/main/> `_ for more information about ``mpiexec`` command line parameters.
2025-05-08 13:39:28 -04:00
.. note ::
2025-05-13 16:26:28 -04:00
Some systems may have multiple MPI installations, some of which do not
have GPU support enabled. You must use the ``mpiexec`` from the expected
MPI library, especially when using the MPI built by yourself
2025-05-08 13:39:28 -04:00
as part of :ref: `install-dependencies` .
2025-05-13 16:26:28 -04:00
Environment variables
2025-05-08 13:39:28 -04:00
---------------------
2025-05-13 16:26:28 -04:00
You can control the behavior of rocSHMEM by using the following environment variables:
2025-05-08 13:39:28 -04:00
.. list-table :: Environment Variables
:widths: 30 10 20
:header-rows: 1
* - Name
- Default Value
- Description
* - ROCSHMEM_HEAP_SIZE
2025-05-13 16:26:28 -04:00
- 1
- Defines the size of the rocSHMEM symmetric heap in GB.
2025-05-08 13:39:28 -04:00
Note the heap is on the GPU memory.
* - ROCSHMEM_MAX_NUM_CONTEXTS
- 1024
2025-05-13 16:26:28 -04:00
- Defines the number of contexts an application can use.
2025-05-08 13:39:28 -04:00
* - ROCSHMEM_MAX_NUM_TEAMS
- 40
2025-05-13 16:26:28 -04:00
- Defines the number of teams an application can use.
2025-06-21 13:23:11 -05:00
* - ROCSHMEM_UNIQUEID_WITH_MPI
- 0
- Defines whether rocSHMEM is expected to use MPI when using the uniqueId based initialization.
2025-07-10 18:49:10 -04:00
* - ROCSHMEM_RO_DISABLE_IPC
- 0
- Defines whether to force using the RO conduit even when IPC is available.
2025-09-25 10:24:59 -04:00
* - ROCSHMEM_GDA_ALTERNATE_QP_PORTS
- 1
- Enables/Disables having QPs alternate their mappings across rocSHMEM contexts. This helps saturate bandwidth on multiport bonded interfaces.