You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clang/docs/HIPSupport.rst
+35-7Lines changed: 35 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -176,8 +176,36 @@ Predefined Macros
176
176
* - ``HIP_API_PER_THREAD_DEFAULT_STREAM``
177
177
- Alias to ``__HIP_API_PER_THREAD_DEFAULT_STREAM__``. Deprecated.
178
178
179
-
Function Pointers Support in Clang with HIP
180
-
===========================================
179
+
Compilation Modes
180
+
=================
181
+
182
+
Each HIP source file contains intertwined device and host code. Depending on the chosen compilation mode by the compiler options ``-fno-gpu-rdc`` and ``-fgpu-rdc``, these portions of code are compiled differently.
183
+
184
+
Device Code Compilation
185
+
-----------------------
186
+
187
+
**``-fno-gpu-rdc`` Mode (default)**:
188
+
189
+
- Compiles to a self-contained, fully linked offloading device binary for each offloading device architecture.
190
+
- Device code within a Translation Unit (TU) cannot call functions located in another TU.
191
+
192
+
**``-fgpu-rdc`` Mode**:
193
+
194
+
- Compiles to a bitcode for each GPU architecture.
195
+
- For each offloading device architecture, the bitcode from different TUs are linked together to create a single offloading device binary.
196
+
- Device code in one TU can call functions located in another TU.
197
+
198
+
Host Code Compilation
199
+
---------------------
200
+
201
+
**Both Modes**:
202
+
203
+
- Compiles to a relocatable object for each TU.
204
+
- These relocatable objects are then linked together.
205
+
- Host code within a TU can call host functions and launch kernels from another TU.
206
+
207
+
Function Pointers Support
208
+
=========================
181
209
182
210
Function pointers' support varies with the usage mode in Clang with HIP. The following table provides an overview of the support status across different use-cases and modes.
183
211
@@ -195,24 +223,24 @@ Function pointers' support varies with the usage mode in Clang with HIP. The fol
195
223
- Not Supported
196
224
- Supported
197
225
198
-
In the ``-fno-gpu-rdc`` mode, the compiler calculates the resource usage of kernels based only on functions present within the same Translation Unit (TU). This mode does not support the use of function pointers defined in a different TU due to the possibility of incorrect resource usage calculations, leading to undefined behavior.
226
+
In the ``-fno-gpu-rdc`` mode, the compiler calculates the resource usage of kernels based only on functions present within the same TU. This mode does not support the use of function pointers defined in a different TU due to the possibility of incorrect resource usage calculations, leading to undefined behavior.
199
227
200
228
On the other hand, the ``-fgpu-rdc`` mode allows the definition and use of function pointers across different TUs, as resource usage calculations can accommodate functions from disparate TUs.
201
229
202
-
Virtual Function Support in Clang with HIP
203
-
==========================================
230
+
Virtual Function Support
231
+
========================
204
232
205
233
In Clang with HIP, support for calling virtual functions of an object in device or host code is contingent on where the object is constructed.
206
234
207
-
- **Constructed in Device Code**: Virtual functions of an object can be called in device code if the object is constructed in device code.
235
+
- **Constructed in Device Code**: Virtual functions of an object can be called in device code on a specific offloading device if the object is constructed in device code on an offloading device with the same architecture.
208
236
- **Constructed in Host Code**: Virtual functions of an object can be called in host code if the object is constructed in host code.
209
237
210
238
In other scenarios, calling virtual functions is not allowed.
211
239
212
240
Explanation
213
241
-----------
214
242
215
-
An object constructed on the device side contains a pointer to the virtual function table on the device side, which is not accessible in host code, and vice versa. Thus, trying to invoke virtual functions from a context different from where the object was constructed will be disallowed because the appropriate virtual table cannot be accessed.
243
+
An object constructed on the device side contains a pointer to the virtual function table on the device side, which is not accessible in host code, and vice versa. Thus, trying to invoke virtual functions from a context different from where the object was constructed will be disallowed because the appropriate virtual table cannot be accessed. The virtual function tables for offloading devices with different architecures are different, therefore trying to invoke virtual functions from an offloading device with a different architecture than where the object is constructed is also disallowed.
0 commit comments