[Openmp-commits] [openmp] [OpenMP] Forward the GNU taskloop strict modifier (PR #237556)
via Openmp-commits
openmp-commits at lists.llvm.org
Sat Oct 31 05:35:50 PDT 2026
https://github.com/SmaCow666 created https://github.com/llvm/llvm-project/pull/237556
The GNU taskloop bridge drops `GOMP_TASK_FLAG_STRICT` (bit 14) and calls
`__kmpc_taskloop`, whose modifier is always zero. A GCC-compiled
`taskloop grainsize(strict: 10)` with 53 iterations therefore produces
11/11/11/10/10 instead of the required 10/10/10/10/10/3 partition.
Extract bit 14 and forward it through the existing `__kmpc_taskloop_5` entry
point. The template covers both `GOMP_taskloop` and `GOMP_taskloop_ull`;
callers without the strict bit still pass a zero modifier.
Add a GNU ABI regression that compiles with the usual libomp test compiler.
It does not require the compiler to accept strict syntax or emit the GNU ABI.
The 480-case matrix checks exact iteration coverage and task partitioning for
both signed and high unsigned coordinates, strict/non-strict grainsize,
num_tasks, small/exact/partial chunks, if(0)/if(1), and one/two threads.
Increasing coordinates isolate flag forwarding from the separate runtime
chunk-bound issue affecting descending and signed-coordinate loops. The two
fixes have also been tested together.
Validation against main `7a59bfc6e7ad44858258af2f0d716a56a6cf102f`:
- Complete independent x86-64 Release and assertions-enabled Debug runtimes;
GCC 11 and Clang 21 callers. The baseline fails 40 of 480 cases; the fixed
runtime passes all cases, including non-strict and num_tasks controls.
- The new regression fails on the baseline and passes on Release and Debug
through the current upstream lit configuration.
- Six unchanged neighboring taskloop/taskgroup tests pass with this fix, the
separate bounds fix, and their combination.
- Complete RV64GC/LP64D build; the new ABI regression fails on the baseline
and passes on the candidate under QEMU. Real GCC 12.4 source-level strict
signed/unsigned callers and a non-strict control also pass against the
candidate. Earlier RV64 baseline validation reproduces the 53/10 mismatch.
Clang strict code generation (#117196) and MLIR clause representation (#128477)
do not forward this GNU ABI flag. The open OMPT codeptr PR #234180 touches the
same bridge but addresses callback return addresses; its reviewed diff retains
the modifier-less call. These are distinct fixes, although rebasing may be
needed if that PR lands first.
The full upstream test suite was not run. This is a portable GNU ABI correctness
fix; the QEMU results support functionality and carry no performance claim.
>From 9d879901ea4dbec03c028c15ee1bd89528e9dcbe Mon Sep 17 00:00:00 2001
From: XuhuiNiu <uiniu666 at gamil.com>
Date: Sat, 31 Oct 2026 20:32:11 +0800
Subject: [PATCH] [OpenMP] Forward the GNU taskloop strict modifier
Read GOMP_TASK_FLAG_STRICT (bit 14) in the shared GNU taskloop bridge and
pass it through __kmpc_taskloop_5. The modifier-less entry silently
rebalances strict grainsize partitions.
Add GNU ABI regression coverage for signed/unsigned entry points,
strict and non-strict grainsize, num_tasks and serial/deferred tasks.
---
openmp/runtime/src/kmp_gsupport.cpp | 7 +-
.../test/tasking/gomp_taskloop_strict.c | 113 ++++++++++++++++++
2 files changed, 117 insertions(+), 3 deletions(-)
create mode 100644 openmp/runtime/test/tasking/gomp_taskloop_strict.c
diff --git a/openmp/runtime/src/kmp_gsupport.cpp b/openmp/runtime/src/kmp_gsupport.cpp
index be95e0f3de6e2b..2dc5adde11add8 100644
--- a/openmp/runtime/src/kmp_gsupport.cpp
+++ b/openmp/runtime/src/kmp_gsupport.cpp
@@ -1778,6 +1778,7 @@ void __GOMP_taskloop(void (*func)(void *), void *data,
int nogroup = gomp_flags & (1u << 11);
int up = gomp_flags & (1u << 8);
int reductions = gomp_flags & (1u << 12);
+ int strict = !!(gomp_flags & (1u << 14));
p_task_dup_t task_dup = NULL;
kmp_tasking_flags_t *input_flags = (kmp_tasking_flags_t *)&flags;
#ifdef KMP_DEBUG
@@ -1865,9 +1866,9 @@ void __GOMP_taskloop(void (*func)(void *), void *data,
KMP_EXPAND_NAME(KMP_API_NAME_GOMP_TASKGROUP_REDUCTION_REGISTER)(d);
}
}
- __kmpc_taskloop(&loc, gtid, task, if_val, (kmp_uint64 *)&(loop_bounds[0]),
- (kmp_uint64 *)&(loop_bounds[1]), (kmp_int64)step, 1, sched,
- (kmp_uint64)num_tasks, (void *)task_dup);
+ __kmpc_taskloop_5(&loc, gtid, task, if_val, (kmp_uint64 *)&(loop_bounds[0]),
+ (kmp_uint64 *)&(loop_bounds[1]), (kmp_int64)step, 1, sched,
+ (kmp_uint64)num_tasks, strict, (void *)task_dup);
if (!nogroup) {
#if OMPT_SUPPORT && OMPT_OPTIONAL
OMPT_STORE_RETURN_ADDRESS(gtid);
diff --git a/openmp/runtime/test/tasking/gomp_taskloop_strict.c b/openmp/runtime/test/tasking/gomp_taskloop_strict.c
new file mode 100644
index 00000000000000..c0e3a9bd281265
--- /dev/null
+++ b/openmp/runtime/test/tasking/gomp_taskloop_strict.c
@@ -0,0 +1,113 @@
+// RUN: %libomp-compile-and-run
+// REQUIRES: linux
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Call the GNU ABI directly so this runtime test does not depend on the
+// compiler accepting the OpenMP strict modifier or choosing the GNU ABI.
+#include <omp.h>
+#include <stdint.h>
+#include <stdio.h>
+
+enum { Capacity = 64 };
+struct context {
+ uint64_t start;
+ int n, tasks, bad, seen[Capacity], sizes[Capacity];
+};
+struct signed_data { long lb, ub; struct context *c; };
+struct unsigned_data { unsigned long long lb, ub; struct context *c; };
+extern void GOMP_taskloop(void (*)(void *), void *, void (*)(void *, void *),
+ long, long, unsigned, unsigned long, int, long, long, long);
+extern void GOMP_taskloop_ull(void (*)(void *), void *, void (*)(void *, void *),
+ long, long, unsigned, unsigned long, int,
+ unsigned long long, unsigned long long,
+ unsigned long long);
+
+static void record(struct context *c, uint64_t lb, uint64_t ub) {
+ uint64_t first = lb - c->start, size = ub - lb;
+ int id = __atomic_fetch_add(&c->tasks, 1, __ATOMIC_RELAXED);
+ if (id >= Capacity || first >= (uint64_t)c->n ||
+ size == 0 || size > (uint64_t)c->n - first) {
+ __atomic_fetch_add(&c->bad, 1, __ATOMIC_RELAXED);
+ return;
+ }
+ c->sizes[id] = (int)size;
+ for (uint64_t i = first; i < first + size; ++i)
+ __atomic_fetch_add(&c->seen[i], 1, __ATOMIC_RELAXED);
+}
+
+static void signed_entry(void *p) {
+ struct signed_data *d = p;
+ record(d->c, d->lb, d->ub);
+}
+static void unsigned_entry(void *p) {
+ struct unsigned_data *d = p;
+ record(d->c, d->lb, d->ub);
+}
+
+static int run(int is_unsigned, int n, int grain, int sched, int strict,
+ int if_val, int threads) {
+ struct context c = {.start = is_unsigned ? (UINT64_C(1) << 63) + 17 : 7, .n = n};
+ unsigned flags = (1u << 8) | (if_val ? 1u << 10 : 0) |
+ (sched == 1 ? 1u << 9 : 0) | (strict ? 1u << 14 : 0);
+ #pragma omp parallel num_threads(threads) shared(c)
+ {
+ #pragma omp single
+ {
+ if (is_unsigned) {
+ struct unsigned_data d = {0, 0, &c};
+ GOMP_taskloop_ull(unsigned_entry, &d, NULL, sizeof(d),
+ _Alignof(struct unsigned_data), flags, grain, 0,
+ c.start, c.start + n, 1);
+ } else {
+ struct signed_data d = {0, 0, &c};
+ GOMP_taskloop(signed_entry, &d, NULL, sizeof(d),
+ _Alignof(struct signed_data), flags, grain, 0,
+ (long)c.start, (long)c.start + n, 1);
+ }
+ }
+ }
+ int bad = c.bad;
+ for (int i = 0; i < n; ++i)
+ bad |= c.seen[i] != 1;
+ int tasks = sched == 2 ? (grain < n ? grain : n) :
+ strict ? (n + grain - 1) / grain : (n < grain ? 1 : n / grain);
+ bad |= c.tasks != tasks;
+ int tail_count = 0;
+ for (int i = 0; i < c.tasks && i < Capacity; ++i) {
+ if (sched == 1 && strict) {
+ int tail = n % grain ? n % grain : grain;
+ bad |= c.sizes[i] != grain && c.sizes[i] != tail;
+ tail_count += c.sizes[i] != grain;
+ } else {
+ int small = n / tasks;
+ bad |= c.sizes[i] != small && c.sizes[i] != small + 1;
+ }
+ }
+ if (sched == 1 && strict)
+ bad |= tail_count != (n % grain != 0);
+ if (bad)
+ printf("GNU strict failure: ull=%d n=%d grain=%d sched=%d strict=%d if=%d "
+ "threads=%d tasks=%d/%d\n", is_unsigned, n, grain, sched, strict,
+ if_val, threads, c.tasks, tasks);
+ return !!bad;
+}
+
+int main(void) {
+ const int counts[] = {1, 10, 11, 53, 60};
+ const int grains[] = {3, 10, 64};
+ int errors = 0, cases = 0;
+ omp_set_dynamic(0);
+ for (int threads = 1; threads <= 2; ++threads)
+ for (int if_val = 0; if_val <= 1; ++if_val)
+ for (int ull = 0; ull <= 1; ++ull)
+ for (int n = 0; n < 5; ++n)
+ for (int g = 0; g < 3; ++g)
+ for (int sched = 1; sched <= 2; ++sched)
+ for (int strict = 0; strict <= 1; ++strict) {
+ errors += run(ull, counts[n], grains[g], sched, strict,
+ if_val, threads);
+ ++cases;
+ }
+ printf("GNU strict: cases=%d errors=%d\n", cases, errors);
+ return errors != 0;
+}
More information about the Openmp-commits
mailing list