- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am experimenting with different OpenMP offloading snippets and stumbled upon the following issue. When using !$declare target on a buffer stored in a module and entering data with explicit memory management constructs, the buffer is then suddenly indexed from 0 instead of 1 when accessed in a target region. See the following reproducer down below. I compile this with IFX 2025.3.0 using:
ifx -O2 -fiopenmp -fopenmp-targets=spir64 main.F90
and run with:
OMP_TARGET_OFFLOAD=mandatory ./a.out
MODULE some_mod
IMPLICIT NONE
REAL, ALLOCATABLE, DIMENSION(:) :: buffer
!$omp declare target(buffer)
CONTAINS
SUBROUTINE init_data()
INTEGER :: i
ALLOCATE(buffer(3))
DO i = 1, SIZE(buffer)
buffer(i) = i
END DO
!$omp target enter data map(to: buffer)
END SUBROUTINE init_data
SUBROUTINE get_value(val, index)
!$omp declare target
REAL, INTENT(OUT) :: val
INTEGER, INTENT(IN) :: index
val = buffer(index)
END SUBROUTINE get_value
SUBROUTINE finalize()
!$omp target exit data map(release: buffer)
DEALLOCATE(buffer)
END SUBROUTINE finalize
END MODULE some_mod
PROGRAM main
USE some_mod
IMPLICIT NONE
INTEGER :: i
REAL :: val
REAL :: values(3)
CALL init_data()
PRINT *, "Buffer host:"
!PRINT*, "i = 1:", buffer(0) This should never be used here
PRINT*, "i = 1:", buffer(1)
PRINT*, "i = 2:", buffer(2)
PRINT*, "i = 3:", buffer(3)
PRINT *, "Buffer device:"
!$omp target map(from: values)
DO i = 1, 3
CALL get_value(val, i)
values(i) = val
PRINT*, "i=",i,":",val
END DO
!$omp end target
! This will show: 2.000000 3.000000 0.0000000E+00
! Which is weird since the indices do not match after the target region
PRINT *, "Values back on host:"
PRINT *, values
CALL finalize()
END PROGRAM main
Gives the output:
Buffer host:
i = 1: 1.000000
i = 2: 2.000000
i = 3: 3.000000
Buffer device:
i= 1 : 2.000000
i= 2 : 3.000000
i= 3 : 0.000000
Values back on host:
2.000000 3.000000 0.0000000E+00
One can also check that only in the target region PRINT*, buffer(0) gives 1.000000 which should be accessible with buffer(1)
I could not reproduce this behavior on other compilers (gfortran 13.3.0, nvfortran 25.9-0 or latest LLVM built from source).
Am I doing something unintended or unsupported for IFX or could this be a bug?
Link Copied
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page