OffTarget

Observed issues › apps/gcc-acc-c-tile-partial-tiles-wrong

Appears to behave incorrectlyWrong answer · C · OpenACC · Open

OpenACC tile(32, 32) over loops whose trip counts are not multiples of the tile size computes wrong elements

Legality: independently confirmed. 2 independent readings find the program legal and the result required. How this is checked

A parallel loop tile(32, 32) over a 98 x 98 (or 100 x 100) nest should run every iteration once. GCC 16.2 leaves 4342 of the 10000 elements it checks wrong (C and Fortran), on the MI250X and the A100. The same nest with collapse(2), or with trip counts that are multiples of 32, is correct. Found through the Parallel Research Kernels' OpenACC stencil.

Affected variants

CompilerMI300A 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.0n/an/an/an/an/an/an/a
CCE 19.0.0n/an/aunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 20.0.2n/an/aunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.3n/an/aunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.4n/an/aunknown
not run
unknown
not run
unknown
not run
n/an/a
NVHPC 25.11n/an/an/an/an/acorrectcorrect
NVHPC 26.9n/an/an/an/an/acorrectcorrect
GCC 16.2.0behaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlyn/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

ResultCompiler and GPUMessage
behaves incorrectlyGCC 16.2.0, MI300A unified
GCC 16.2.0, MI300A copy
GCC 16.2.0, MI250X
GCC 16.2.0, MI300X
GCC 16.2.0, MI350X
GCC 16.2.0, A100 separate
show
bad= 4342
RESULT ran_on_host=0 check=fail

Reproduce

GCC 16.2.0, MI300A unified

export LD_LIBRARY_PATH=$GCC_16_2/lib64:/opt/rocm-7.2.1/lib
$GCC_16_2/bin/gcc -fopenacc -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx942 -O2 repro.c -o repro
HSA_XNACK=1 ./repro

GCC 16.2.0, A100 separate

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=$GCC_16_2/lib64
$GCC_16_2/bin/gcc -fopenacc -foffload=nvptx-none -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 repro.c -o repro
./repro

NVHPC 25.11, A100 separate (runs correctly)

export LD_LIBRARY_PATH=$NVHPC_25_11/compilers/lib
nvc -acc=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.c -o repro
./repro
Program (53 lines)
// # Finding (GCC 16.2, application corpus): OpenACC tile(32, 32) over loops whose trip counts are not multiples of 32 computes
//   wrong elements
//
// - toolchains: gcc_g90 (GCC 16.2.0, AMD Instinct MI250X gfx90a, Tioga) and gcc_sm80 (GCC 16.2.0, NVIDIA A100 sm_80, wingtip);
//   separate memory only; -O2
// - build: gcc -fopenacc -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx90a -O2 (gcc_g90); -foffload=nvptx-none
//   -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 (gcc_sm80)
// - failure: wrong_answer
// - observed: `bad= 4342` (of the 10000 elements checked) and check=fail in every run (gcc_sm80: mandatory wrong 5 of 5; unset
//   wrong 5 of 5; gcc_g90: mandatory wrong 5 of 5; unset wrong 5 of 5 (results/parity/<machine>/<tc>/probes.jsonl))
// - expected: `bad= 0`, then `RESULT ran_on_host=0 check=pass`
// - rule: "Each loop in the nest will be split, or strip-mined, into two loops, an outer tile loop and an inner element loop. The
//   trip count of the element loop will be limited to the corresponding tile size from the size-expr-list" (OpenACC 3.4 §2.9.8
//   l.2486-2489): tiling reorders the iterations of the nest, each still runs once. The tile clause is OpenACC 2.0's; GCC documents
//   OpenACC 2.6.
// - same-compiler control (correct, gcc_sm80: mandatory pass 5 of 5; unset pass 5 of 5; gcc_g90: mandatory pass 5 of 5; unset pass
//   5 of 5 (results/parity/<machine>/<tc>/probes.jsonl)): collapse(2) in place of tile(32, 32) (controls/gcc-acc-c-tile-control.c).
//   With trip counts of 64 (multiples of the tile size) the tiled form is correct too, and so is a one-loop tile(32) (C and
//   Fortran, both GPUs, mandatory pass 5 of 5, unset pass 5 of 5; results/parity/probes-r2/tile_mult32.*, tile_one_loop.*).
// - application: prk-c-stencil-acc (C1z/stencil-openacc.c, stencil_openacc.h) of the Parallel Research Kernels
//   (data/bench/apps/manifest.yaml): its stencil kernels are `acc parallel loop tile(32,32)` over the interior of a 1000 x
//   1000 grid;
//   GCC's run prints `ERROR: L1 norm = 21.912356 Reference L1 norm = 22.000000`, exit 1 on both GPUs
//   (results/parity/<machine>/results/apps/runs). NVHPC 25.11 and 26.9 validate it (results/apps/wingtip/runs).
// - other families: NVHPC 25.11 and 26.9 run this file correctly in both memory modes (C OpenACC: no AFAR or CCE support) (site
//   matrix). The site's finding matrix runs this file on every compiler.
// - legality: OpenACC 3.4 §2.9.8; the nest is tightly nested and every iteration writes its own element (no race). GCC is a
//   compiler under test only and never a legality witness.
#include <stdio.h>
#include <stdlib.h>
#include <openacc.h>

