Index: clang/docs/HIPSupport.rst =================================================================== --- /dev/null +++ clang/docs/HIPSupport.rst @@ -0,0 +1,104 @@ +.. raw:: html + + + +.. role:: none +.. role:: part +.. role:: good + +.. contents:: + :local: + +=========== +HIP Support +=========== + +`HIP (Heterogeneous-Compute Interface for Portability) `_ +is a C++ Runtime API and Kernel Language that allows developers to create portable applications for +GPUs from single source code. + +Clang supports HIP on `ROCm platform `_. + +Example Usage +============= + +To compile a HIP program, you can use the following command: + +.. code-block:: shell + + clang -c --offload-arch=gfx906 test.hip -o test.o + +To link a HIP program, you can use this command: + +.. code-block:: shell + + clang --hip-link --offload-arch=gfx906 test.o -o test + +In the above commands, ``gfx906`` is the GPU architecture that the code is being compiled for. +The supported GPU architectures can be found in the `AMDGPU Processor Table `_. +Alternatively, you can run the ``amdgpu-arch`` tool that comes with Clang to list the GPU architecture on your sytem: + +.. code-block:: shell + + amdgpu-arch + +You can also use ``--offload-arch=native`` to let ``amdgpu-arch`` automatically detect the GPU architecture on your system: + +.. code-block:: shell + + clang -c --offload-arch=native test.hip -o test.o + +Environment Variables +===================== + +.. list-table:: + :header-rows: 1 + + * - Variable + - Description + - Default Value + * - ``ROCM_PATH`` + - ROCm installation path. + - Empty + * - ``HIP_PATH`` + - HIP runtime installation path. + - Empty + * - ``HIP_DEVICE_LIB_PATH`` + - HIP device library installation path. + - Empty + +Predefined Macros +================= + +.. list-table:: + :header-rows: 1 + + * - Macro + - Description + * - ``__CLANG_RDC__`` + - This macro indicates that Clang is used for relocatable device code compilation (RDC). + * - ``__HIP__`` + - This macro is defined when the HIP language option is enabled. It is used to indicate that the code is being compiled for the HIP environment. + * - ``__HIPCC__`` + - This macro indicates that the code is being compiled using the HIP compiler. + * - ``__HIP_MEMORY_SCOPE_SINGLETHREAD`` + - This macro is set to 1 and represents the memory scope that is limited to a single thread in HIP. + * - ``__HIP_MEMORY_SCOPE_WAVEFRONT`` + - This macro is set to 2 and represents the memory scope that is limited to a wavefront in HIP. + * - ``__HIP_MEMORY_SCOPE_WORKGROUP`` + - This macro is set to 3 and represents the memory scope that is limited to a workgroup in HIP. + * - ``__HIP_MEMORY_SCOPE_AGENT`` + - This macro is set to 4 and represents the memory scope that is limited to an agent in HIP. + * - ``__HIP_MEMORY_SCOPE_SYSTEM`` + - This macro is set to 5 and represents the memory scope that is limited to the system in HIP. + * - ``__HIP_DEVICE_COMPILE__`` + - This macro is defined when the code is being compiled for a HIP device. + * - ``__HIP_NO_IMAGE_SUPPORT`` + - This macro is set to 1 when the target device does not support HIP image functions. + * - ``HIP_API_PER_THREAD_DEFAULT_STREAM`` + - This macro is defined when the GPU default stream kind is set to per-thread. +