OffTarget

Observed issues › catalog/cce-c-dist-schedule-chunk

Appears to behave incorrectlyWrong answer · C · OpenMP · Open

craycc: dist_schedule(static, 4) on target teams distribute parallel for puts every iteration on team 0

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

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.0correctcorrectcorrectcorrectcorrectn/an/a
CCE 19.0.0behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
CCE 20.0.2behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
CCE 21.0.3behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
CCE 21.0.4behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
NVHPC 25.11n/an/an/an/an/afails another wayfails another way
NVHPC 26.9n/an/an/an/an/afails another wayfails another way
GCC 16.2.0correctcorrectcorrectcorrectcorrectcorrectn/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 incorrectlyCCE 19.0.0, MI300A unified
CCE 19.0.0, MI300A copy
CCE 19.0.0, MI250X
CCE 20.0.2, MI300A unified
CCE 20.0.2, MI300A copy
CCE 20.0.2, MI250X
CCE 21.0.3, MI300A unified
CCE 21.0.3, MI300A copy
CCE 21.0.3, MI250X
CCE 21.0.4, MI300A unified
CCE 21.0.4, MI300A copy
CCE 21.0.4, MI250X
show
RESULT ran_on_host=0 check=fail
fails another wayNVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
NVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
Compilation terminated.
cleaning up after signal(15)...

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
craycc -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx942 -fopenmp-version=52 -O2 repro.c -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
craycc -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx942 -fopenmp-version=52 -O2 repro.c -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
craycc -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx942 -fopenmp-version=52 -O2 repro.c -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
craycc -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx942 -fopenmp-version=52 -O2 repro.c -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro

AFAR 24.3.0, MI300A unified (runs correctly)

$AFAR/bin/amdclang -fopenmp --offload-arch=gfx942 -fopenmp-version=52 -fopenmp-version=52 -O2 repro.c -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (75 lines)
// # Draft finding: omp52-c-clause-dist_schedule-chunk_size on cce19
//
// - compiler: cce19
// - toolchain: cce19; arch: gfx942; machine: tuolumne; memory mode: unified; opt: -O2
// - program: catalog omp52-c-clause-dist_schedule-chunk_size (c, version 52, sha256 47094ef1ef5dfbfa)
// - expected: check=pass (trusted; derivation + model)
// - actual: wrong_answer check=fail (check_fail: ran_on_host=0 check=fail)
// - verdict: compiler_bug by rule R20-runtime-bug: a legal program fails at run time, deterministically, against an expected value from two or more independent sources with an executed witness, and another toolchain, mode, arch or the elision gives the expected value
// - reason: expected trusted check=pass (derivation + model): derivation + model agree; witnesses: afar/gfx942/unified, cce19/gfx942/unified (port:omp52-clause-dist_schedule-chunk_size), cce20/gfx942/unified (port:omp52-clause-dist_schedule-chunk_size), cce21/gfx942/unified (port:omp52-clause-dist_schedule-chunk_size)
// - citations: RUL-DERIVED-NEEDS-EXECUTION (rulings.md); RUL-WITNESS-PER-MODE (rulings.md); RUL-SAME-COMPILER-RUNS (rulings.md)
// - legality: legal (legal by construction: offload.engine.gen / c_gen / acc_gen check every program against the catalog rules and the offload scope as it is built (no compiler))
// - witnesses: afar/gfx942/unified, cce19/gfx942/unified (port:omp52-clause-dist_schedule-chunk_size), cce20/gfx942/unified (port:omp52-clause-dist_schedule-chunk_size), cce21/gfx942/unified (port:omp52-clause-dist_schedule-chunk_size)
// - withdrawn: none
//
// Generated by compliance.c_gen (OpenMP 5.2, C11): the C port (offload.engine.f2c) of omp52-clause-dist_schedule-chunk_size. Do not edit.
// id: omp52-c-clause-dist_schedule-chunk_size
// primary atom: omp.clause.dist_schedule.chunk_size
// legal: yes
// observable: yes
// ran_on_host: inside the target region of interest
// evidence: construct
// needs: none
// std: c11
#include <stdio.h>
#include <stdbool.h>
#include <omp.h>

enum { n = 64 };

