Skip to content

Commit 2bf4889

Browse files
authored
[HIP] document difference with CUDA (#86838)
1 parent a8f9f85 commit 2bf4889

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

clang/docs/HIPSupport.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ Host Code Compilation
208208
- These relocatable objects are then linked together.
209209
- Host code within a TU can call host functions and launch kernels from another TU.
210210

211+
Syntax Difference with CUDA
212+
===========================
213+
214+
Clang's front end, used for both CUDA and HIP programming models, shares the same parsing and semantic analysis mechanisms. This includes the resolution of overloads concerning device and host functions. While there exists a comprehensive documentation on the syntax differences between Clang and NVCC for CUDA at `Dialect Differences Between Clang and NVCC <https://llvm.org/docs/CompileCudaWithLLVM.html#dialect-differences-between-clang-and-nvcc>`_, it is important to note that these differences also apply to HIP code compilation.
215+
216+
Predefined Macros for Differentiation
217+
-------------------------------------
218+
219+
To facilitate differentiation between HIP and CUDA code, as well as between device and host compilations within HIP, Clang defines specific macros:
220+
221+
- ``__HIP__`` : This macro is defined only when compiling HIP code. It can be used to conditionally compile code specific to HIP, enabling developers to write portable code that can be compiled for both CUDA and HIP.
222+
223+
- ``__HIP_DEVICE_COMPILE__`` : Defined exclusively during HIP device compilation, this macro allows for conditional compilation of device-specific code. It provides a mechanism to segregate device and host code, ensuring that each can be optimized for their respective execution environments.
224+
211225
Function Pointers Support
212226
=========================
213227

0 commit comments

Comments
 (0)