Observed issues › oop/cce-final-dealloc-device-abort
deallocating a finalizable object in device code aborts
Legality: not independently confirmed. Independent readings are uncertain: Nothing forbids ALLOCATE, DEALLOCATE or finalization in a declare target procedure called from target, and ft_fin is declare target. The spec requires ALLOCATE and DEALLOCATE to be thread-safe but sets no device heap or support level. A device runtime stop at the allocate is not clearly a violation. How this is checked
A declare target subroutine allocates and deallocates a local allocatable object of a type with a final subroutine. CCE 19 and 20 stop the device thread at the DEALLOCATE; CCE 21 aborts with a queue error. The same type as a non-allocatable local is finalized correctly. GCC runs it correctly.
Affected variants
| Compiler | MI300A gfx942 unified memory (XNACK 1) | MI300A gfx942 copy (XNACK 0) | MI250X gfx90a copy (XNACK 0) | MI300X gfx942 copy (XNACK 0) | MI350X gfx950 copy (XNACK 0) | A100 sm_80 separate memory | A100 sm_80 managed memory |
|---|---|---|---|---|---|---|---|
| AFAR 24.3.0 | fails another way | fails another way | unknown not run | correct | correct | n/a | n/a |
| CCE 19.0.0 | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 20.0.2 | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.3 | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.4 | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | unknown not run | n/a | n/a |
| NVHPC 25.11 | n/a | n/a | n/a | n/a | n/a | fails another way | fails another way |
| NVHPC 26.9 | n/a | n/a | n/a | n/a | n/a | fails another way | fails another way |
| GCC 16.2.0 | correct | correct | correct | correct | correct | correct | n/a |
"behaves incorrectly" / "not supported": this issue, confirmed in up to four environments (another build directory, another node, a repeat). "fails another way": a different failure, not counted as this issue. "unknown": not run there, or the runs disagree.
Messages
| Result | Compiler and GPU | Message |
|---|---|---|
| behaves incorrectly | CCE 19.0.0, MI300A unified CCE 19.0.0, MI300A copy CCE 20.0.2, MI300A unified CCE 20.0.2, MI300A copy CCE 21.0.3, MI300A unified CCE 21.0.3, MI300A copy CCE 21.0.4, MI300A unified CCE 21.0.4, MI300A copy | showThread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. |
| fails another way | AFAR 24.3.0, MI300A unified AFAR 24.3.0, MI300A copy | showsite-oop--cce-final-dealloc-device-abort.f90:29:24: warning: The usage of TO clause on DECLARE TARGET directive has been deprecated. Use ENTER clause instead. [-Wopenmp-usage]
!$omp declare target to(fin_count)
^^^^^^^^^^^^^
site-oop--cce-final-dealloc-device-abort.f90:29:24: warning: The usage of TO clause on DECLARE TARGET directive has been deprecated. Use ENTER clause instead. [-Wopenmp-usage]
!$omp declare target to(fin_count)
^^^^^^^^^^^^^
ld.lld: error: undefined symbol: flang_rt_verbose_abort(char const*, ...)
>>> referenced by <dir>:(std::__1::__throw_bad_variant_access[abi:nqn240000](char const*)) |
| fails another way | NVHPC 25.11, A100 separate NVHPC 26.9, A100 separate | showNVFORTRAN-S-1058-Call to NVHPC runtime function not supported - pgf90_calloc04a_i8 (site-oop--cce-final-dealloc-device-abort.f90: 43) 0 inform, 0 warnings, 1 severes, 0 fatal for alloc_work |
| fails another way | NVHPC 25.11, A100 managed NVHPC 26.9, A100 managed | showNVFORTRAN-S-1058-Call to NVHPC runtime function not supported - pgf90_calloc04ma_i8 (site-oop--cce-final-dealloc-device-abort.f90: 43) 0 inform, 0 warnings, 1 severes, 0 fatal for alloc_work |
Reproduce
CCE 19.0.0, MI300A unified
module load cce/19.0.0 craype-accel-amd-gfx942 rocm/6.4.3 module unload cray-mpich ftn -fopenmp -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
CCE 20.0.2, MI300A unified
module load cce/20.0.2 craype-accel-amd-gfx942 rocm/6.4.3 module unload cray-mpich ftn -fopenmp -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
CCE 21.0.3, MI300A unified
module load cce/21.0.3 craype-accel-amd-gfx942 rocm/7.2.0 module unload cray-mpich ftn -fopenmp -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
CCE 21.0.4, MI300A unified
module load cce/21.0.4 craype-accel-amd-gfx942 rocm/7.2.0 module unload cray-mpich ftn -fopenmp -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
AFAR 24.3.0, MI300X (runs correctly)
$AFAR/bin/amdflang -fopenmp --offload-arch=gfx942 -O2 repro.f90 -o repro HSA_XNACK=0 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (78 lines)
! # Finding (fortran-oop): DEALLOCATE of an allocatable finalizable object in device code aborts
!
! - toolchains and modes that fail: cce19 (CCE 19.0.0: copy, unified), cce20 (CCE 20.0.2: copy, unified), cce21 (CCE 21.0.3: copy,
! unified), cce21_4 (CCE 21.0.4: copy, unified); -O2
! - build: ftn -fopenmp -O2 (module load cce/<v> craype-accel-amd-gfx942 rocm/<r>; OpenACC: ftn -h acc)
! - failure: crash / run_error; OMP_TARGET_OFFLOAD=mandatory
! - observed: CCE 19 and 20: `Thread execution stopped at ... LINE 29 due to a Fortran allocate/deallocate statement` (SIGABRT);
! CCE 21.0.3 and 21.0.4: a queue error dump, exit 1; both modes
! - expected: `r1= 64 r2= 2144`
! - rule: Fortran 2018 7.5.6.3 para 2 (DEALLOCATE finalizes the object); the final subroutine is declare target (5.2 §1.2.6 p.19)
! - same-compiler control: a non-allocatable local of the same type (controls/final-local.f90, the family program
! oop-assignfinal-final-local): correct on every CCE release and AFAR in both modes, stored run and gate environments a-d
! (results/oop/probe/ctl2.*.final-local.*.jsonl)
! - other families: AFAR fails at the device link (afar-final-dealloc-device-link.f90); GCC 16.2 correct
! - gate and confirmer: 8 cells, 8 confirmed in the gate's four environments (a-d; results/oop/main/gate_reruns*.jsonl); confirmer
! (results/oop/main/confirm.jsonl): needs_human (R22-expected-weak) 8; R22-expected-weak means the expected value has one
! source, the generator's Python model; the values follow from the program's arithmetic (checked by hand), and GCC 16.2
! (gfx90a), GCC 16.2 (sm_80) print them on this program
! - programs (1): oop-assignfinal-final-dealloc (offload/engine/oop_gen.py; this file is the first one)
! - legality: for the cce cells: the rules (offload.engine.rules, with the fortran-oop restrictions) and AFAR's flang front end
! (-fsyntax-only) (tools/campaigns/oop.py legality, results/oop/main/legality.json)
module oop_m
implicit none
integer, parameter :: n = 64
type ft
integer :: v = 0
contains
final :: ft_fin
end type ft
integer :: fin_count = 0
!$omp declare target to(fin_count)
contains
subroutine ft_fin(o)
!$omp declare target
type(ft), intent(inout) :: o
!$omp atomic update
fin_count = fin_count + 1
end subroutine ft_fin
subroutine alloc_work(k, r)
!$omp declare target
integer, intent(in) :: k
integer, intent(out) :: r
type(ft), allocatable :: o
allocate(o)
o%v = k
r = o%v + 1
deallocate(o)
end subroutine alloc_work
end module oop_m
program oop
use omp_lib
use oop_m
implicit none
integer :: host_flag
logical :: ok
integer :: r1, r2
integer :: res(n), i
host_flag = 1
!$omp target map(from: host_flag)
host_flag = merge(1, 0, omp_is_initial_device())
!$omp end target
fin_count = 0
!$omp target update to(fin_count)
!$omp target teams distribute parallel do map(tofrom: res)
do i = 1, n
call alloc_work(i, res(i))
end do
!$omp target update from(fin_count)
r1 = fin_count
r2 = sum(res)
ok = .true.
ok = ok .and. (r1 == 64)
ok = ok .and. (r2 == 2144)
print '(a,i0)', 'r1= ', r1
print '(a,i0)', 'r2= ', r2
print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok)
end program oop
Something to add? Dispute its legality · Report it fixed in a newer release · Report a mistake on this page
Expected and observed
Observed where it behaves incorrectly
Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--cce-final-dealloc-device-abort.f90 LINE 42 due to a Fortran allocate/deallocate statement.
What the specification requires
The specification text this program relies on and the compiler is expected to support.
OpenMP 5.2 §1.2.6 p.19
Evidence
Same compiler, one change
- a non-allocatable local of the same finalizable type (no DEALLOCATE): not run yet
Control program
! control for oop-assignfinal-final-dealloc: the family program oop-assignfinal-final-local (a non-allocatable local of ! the same finalizable type; no ALLOCATE/DEALLOCATE) ! fortran-oop assignfinal/final-local (OpenMP 5.2, free-form Fortran): ! a local object of a finalizable type in a declare target subroutine is finalized on return (the ! final subroutine counts on the device) ! spec: Fortran 2018 7.5.6.3 (when finalization occurs); OpenMP 5.2 §1.2.6 p.19 (type-bound procedures ! in declare target); OpenMP 5.2 §7.8.1 p.205-207 (declare target, procedures) ! legality: defined ! expected (computed by compliance/oop_gen.py): r1= 64, r2= 4160 module oop_m implicit none integer, parameter :: n = 64 type ft integer :: v = 0 contains final :: ft_fin end type ft integer :: fin_count = 0 !$omp declare target to(fin_count) contains subroutine ft_fin(o) !$omp declare target type(ft), intent(inout) :: o !$omp atomic update fin_count = fin_count + 1 end subroutine ft_fin subroutine work(k, r) !$omp declare target integer, intent(in) :: k integer, intent(out) :: r type(ft) :: o o%v = k r = 2 * o%v end subroutine work end module oop_m program oop use omp_lib use oop_m implicit none integer :: host_flag logical :: ok integer :: r1, r2 integer :: res(n), i host_flag = 1 !$omp target map(from: host_flag) host_flag = merge(1, 0, omp_is_initial_device()) !$omp end target fin_count = 0 !$omp target update to(fin_count) !$omp target teams distribute parallel do map(tofrom: res) do i = 1, n call work(i, res(i)) end do !$omp target update from(fin_count) r1 = fin_count r2 = sum(res) ok = .true. ok = ok .and. (r1 == 64) ok = ok .and. (r2 == 4160) print '(a,i0)', 'r1= ', r1 print '(a,i0)', 'r2= ', r2 print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok) end program oop
Other compilers run it correctly
AFAR 24.3.0, GCC 16.2.0