Commit 932022e
authored
Force array data pointers to stay flat in AMD GPU codegen (#29053)
Force array data pointers to stay flat in AMD GPU codegen
The `shoc-sort` GPU test crashed with a "Memory access fault by GPU"
only when compiled with `--optimize`, and bisecting the LLVM backend
pipeline traced the regression to the `InferAddressSpaces` pass (which
only runs at `-O1` and above). Comparing device IR between the working
and crashing builds showed that with optimizations every array data
pointer was rewritten from the flat/generic address space to
`addrspace(1)` global, and the resulting loads were stamped with
`!amdgpu.noclobber`. That `noclobber` is incorrect for the recursive
in-place scan kernel, which reads and writes the same buffer through
different array descriptors, so stale reads corrupted the offset data
and produced an out-of-bounds store in `reorderData`.
Chapel materializes array data pointers by chasing the array descriptor
in memory, and `getAssumedAddrSpace` assumes any flat pointer loaded
from the kernarg segment is global, which is what drives the unsafe
promotion. To prevent it, the array data base pointer is now laundered
through an identity inline-asm "barrier" (`call ptr asm "",
"=v,0"(ptr)`) that address-space inference cannot see through, keeping
the pointer and everything derived from it flat. The barrier is emitted
only for `_ddata` base pointers in `codegenElementPtr`, and only when
generating AMD GPU device code, so non-GPU and CUDA codegen and all
other loads are unaffected.
I don't actually know if this is the best possible fix, but it works and
seems to have no adverse affects. This feels brittle and like it could
inhibit other optimizations, but its the best fix I have at this time.
Note: AI was used to help me diagnose and fix this failure, the concept
for the fix and the code for it are both AI generated.
Related to #28955
[Reviewed by @benharsh]1 file changed
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
697 | 698 | | |
698 | 699 | | |
699 | 700 | | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
700 | 731 | | |
701 | 732 | | |
702 | 733 | | |
| |||
1502 | 1533 | | |
1503 | 1534 | | |
1504 | 1535 | | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
1505 | 1545 | | |
1506 | 1546 | | |
1507 | 1547 | | |
| |||
0 commit comments