Observed issues › oop/afar-final-dealloc-device-link
deallocating a finalizable object in device code fails at the link
Legality: independently confirmed. 2 independent readings find the program legal and the result required. How this is checked
A declare target subroutine allocates and deallocates a local allocatable object of a type with a final subroutine. AMD's flang fails at the device link: flang_rt_verbose_abort is undefined. The same type as a non-allocatable local is finalized correctly on the device.
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 | not supported | not supported | unknown not run | correct | correct | n/a | n/a |
| CCE 19.0.0 | fails another way | fails another way | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 20.0.2 | fails another way | fails another way | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.3 | fails another way | fails another way | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.4 | fails another way | fails another way | 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 |
|---|---|---|
| not supported | AFAR 24.3.0, MI300A unified AFAR 24.3.0, MI300A copy | showsite-oop--afar-final-dealloc-device-link.f90:30: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--afar-final-dealloc-device-link.f90:30: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 | 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--afar-final-dealloc-device-link.f90 LINE 43 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--afar-final-dealloc-device-link.f90 LINE 43 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--afar-final-dealloc-device-link.f90 LINE 43 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--afar-final-dealloc-device-link.f90 LINE 43 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--afar-final-dealloc-device-link.f90 LINE 43 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--afar-final-dealloc-device-link.f90 LINE 43 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--afar-final-dealloc-device-link.f90 LINE 43 due to a Fortran allocate/deallocate statement. Thread execution stopped at FILE site-oop--afar-final-dealloc-device-link.f90 LINE 43 due to a Fortran allocate/deallocate statement. |
| 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--afar-final-dealloc-device-link.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--afar-final-dealloc-device-link.f90: 43) 0 inform, 0 warnings, 1 severes, 0 fatal for alloc_work |
Reproduce
AFAR 24.3.0, MI300A unified
$AFAR/bin/amdflang -fopenmp --offload-arch=gfx942 -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
GCC 16.2.0, MI300A unified (runs correctly)
export LD_LIBRARY_PATH=$GCC_16_2/lib64:/opt/rocm-7.2.1/lib $GCC_16_2/bin/gfortran -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx942 -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (78 lines)
! # Finding (fortran-oop): amdflang: DEALLOCATE of an allocatable finalizable object in device code fails at the device link
!
! - toolchains and modes that fail: afar (AFAR: copy, unified); -O2
! - build: amdflang -fopenmp --offload-arch=gfx942 -fopenmp-version=52 -O2
! - failure: rejected (link_undefined_symbol, the program's own object); OMP_TARGET_OFFLOAD=mandatory
! - observed: `ld.lld: error: undefined symbol: flang_rt_verbose_abort(char const*, ...)` at the device link, both modes: the
! device code of the DEALLOCATE (with its finalization) calls a flang runtime routine that has no device version
! - expected: compiles; `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 in both modes (results/oop/main/rows.part*.jsonl,
! results/oop/probe/ctl2.*.final-local.*.jsonl)
! - other families: CCE 19/20 stop the device thread at the DEALLOCATE and CCE 21 aborts (cce-final-dealloc-device-abort.f90); GCC
! 16.2 correct. The confirmer's signature also matches afar-udr-derived-type-link.f90 (the same undefined symbol, from a declare
! reduction with a structure-constructor combiner); the triggers differ, so this is a finding of its own
! - gate and confirmer: 2 cells, 2 confirmed in the gate's four environments (a-d; results/oop/main/gate_reruns*.jsonl); confirmer
! (results/oop/main/confirm.jsonl): compiler_bug (R10b-own-link-or-hang) 2
! - programs (1): oop-assignfinal-final-dealloc (offload/engine/oop_gen.py; this file is the first one)
! - legality: the rules and the front ends of the other families (AFAR's own front end is not its witness): CCE compiles it (its
! failure is at run time) and NVHPC's verdict is no verdict (an unsupported runtime routine, results/oop/main/witness.jsonl);
! tools/campaigns/oop.py legality: legal for AFAR
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
site-oop--afar-final-dealloc-device-link.f90:30: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--afar-final-dealloc-device-link.f90:30: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*))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
GCC 16.2.0