int main(void) {
  const int n = 100;
  int *a = malloc(n * n * sizeof(int));
  int bad = 0, host_flag = 1;
  for (int k = 0; k < n * n; k++) a[k] = 0;
#pragma acc parallel loop tile(32, 32) copy(a[0:n*n])
  for (int i = 1; i < n - 1; i++)
    for (int j = 1; j < n - 1; j++)
      a[i * n + j] += i + j;
#pragma acc parallel num_gangs(1) copy(host_flag)
  host_flag = acc_on_device(acc_device_host);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      int want = (i > 0 && i < n - 1 && j > 0 && j < n - 1) ? i + j : 0;
      bad += a[i * n + j] != want;
    }
  printf("bad= %d\n", bad);
  printf("RESULT ran_on_host=%d check=%s\n", host_flag, bad ? "fail" : "pass");
  free(a);
  return 0;
}

Source in the repository

Something to add? Dispute its legality · Report it fixed in a newer release · Report a mistake on this page

Expected and observed

Expected

check=pass

Observed where it behaves incorrectly

bad= 4342
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.

OpenACC 3.4 §2.9.8

Each loop in the nest will be split, or strip-mined, into two loops, an outer tile loop and an inner element loop. The trip count of the element loop will be limited to the corresponding tile size from the size-expr-list

OpenACC 3.4 §2.9.8

Evidence

Same compiler, one change

  • collapse(2) in place of tile(32, 32): not run yet
    Control program
    // Control of apps/gcc-acc-c-tile-partial-tiles-wrong.c: collapse(2) in place of tile(32, 32) (correct on gcc_g90 and gcc_sm80).
    #include <stdio.h>
    #include <stdlib.h>
    #include <openacc.h>
    
    int main(void) {
      const int n = 100;
      int *a = malloc(n * n * sizeof(int));
      int bad = 0, host_flag = 1;
      for (int k = 0; k < n * n; k++) a[k] = 0;
    #pragma acc parallel loop collapse(2) copy(a[0:n*n])
      for (int i = 1; i < n - 1; i++)
        for (int j = 1; j < n - 1; j++)
          a[i * n + j] += i + j;
    #pragma acc parallel num_gangs(1) copy(host_flag)
      host_flag = acc_on_device(acc_device_host);
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
          int want = (i > 0 && i < n - 1 && j > 0 && j < n - 1) ? i + j : 0;
          bad += a[i * n + j] != want;
        }
      printf("bad= %d\n", bad);
      printf("RESULT ran_on_host=%d check=%s\n", host_flag, bad ? "fail" : "pass");
      free(a);
      return 0;
    }
    

Other compilers run it correctly

NVHPC 25.11, NVHPC 26.9

Reproducers of this issue