int main(void) {
  int a[n];
  int b[n];
  int ref[n];
  int host_flag;
  bool ok;
  int team[n];
  int nt;
  bool dok;
  for (int i = 1; i <= n; i++) {
    a[i - 1] = i;
    b[i - 1] = 0;
    ref[i - 1] = 2 * i + 1;
  }
  host_flag = 1;
  for (int k1_ = 0; k1_ < n; k1_++)
    team[k1_] = -1;
  nt = -1;
  #pragma omp target teams distribute parallel for map(to: a) map(from: b) map(from: team, nt) \
      map(tofrom: host_flag) default(none) shared(a, b, team, nt, host_flag) num_teams(4) \
      dist_schedule(static, 4)
  for (int i = 1; i <= n; i++) {
    b[i - 1] = 2 * a[i - 1] + 1;
    team[i - 1] = omp_get_team_num();
    if (i == 1) nt = omp_get_num_teams();
    if (i == 1) host_flag = (omp_is_initial_device() ? 1 : 0);
  }
  dok = true;
  for (int i = 1; i <= n; i++) {
    dok = dok && (team[i - 1] == ((i - 1) / 4 % nt));
  }
  bool t2_ = true;
  for (int k3_ = 0; k3_ < n; k3_++)
    t2_ = t2_ && (b[k3_] == ref[k3_]);
  ok = t2_ && (nt >= 1) && dok;
  printf("RESULT ran_on_host=%d check=%s\n", host_flag, ok ? "pass" : "fail");
  return 0;
}
// spec (requirement): With a chunk_size, dist_schedule divides the iterations into chunks of that size.
// "If the chunk_size argument is specified, iterations are divided into chunks of size chunk_size." (5.2 §11.6.1
//   p.256 l.18-19)
// spec (requirement): The chunks are assigned to the initial teams of the league round-robin in team-number order.
// "These chunks are assigned to the initial teams of the league in a round-robin fashion in the order of the initial
//   team number." (5.2 §11.6.1 p.256 l.23-24)
// spec (this program): dist_schedule(static, 4) with num_teams(4) puts iterations 1-4 on team 0, 5-8 on team 1, and
//   so on, round robin; craycc places every iteration on team 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

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 §11.6.1 p.256 l.18-19

If the chunk_size argument is specified, iterations are divided into chunks of size chunk_size.

OpenMP 5.2 §11.6.1 p.256 l.23-24

These chunks are assigned to the initial teams of the league in a round-robin fashion in the order of the initial team number.

Evidence

Same compiler, one change

  • num_teams(1) instead of num_teams(4) (every chunk on team 0): AFAR 24.3.0: correct; CCE 19.0.0: correct; CCE 20.0.2: correct; CCE 21.0.3: correct; CCE 21.0.4: correct
    Control program
    #include <stdio.h>
    #include <stdbool.h>
    #include <omp.h>
    
    enum { n = 64 };
    
    int main(void) {
      int a[n];
      int b[n];
      int ref[n];
      int host_flag;
      bool ok;
      int team[n];
      int nt;
      bool dok;
      for (int i = 1; i <= n; i++) {
        a[i - 1] = i;
        b[i - 1] = 0;
        ref[i - 1] = 2 * i + 1;
      }
      host_flag = 1;
      for (int k1_ = 0; k1_ < n; k1_++)
        team[k1_] = -1;
      nt = -1;
      #pragma omp target teams distribute parallel for map(to: a) map(from: b) map(from: team, nt) \
          map(tofrom: host_flag) default(none) shared(a, b, team, nt, host_flag) num_teams(1) \
          dist_schedule(static, 4)
      for (int i = 1; i <= n; i++) {
        b[i - 1] = 2 * a[i - 1] + 1;
        team[i - 1] = omp_get_team_num();
        if (i == 1) nt = omp_get_num_teams();
        if (i == 1) host_flag = (omp_is_initial_device() ? 1 : 0);
      }
      dok = true;
      for (int i = 1; i <= n; i++) {
        dok = dok && (team[i - 1] == ((i - 1) / 4 % nt));
      }
      bool t2_ = true;
      for (int k3_ = 0; k3_ < n; k3_++)
        t2_ = t2_ && (b[k3_] == ref[k3_]);
      ok = t2_ && (nt >= 1) && dok;
      printf("RESULT ran_on_host=%d check=%s\n", host_flag, ok ? "pass" : "fail");
      return 0;
    }
    

Other compilers run it correctly

AFAR 24.3.0, GCC 16.2.0