| Issue |
244359
|
| Summary |
[Clang][OpenMP] GPU parallel callback type mismatch
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
amad00r
|
```c
void __kmpc_parallel_60(IdentTy *ident, int32_t, int32_t if_expr,
int32_t num_threads, int proc_bind, FnPtrTy fn,
FnPtrTy wrapper_fn, void **args, int64_t nargs,
int32_t nt_strict);
```
__kmpc_parallel_60 takes an outlined function pointer, an array of capture arguments, and the number of captures. It invokes the function with two thread-ID pointers followed by the appropriate number of elements from the array, all passed as pointers.
When __kmpc_parallel_60 is inlined during device LTO, the callback’s target can become known. However, Clang can emit the outlined function with a combination of pointer and uintptr_t parameters. The resulting call may therefore pass pointer arguments to integer parameters.
This mismatch prevents subsequent inlining: CallBase::getCalledFunction() returns nullptr when the call signature differs from the function signature, even if the called operand is a known function. The inliner consequently treats the call as indirect.
Attributor’s indirect-call specialization in OpenMPOpt previously masked this problem as call promotion inserted casts to reconcile the argument types. PR #219323 introduced a limit of three callees for specialization at a call site, exposing the path without those casts.
For example:
```c
void foo(float *V) {
#pragma omp target teams distribute parallel for
for (int i = 0; i < 10; ++i) (*V)++;
#pragma omp target teams distribute parallel for
for (int i = 0; i < 10; ++i) (*V)++;
#pragma omp target teams distribute parallel for
for (int i = 0; i < 10; ++i) (*V)++;
#pragma omp target teams distribute parallel for
for (int i = 0; i < 10; ++i) (*V)++;
}
```
With this reproducer on AMD gfx90a, I observe flat accesses through V instead of global accesses when the relevant indirect calls inside __kmpc_parallel_60 are not specialized.
The missed inlining also explains the lost address-space inference. AMDGPUPromoteKernelArgumentsPass runs only on kernel functions, and InferAddressSpacesPass performs inference within individual functions. Neither propagates a kernel argument’s address-space information through an ordinary call into the outlined body. For a direct kernel pointer argument such as V, InferAddressSpacesPass can infer global addressing once the accesses are exposed in the kernel.
The expected behavior is that these accesses retain global addressing regardless of whether Attributor specializes the callback call.
I propose to fix this directly in the codegen. A simple fix is to emit GPU parallel outlines with pointer parameters matching the runtime’s calls. However, I would like to discuss the possibility of generating an aggregate outline, which would fix the problem while allowing a simpler __kmpc_parallel_60 signature and implementation.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs