Skip to content

Commit

Permalink
PR feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
neon60 committed Oct 21, 2024
1 parent 88fe6da commit d84fc74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 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 strategies
for handling errors, such as retry mechanisms, resource cleanup, or graceful
degradation.

Descriptions of the important :ref:`error handling functions <error_handling_reference>`
are as follows:

* :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
29 changes: 15 additions & 14 deletions docs/how-to/hip_runtime_api/initialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,24 @@ 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, when you ensure that the GPU is initialized and
ready or you want to isolate the GPU initialization time from other parts of
your program.

.. note::

:cpp:func:`hipDeviceReset()` deletes 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 in the system, you can query and select the desired GPU(s) to use
based on device properties, such as ...
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
--------------------------------------------------------------------------------
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 d84fc74

Please sign in to comment.