| Issue |
234675
|
| Summary |
[flang][cuda] Descriptors passed to kernel launches are allocated in managed memory and never freed
|
| Labels |
|
| Assignees |
|
| Reporter |
khaki3
|
Descriptors of declared device variables are freed at scope exit (`cuf.free`). Temporary descriptors created during codegen are not. When a temporary box reaches a `gpu.launch_func` or a BIND(C) device dummy, codegen places it in managed memory (`CUFAllocDescriptor`) and never frees it, so each such launch or call leaks one.
```fortran
do i = 1, n
call k<<<1,32>>>(a) ! one managed temporary descriptor per launch, never freed
end do
```
A free right after the launch is unsafe, because the kernel runs asynchronously, and `cudaFreeAsync` cannot free managed memory.
Options:
- **Pass the descriptor by value as a kernel parameter.** Nothing to free, since CUDA copies kernel arguments at launch. This changes the kernel ABI.
- **Runtime pool.** Recycle a descriptor once an event recorded after its launch has completed.
- **Stream-ordered device copy.** `cudaFreeAsync` on the launch stream after the launch. This breaks under CUDA graph capture.
For BIND(C), the foreign code should copy the descriptor if a kernel needs it, and free its copy after that kernel completes.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs