Skip to content

Pragma_Examples: fix Fortran min/max/sum array reduction test discarding its device result - #191

Open
dannybaths wants to merge 1 commit into
amd:mainfrom
dannybaths:fortran-reduction-array-combined-construct
Open

Pragma_Examples: fix Fortran min/max/sum array reduction test discarding its device result#191
dannybaths wants to merge 1 commit into
amd:mainfrom
dannybaths:fortran-reduction-array-combined-construct

Conversation

@dannybaths

@dannybaths dannybaths commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

What

Pragma_Examples/OpenMP/Fortran/5_reduction_array/2_reduction_array_min_max_sum/reduction.f90
reports the wrong answer for all eight of its sub-tests. Each one reports the
initialiser of its result variable rather than the reduction: Test 1 int MAX
prints the value of -huge(imax_result), Test 4 int SUM prints 0, and so on.

All eight sub-tests use a bare !$omp target with the reduction on an inner
!$omp teams loop:

!$omp target
!$omp teams loop collapse(1) default(shared) private(i) reduction(MAX: imax_result)
...
!$omp end teams loop
!$omp end target

A scalar referenced in a target region with no map or defaultmap clause is
firstprivate, so the value is copied in and never copied back. The device
performs the reduction correctly and the host then discards the result.

This change uses the combined construct instead, which is what the passing
sibling test OpenMP_Language_Constructs_Fortran_Reduction_Array already does:

!$omp target teams loop collapse(1) default(shared) private(i) reduction(MAX: imax_result)
...
!$omp end target teams loop

The change also removes this annotation above the test in tests/CMakeLists.txt:

# Expected failure -- not implemented in amdflang-new yet

That comment is a mis-diagnosis. The construct is implemented and the reduction is
computed correctly; only the data mapping was wrong.

Why

The test currently fails for a reason that has nothing to do with compiler
support, while an annotation in the test list attributes the failure to a missing
compiler feature. Anyone reading it learns the wrong lesson twice: that this
reduction form is unsupported, and that the code as written is correct.

Validation

MI300A / gfx942, HSA_XNACK=1, amdflang from $ROCM_PATH/bin. Focused run on
upstream main (20e93223):

git clone https://github.com/amd/HPCTrainingExamples.git
cd HPCTrainingExamples/tests
export HSA_XNACK=1
export ROCM_GPU=gfx942
export FC="${ROCM_PATH}/bin/amdflang"
rm -rf build && cmake . -B build
ctest -V -R '^OpenMP_Language_Constructs_Fortran_Reduction_Array_Min_Max_Sum$' --test-dir build

On many raw clones the CTest driver does not pick up amdflang unless FC is set
explicitly as above.

Unpatched upstream: 1/1 FAIL. All eight sub-tests report wrong answers
(initialiser values); CTest misses the ALL TESTS PASSED regex.

With this change: 1/1 PASS. Example lines:

Test 1  int MAX (n=4):       result=320  expected=320
Test 4  int SUM (n=100):     result=5050  expected=5050
Test 7  dp  SUM (n=1000):    result=     1000.00  expected=     1000.00
Test 8  int MAX cond (n=4):  result=320  expected=320
ALL TESTS PASSED

AAC7 proof: current-main CTest on ROCm 10.0.0 — unpatched FAIL, patched PASS.

AAC6 no-regression: MI300A, Lmod rocm/7.14.0, Slurm job 19739 on
ppac-pl1-s24-16 — 1/1 PASS, ALL TESTS PASSED, with
FC=$ROCM_PATH/bin/amdflang.

…ts device result

Signed-off-by: Daniele Bagni <30289343+dannybaths@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant