Observed issues › oop/cce-select-type-guard-not-taken
SELECT TYPE in a device procedure takes the CLASS DEFAULT branch for mapped objects
Legality: independently confirmed. One independent reading was uncertain; 2 adjudicating readings that weighed both find the program legal and the result required: Both readings find the program legal. The only OpenMP polymorphism restrictions concern ALLOCATABLE polymorphic list items (map clause) or C++ types with mismatched static and dynamic types; none applies since e1, e2, b0 are non-polymorphic variables mapped tofrom. A declare target procedure with CLASS dummy and SELECT TYPE is plain Fortran, so the values are determined. How this is checked
A declare target subroutine with a CLASS(base_t) dummy argument and a SELECT TYPE construct, called in a target region with objects of two extended types, should run the matching TYPE IS branch. CCE 19, 20 and 21 run the CLASS DEFAULT branch for every object (the same with a CLASS(*) dummy). The same calls on the host take the right branches. AFAR runs the right branches.
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 | correct | correct | 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 | fails another way | fails another way | fails another way | fails another way | fails another way | fails another way | 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 | showr1= 0 r2= 0 r3= -1 RESULT ran_on_host=0 check=fail |
| fails another way | NVHPC 25.11, A100 separate NVHPC 25.11, A100 managed NVHPC 26.9, A100 separate NVHPC 26.9, A100 managed | showNVFORTRAN-S-1058-Call to Compiler runtime function not supported - pgf90_same_type_as_i8 (site-oop--cce-select-type-guard-not-taken.f90: 42) 0 inform, 0 warnings, 1 severes, 0 fatal for bump |
| fails another way | GCC 16.2.0, MI300A unified GCC 16.2.0, MI300A copy | showsite-oop--cce-select-type-guard-not-taken.f90:52:16: error: variable ‘__vtab_oop_m_Ext1’ has been referenced in offloaded code but hasn’t been marked to be included in the offloaded code
52 | end module oop_m
| ^
site-oop--cce-select-type-guard-not-taken.f90:52:16: error: variable ‘__vtab_oop_m_Ext2’ has been referenced in offloaded code but hasn’t been marked to be included in the offloaded code
lto1: fatal error: errors during merging of translation units
compilation terminated.
gcn mkoffload: fatal error: <home>/gcc-16.2/bin/x86_64-pc-linux-gnu-accel-amdgcn-amdhsa-gcc returned 1 exit status
compilation terminated. |
| fails another way | GCC 16.2.0, MI250X | showsite-oop--cce-select-type-guard-not-taken.f90:53:16: error: variable ‘__vtab_oop_m_Ext1’ has been referenced in offloaded code but hasn’t been marked to be included in the offloaded code
53 | end module oop_m
| ^
site-oop--cce-select-type-guard-not-taken.f90:53:16: error: variable ‘__vtab_oop_m_Ext2’ has been referenced in offloaded code but hasn’t been marked to be included in the offloaded code
lto1: fatal error: errors during merging of translation units
compilation terminated.
gcn mkoffload: fatal error: <home>/gcc-16.2/bin/x86_64-pc-linux-gnu-accel-amdgcn-amdhsa-gcc returned 1 exit status
compilation terminated. |
| fails another way | GCC 16.2.0, MI300X GCC 16.2.0, MI350X | showsite-oop--cce-select-type-guard-not-taken.f90:52:16: error: variable ‘__vtab_oop_m_Ext1’ has been referenced in offloaded code but hasn’t been marked to be included in the offloaded code
52 | end module oop_m
| ^
site-oop--cce-select-type-guard-not-taken.f90:52:16: error: variable ‘__vtab_oop_m_Ext2’ has been referenced in offloaded code but hasn’t been marked to be included in the offloaded code
lto1: fatal error: errors during merging of translation units
compilation terminated.
gcn mkoffload: fatal error: <home>/<user>/gcc-16.2/bin/x86_64-pc-linux-gnu-accel-amdgcn-amdhsa-gcc returned 1 exit status
compilation terminated. |
| fails another way | GCC 16.2.0, A100 separate | showsite-oop--cce-select-type-guard-not-taken.f90:51:16: error: variable ‘__vtab_oop_m_Ext1’ has been referenced in offloaded code but hasn’t been marked to be included in the offloaded code
51 | end module oop_m
| ^
site-oop--cce-select-type-guard-not-taken.f90:51:16: error: variable ‘__vtab_oop_m_Ext2’ has been referenced in offloaded code but hasn’t been marked to be included in the offloaded code
lto1: fatal error: errors during merging of translation units
compilation terminated.
nvptx mkoffload: fatal error: <home>/gcc-16.2/bin/x86_64-pc-linux-gnu-accel-nvptx-none-gcc returned 1 exit status
compilation terminated. |
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, MI300A unified (runs correctly)
$AFAR/bin/amdflang -fopenmp --offload-arch=gfx942 -O2 repro.f90 -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (84 lines)
! # Finding (fortran-oop): SELECT TYPE in a declare target procedure takes CLASS DEFAULT for mapped objects of extended types
!
! - 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: wrong_answer (check=fail); OMP_TARGET_OFFLOAD=mandatory
! - observed: `r1= 0 r2= 0 r3= -1`: the calls with an ext1 and an ext2 actual take the CLASS DEFAULT branch (oop-poly-select-type,
! every CCE release, both modes); a CLASS(*) dummy classifies every derived-type actual as CLASS DEFAULT (oop-unlimited-classify
! `r1= 0`, every CCE, both modes); with intrinsic and derived actuals of a CLASS(*) dummy CCE 19 misses only the derived-type
! actual (oop-unlimited-select-type `r1= 42 r2= 20 r3= 5`, expected r3= 7; CCE 20 and 21 correct). All three programs map
! non-polymorphic objects from the host and dispatch on them in the device procedure
! - expected: `r1= 10 r2= 100 r3= -1` (the TYPE IS (ext1) and TYPE IS (ext2) branches run for those actuals)
! - rule: Fortran 2018 11.1.11 (a TYPE IS guard is chosen when the dynamic type of the selector is that type); a CLASS dummy
! argument of a declare target procedure is not restricted by OpenMP (5.2 §1.2.6 p.19 l.1-3: the type-bound procedures accessed
! must be declare target; this program has none)
! - same-compiler control: the same three calls on the host (controls/host-select-type.f90 and
! controls/host-class-star-select-type.f90: correct on every CCE release in both modes, results/oop/probe/controls.jsonl)
! - other families: AFAR correct on all three programs; GCC 16.2 rejects them at compile time (a separate finding:
! gcc-vtab-not-marked-for-offload.f90)
! - gate and confirmer: 18 cells, 18 confirmed in the gate's four environments (a-d; results/oop/main/gate_reruns*.jsonl);
! confirmer (results/oop/main/confirm.jsonl): compiler_bug (R20-runtime-bug) 18
! - programs (3): oop-poly-select-type, oop-unlimited-classify, oop-unlimited-select-type (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 base_t
integer :: a = 0
end type base_t
type, extends(base_t) :: ext1
integer :: u = 0
end type ext1
type, extends(base_t) :: ext2
integer :: v = 0
end type ext2
contains
subroutine bump(s)
!$omp declare target
class(base_t), intent(inout) :: s
select type (s)
type is (ext1)
s%u = s%u + 10
type is (ext2)
s%v = s%v + 100
class default
s%a = -1
end select
end subroutine bump
end module oop_m
program oop
use omp_lib
use oop_m
implicit none
integer :: host_flag
logical :: ok
integer :: r1, r2, r3
type(ext1) :: e1
type(ext2) :: e2
type(base_t) :: b0
host_flag = 1
!$omp target map(from: host_flag)
host_flag = merge(1, 0, omp_is_initial_device())
!$omp end target
!$omp target map(tofrom: e1, e2, b0)
call bump(e1)
call bump(e2)
call bump(b0)
!$omp end target
r1 = e1%u
r2 = e2%v
r3 = b0%a
ok = .true.
ok = ok .and. (r1 == 10)
ok = ok .and. (r2 == 100)
ok = ok .and. (r3 == -1)
print '(a,i0)', 'r1= ', r1
print '(a,i0)', 'r2= ', r2
print '(a,i0)', 'r3= ', r3
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
Expected
r1= 10
Observed where it behaves incorrectly
r1= 0 r2= 0 r3= -1 RESULT ran_on_host=0 check=fail
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 l.1-3
Evidence
Same compiler, one change
- the same calls of the same procedure on the host: not run yet
Control program
! control for oop-poly-select-type: the same calls on the host (one change: no target construct) ! fortran-oop poly/select-type (OpenMP 5.2, free-form Fortran): ! a declare target subroutine with a CLASS(base_t) dummy and SELECT TYPE, called on the device ! with mapped non-polymorphic objects of three types ! spec: OpenMP 5.2 §1.2.6 p.19 l.1-3 (type-bound procedures accessed in a target region appear in a ! declare target directive); OpenMP 5.2 §7.8.1 p.205-207 (declare target, procedures); OpenMP 5.2 ! §5.3 p.107 l.17-19 (SELECT TYPE in OpenMP regions); Fortran 2018 11.1.11 (SELECT TYPE) ! legality: defined ! expected (computed by compliance/oop_gen.py): r1= 10, r2= 100, r3= -1 module oop_m implicit none integer, parameter :: n = 64 type base_t integer :: a = 0 end type base_t type, extends(base_t) :: ext1 integer :: u = 0 end type ext1 type, extends(base_t) :: ext2 integer :: v = 0 end type ext2 contains subroutine bump(s) !$omp declare target class(base_t), intent(inout) :: s select type (s) type is (ext1) s%u = s%u + 10 type is (ext2) s%v = s%v + 100 class default s%a = -1 end select end subroutine bump end module oop_m program oop use omp_lib use oop_m implicit none integer :: host_flag logical :: ok integer :: r1, r2, r3 type(ext1) :: e1 type(ext2) :: e2 type(base_t) :: b0 host_flag = 1 !$omp target map(from: host_flag) host_flag = merge(1, 0, omp_is_initial_device()) !$omp end target call bump(e1) call bump(e2) call bump(b0) r1 = e1%u r2 = e2%v r3 = b0%a ok = .true. ok = ok .and. (r1 == 10) ok = ok .and. (r2 == 100) ok = ok .and. (r3 == -1) print '(a,i0)', 'r1= ', r1 print '(a,i0)', 'r2= ', r2 print '(a,i0)', 'r3= ', r3 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