[AMDGCN] Aliases for kernel functions do not generate aliases for associated kernel descriptor symbols
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This was discovered on the 0.16.0+ versions of the Zig compiler. When the following code is compiled on the AMDGCN architecture, the compiler [asks LLVM](https://codeberg.org/ziglang/zig/src/commit/eff54d672b863c46c3df7f7bbc7239dd585e83f8/src/codegen/llvm.zig#L1539) to add an alias for the internal function symbol.
```zig
// kernel.zig
export fn vector_add(
a: [*]const f64,
b: [*]const f64,
c: [*]f64,
) callconv(.kernel) void {
const idx = @workItemId(0);
if (idx < 256) {
c[idx] = a[idx] + b[idx];
}
}
```
Since LLVM does not additionally generate an alias for the associated kernel descriptor symbol, it is impossible for the HIP runtime to find and load this function.
```
$ zig build-obj -target amdgcn-amdhsa-none -mcpu=gfx1101 kernel.zig -femit-bin=kernel.o
$ llvm-readelf --symbols ./kernel.o
Symbol table '.symtab' contains 29 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 952 FUNC LOCAL PROTECTED 1 kernel.vector_add
2: 0000000000000000 64 OBJECT LOCAL DEFAULT 2 kernel.vector_add.kd
...
28: 0000000000000000 952 FUNC GLOBAL DEFAULT 1 vector_add
```
Contributor guide
Research direction
Reproduce the issue with kernel.zig using the shown zig build-obj command and inspect codegen/llvm.zig around line 1539, where the function alias is requested from LLVM. Compare the emitted symbols with llvm-readelf and trace how the AMDGCN kernel descriptor is represented. Done means the exported alias is accompanied by a usable alias for its associated kernel descriptor so the HIP runtime can load it.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100