Files
TheRock/rocm-libraries/projects/hipthreads/docs/reference/std-to-hip-mapping.rst
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

86 lines
2.4 KiB
ReStructuredText

.. meta::
:description: Mapping from C++ standard threading primitives to hipThreads equivalents
:keywords: hipThreads, ROCm, std, hip, mapping, thread, mutex, condition_variable
.. _std-to-hip-mapping:
******************************************
Mapping ``std::`` to ``hip::``
******************************************
hipThreads mirrors the C++ Concurrency Support Library.
In most cases, porting CPU code means replacing the ``std::`` qualifier with ``hip::`` and adding ``__device__`` or ``__host__ __device__`` to the callables that run on the GPU.
The tables below list the supported primitives and how they correspond to the standard library.
For behavioral differences that have no standard-library analogue, see :ref:`limitations`.
Threads
=======
.. list-table::
:header-rows: 1
:widths: 40 40 20
* - C++ standard
- hipThreads
- Header
* - ``std::thread``
- ``hip::wthread``
- ``<hip/thread>``
* - ``std::thread::id``
- ``hip::wthread::id``
- ``<hip/thread>``
* - ``std::this_thread::get_id``
- ``hip::this_thread::get_id``
- ``<hip/thread>``
* - ``std::this_thread::yield``
- ``hip::this_thread::pseudo_yield``
- ``<hip/thread>``
* - ``std::this_thread::sleep_for``
- ``hip::this_thread::sleep_for``
- ``<hip/thread>``
* - *(no equivalent)*
- ``hip::this_thread::get_fiber_id``
- ``<hip/thread>``
Mutexes and locks
=================
.. list-table::
:header-rows: 1
:widths: 40 40 20
* - C++ standard
- hipThreads
- Header
* - ``std::mutex``
- ``hip::spin_mutex`` (also ``hip::pseudo_mutex``)
- ``<hip/mutex>``, ``<hip/pseudo_mutex>``
* - ``std::lock_guard``
- ``hip::lock_guard``
- ``<hip/mutex>``
* - ``std::unique_lock``
- ``hip::unique_lock``
- ``<hip/mutex>``
Condition variables
===================
.. list-table::
:header-rows: 1
:widths: 40 40 20
* - C++ standard
- hipThreads
- Header
* - ``std::condition_variable_any``
- ``hip::condition_variable_any`` (also
``hip::spin_condition_variable``, ``hip::pseudo_condition_variable``)
- ``<hip/condition_variable>``, ``<hip/pseudo_condition_variable>``
.. note::
The ``spin_`` variants busy-wait.
The ``pseudo_`` variants busy-wait but periodically call ``pseudo_yield`` to let other GPU work progress.
Choose a ``pseudo_`` primitive only when you can guarantee no yield-loops occur; see :ref:`limitations`.