| Issue |
203915
|
| Summary |
[Flang][OpenMP] - Excessive compile time when `_FortranAAssign` is called in OpenMP target regions
|
| Labels |
flang
|
| Assignees |
bhandarkar-pranav
|
| Reporter |
bhandarkar-pranav
|
## Description
OpenMP target regions that generate calls to `_FortranAAssign` experience significantly longer compile times. This occurs when using the `firstprivate` clause, which requires copying array data to the device. The compile time overhead is approximately 30x compared to equivalent code using `private` (which does not generate `_FortranAAssign` calls).
## Reproducer - Slow Case (with firstprivate)
```fortran
! test_firstprivate.f90
! This version uses firstprivate, which generates _FortranAAssign calls
program test_firstprivate
implicit none
integer, allocatable :: arr(:)
integer :: source(8)
integer :: result
integer :: i
! Initialize source array
do i = 1, 8
source(i) = i * 10
end do
! Allocate array
allocate(arr(8))
arr(:) = 0
!$omp target firstprivate(source) map(tofrom: arr) map(from: result)
! firstprivate(source) causes _FortranAAssign to be called
arr(:) = source(:)
result = arr(1) + arr(8)
!$omp end target
end program test_firstprivate
```
**Compile time:** ~29 seconds
## Comparison - Fast Case (with private)
```fortran
! test_firstprivate.f90
! This version uses firstprivate, which generates _FortranAAssign calls
program test_private
implicit none
integer, allocatable :: arr(:)
integer :: source(8)
integer :: result
integer :: i
! Initialize source array
do i = 1, 8
source(i) = i * 10
end do
! Allocate array
allocate(arr(8))
arr(:) = 0
!$omp target private(source) map(tofrom: arr) map(from: result)
! firstprivate(source) causes _FortranAAssign to be called
arr(:) = source(:)
result = arr(1) + arr(8)
!$omp end target
deallocate(arr)
end program test_private
```
**Compile time:** ~0.9 seconds
## Build Command
```bash
flang-new -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -O2 test_firstprivate.f90 -o test.out
```
## Root Cause
The `firstprivate` clause requires the runtime to set up array data on the device side based on the array on the host. This generates calls to `_FortranAAssign`.
The `private` clause, by contrast, only allocates the array on the device without copying data, avoiding calls to `_FortranAAssign` entirely.
## Impact
- **30x compile-time overhead** when using `firstprivate` compared to `private`
- This makes development iteration times impractical for codes using `firstprivate` arrays with OpenMP GPU offloading
- The overhead is present regardless of array size or complexity
## Environment
- **Compiler:** flang-new (upstream LLVM/Flang main branch)
- **Target:** `amdgcn-amd-amdhsa` (AMD GPU)
- **Optimization level:** `-O2`
- **OpenMP flags:** `-fopenmp -fopenmp-targets=amdgcn-amd-amdhsa`
Also related to https://github.com/llvm/llvm-project/issues/200922
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs