Skip to content

Commit f05e879

Browse files
committed
Document Kokkos::num_devices()
1 parent 277a752 commit f05e879

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

docs/source/API/core/Utilities.rst

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ Utilities
1313
./utilities/swap
1414
./utilities/timer
1515
./utilities/device_id
16+
./utilities/num_devices
1617
./utilities/num_threads
1718
./utilities/experimental

docs/source/API/core/utilities/device_id.rst

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Returns the id of the device that is used by ``DefaultExecutionSpace`` or
1717

1818
**See also**
1919

20+
.. _num_devices : num_devices.html
21+
22+
.. |num_devices| replace:: ``num_devices``
23+
2024
.. _num_threads : num_threads.html
2125

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

3034
.. |InitializationSettings| replace:: ``InitializationSettings``
3135

36+
|num_devices|_: returns the number of devices available to Kokkos
37+
3238
|num_threads|_: returns the number of threads used by Kokkos
3339

3440
|initialize|_: initializes the Kokkos execution environment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
``Kokkos::num_devices``
2+
=======================
3+
4+
.. role:: cppkokkos(code)
5+
:language: cppkokkos
6+
7+
Defined in header ``<Kokkos_Core.hpp>``
8+
9+
.. code-block:: cpp
10+
11+
[[nodiscard]] int num_devices() noexcept; // (since 4.3)
12+
13+
Returns the number of available devices on the system or ``-1`` if only host backends are enabled.
14+
15+
Notes
16+
-----
17+
18+
``Kokkos::num_devices()`` may be used to determine the number of devices that
19+
are available to Kokkos for execution.
20+
It is one of the few runtime functions that may be called before
21+
``Kokkos::initialize()`` or after ``Kokkos::finalize()``.
22+
23+
Example
24+
-------
25+
26+
.. code-block:: cpp
27+
28+
#include <Kokkos_Core.hpp>
29+
#include <iostream>
30+
31+
int main(int argc, char* argv[]) {
32+
if (Kokkos::num_devices() == 0) {
33+
std::cerr << "no device available for execution\n";
34+
return 1;
35+
}
36+
Kokkos::initialize(argc, argv);
37+
// do stuff
38+
Kokkos::finalize();
39+
return 0;
40+
}
41+
42+
43+
----
44+
45+
**See also**
46+
47+
.. _device_id : device_id.html
48+
49+
.. |device_id| replace:: ``device_id``
50+
51+
.. _num_threads : num_threads.html
52+
53+
.. |num_threads| replace:: ``num_threads``
54+
55+
.. _initialize: ../initialize_finalize/initialize.html
56+
57+
.. |initialize| replace:: ``initialize``
58+
59+
.. _InitializationSettings: ../initialize_finalize/InitializationSettings.html
60+
61+
.. |InitializationSettings| replace:: ``InitializationSettings``
62+
63+
|device_id|_: returns the id of the device used by Kokkos
64+
65+
|num_threads|_: returns the number of threads used by Kokkos
66+
67+
|initialize|_: initializes the Kokkos execution environment
68+
69+
|InitializationSettings|_: settings for initializing Kokkos
70+

docs/source/API/core/utilities/num_threads.rst

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Returns the number of concurrent threads that are used by ``DefaultHostExecution
2020

2121
.. |device_id| replace:: ``device_id``
2222

23+
.. _num_devices : num_devices.html
24+
25+
.. |num_devices| replace:: ``num_devices``
26+
2327
.. _initialize: ../initialize_finalize/initialize.html
2428

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

2933
.. |InitializationSettings| replace:: ``InitializationSettings``
3034

35+
|num_devices|_: returns the number of devices available to Kokkos
36+
3137
|device_id|_: returns the id of the device used by Kokkos
3238

3339
|initialize|_: initializes the Kokkos execution environment

0 commit comments

Comments
 (0)