Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: randyh62 <[email protected]>
  • Loading branch information
neon60 and randyh62 committed Nov 10, 2024
1 parent f401231 commit 693a7b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
26 changes: 5 additions & 21 deletions docs/how-to/hip_runtime_api/error_handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,20 @@ while :cpp:func:`hipPeekAtLastError` just returns the error without changing it.
To get a human readable version of the errors, :cpp:func:`hipGetErrorString()`
and :cpp:func:`hipGetErrorName()` can be used.

Error handling usage
================================================================================

Error handling functions enable developers to implement appropriate error
handling strategies, such as retry mechanisms, resource cleanup, or graceful
degradation.

The descriptions of the important :ref:`error handling functions <error_handling_reference>`
are the following:

* :cpp:func:`hipGetLastError` returns the last error that occurred during a HIP
runtime API call and resets the error code to :cpp:enumerator:`hipSuccess`.
* :cpp:func:`hipPeekAtLastError` returns the last error that occurred during a HIP
runtime API call **without** resetting the error code.
* :cpp:func:`hipGetErrorName` converts a HIP error code to a string representing
the error name.
* :cpp:func:`hipGetErrorString` converts a HIP error code to a string describing
the error.

Best practices of HIP error handling:

1. Check errors after each API call - Avoid error propagation.
2. Use macros for error checking - Check :ref:`hip_check_macros`.
3. Handle errors gracefully - Free resources and provide meaningful error
messages to the user.

For more details on the error handling functions, see :ref:`error handling
functions reference page <error_handling_reference>`.

.. _hip_check_macros:

HIP check macros
--------------------------------------------------------------------------------
================================================================================

HIP uses check macros to simplify error checking and reduce code duplication.
The ``HIP_CHECK`` macros are mainly used to detect and report errors. It can
Expand All @@ -68,7 +52,7 @@ print. The ``HIP_CHECK`` macro example:
}
Complete example
--------------------------------------------------------------------------------
================================================================================

A complete example to demonstrate the error handling with a simple addition of
two values kernel:
Expand Down
35 changes: 18 additions & 17 deletions docs/how-to/hip_runtime_api/initialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,32 @@ Initialize the HIP runtime

The HIP runtime is initialized automatically when the first HIP API call is
made. However, you can explicitly initialize it using :cpp:func:`hipInit`,
to be able to control the timing of the initialization.
to be able to control the timing of the initialization. The manual
initialization can be useful to ensure that the GPU is initialized and
ready, or to isolate GPU initialization time from other parts of
your program.

.. note::

You can use :cpp:func:`hipDeviceReset()` to delete all streams created, memory allocated,
kernels running and events created by the current process. Any new HIP API
call initializes the HIP runtime again.

Querying and setting GPUs
================================================================================

If multiple GPUs are available, it's worth to query and select the desired GPU(s)
based on properties.
If multiple GPUs are available in the system, you can query and select the
desired GPU(s) to use based on device properties, such as size of global memory,
size shared memory per block, support of cooperative launch and support of
managed memory.

Querying GPUs
--------------------------------------------------------------------------------

The properties of a gpu can be queried using :cpp:func:`hipGetDeviceProperties`,
which returns a struct of :cpp:struct:`hipDeviceProp_t`. This struct can be
The properties of a GPU can be queried using :cpp:func:`hipGetDeviceProperties`,
which returns a struct of :cpp:struct:`hipDeviceProp_t`. The properties in the struct can be
used to identify a device or give an overview of hardware characteristics, that
might make one gpu better suited for the task at hand than others.
might make one GPU better suited for the task than others.

The :cpp:func:`hipGetDeviceCount` function returns the number of available GPUs,
which can be used to loop over the available GPUs.
Expand Down Expand Up @@ -85,17 +96,7 @@ operations. This function performs several key tasks:
Prepares the device for resource allocation, such as memory allocation and
stream creation.

- Check device availablity
- Check device availability

Checks for errors in device selection and returns error if the specified
device is not available or not capable of executing HIP operations.

Finalize
================================================================================

:cpp:func:`hipDeviceReset()` deletes all streams created, memory allocated,
kernels running and events created by the current process. Make sure that no
other thread is using the device or streams, memory, kernels or events
associated with the current device.

Any new HIP API call initializes the HIP runtime again.

0 comments on commit 693a7b7

Please sign in to comment.