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

Document Kokkos::num_devices() #486

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docs/source/API/core/Utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Utilities
./utilities/swap
./utilities/timer
./utilities/device_id
./utilities/num_devices
./utilities/num_threads
./utilities/experimental
6 changes: 6 additions & 0 deletions docs/source/API/core/utilities/device_id.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Returns the id of the device that is used by ``DefaultExecutionSpace`` or

**See also**

.. _num_devices : num_devices.html

.. |num_devices| replace:: ``num_devices``

.. _num_threads : num_threads.html

.. |num_threads| replace:: ``num_threads``
Expand All @@ -29,6 +33,8 @@ Returns the id of the device that is used by ``DefaultExecutionSpace`` or

.. |InitializationSettings| replace:: ``InitializationSettings``

|num_devices|_: returns the number of devices available to Kokkos

|num_threads|_: returns the number of threads used by Kokkos

|initialize|_: initializes the Kokkos execution environment
Expand Down
70 changes: 70 additions & 0 deletions docs/source/API/core/utilities/num_devices.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
``Kokkos::num_devices``
=======================

.. role:: cppkokkos(code)
:language: cppkokkos

Defined in header ``<Kokkos_Core.hpp>``

.. code-block:: cpp

[[nodiscard]] int num_devices() noexcept; // (since 4.3)

Returns the number of available devices on the system or ``-1`` if only host backends are enabled.

Notes
-----

``Kokkos::num_devices()`` may be used to determine the number of devices that
are available to Kokkos for execution.
It is one of the few runtime functions that may be called before
``Kokkos::initialize()`` or after ``Kokkos::finalize()``.

Example
-------

.. code-block:: cpp

#include <Kokkos_Core.hpp>
#include <iostream>

int main(int argc, char* argv[]) {
if (Kokkos::num_devices() == 0) {
std::cerr << "no device available for execution\n";
return 1;
}
Kokkos::initialize(argc, argv);
// do stuff
Kokkos::finalize();
return 0;
}


----

**See also**

.. _device_id : device_id.html

.. |device_id| replace:: ``device_id``

.. _num_threads : num_threads.html

.. |num_threads| replace:: ``num_threads``

.. _initialize: ../initialize_finalize/initialize.html

.. |initialize| replace:: ``initialize``

.. _InitializationSettings: ../initialize_finalize/InitializationSettings.html

.. |InitializationSettings| replace:: ``InitializationSettings``

|device_id|_: returns the id of the device used by Kokkos

|num_threads|_: returns the number of threads used by Kokkos

|initialize|_: initializes the Kokkos execution environment

|InitializationSettings|_: settings for initializing Kokkos

6 changes: 6 additions & 0 deletions docs/source/API/core/utilities/num_threads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Returns the number of concurrent threads that are used by ``DefaultHostExecution

.. |device_id| replace:: ``device_id``

.. _num_devices : num_devices.html

.. |num_devices| replace:: ``num_devices``

.. _initialize: ../initialize_finalize/initialize.html

.. |initialize| replace:: ``initialize``
Expand All @@ -28,6 +32,8 @@ Returns the number of concurrent threads that are used by ``DefaultHostExecution

.. |InitializationSettings| replace:: ``InitializationSettings``

|num_devices|_: returns the number of devices available to Kokkos

|device_id|_: returns the id of the device used by Kokkos

|initialize|_: initializes the Kokkos execution environment
Expand Down
Loading