gdb/testsuite/gdb.rocm: add OpenMP GPU offload tests#134
Conversation
|
With flang-23 I get: |
gdb_compile auto-injects "early_flags=-fno-stack-protector" whenever
test_compiler_info reports the host C compiler as gcc-N-M, the GCC
DWARF line-numbering workaround applies (GCC PR 88432), and the
options don't include rust or hip.
LLVM-based Fortran drivers (such as flang/amdflang) reject the
unknown -fno-stack-protector argument:
flang-23: error: unknown argument: '-fno-stack-protector'
This breaks gdb.rocm/omp-target-fortran.exp on hosts where the host
C compiler is GCC but F90_FOR_TARGET is a non-GNU driver, even
though the test never asked for the flag.
GCC PR 88432 is language-agnostic but the workaround itself is
GCC-specific. Extend the existing rust/hip exclusions so that the
flag is also skipped when:
- the "f77" option is set (no get_compiler_info entry; effectively
unused in the modern testsuite), or
- the "f90" option is set together with a non-gcc-* F90 compiler.
gfortran ("f90" + gcc-*) continues to receive the workaround, so
gdb.fortran tests on Debian/Ubuntu (where -fstack-protector-strong
is the default) are unaffected.
Verified with AMD flang 23.0.0git on
gdb.rocm/omp-target-fortran.exp (3 PASS, 0 FAIL); the rest of the
gdb.rocm/omp-target-*.exp suite is unchanged at 44 PASS / 0 FAIL
(47 total).
Reported on PR #134.
There was a problem hiding this comment.
With flang-23 I get:
gdb compile failed, flang-23: error: unknown argument: '-fno-stack-protector'
for omp-target-fortran.exp.
It comes from this part of gdb.exp:if { !$getting_compiler_info && [test_compiler_info {gcc-*-*}] && !([test_compiler_info {gcc-[0-3]-*}] || [test_compiler_info {gcc-4-0-*}]) && [lsearch -exact $options rust] == -1 && [lsearch -exact $options hip] == -1} { # Put it at the front to not override any user-provided value. lappend new_options "early_flags=-fno-stack-protector" }flang --version AMD flang version 23.0.0git (https://github.com/ROCm/llvm-project.git 43215c73116c407735c85a180d174f718798c328+PATCHED:2506c552d8428e2cc1778bef048b20f818e06bb3) Target: x86_64-unknown-linux-gnu Thread model: posix
Applied fix in 1d0d3cd this commit
The previous attempt at gating the -fno-stack-protector skip on a
non-GNU Fortran driver used:
!([lsearch -exact $options f90] != -1
&& ![test_compiler_info {gcc-*} f90])
This was wrong. lib/compiler.F90 emits the f90 compiler_info string
as "gfortran-N-N-N" for gfortran (driven by __GFORTRAN__), never as
"gcc-*". As a result, [test_compiler_info {gcc-*} f90] always
returned false, so the inner sub-clause was always true and the flag
was skipped for every Fortran compile - functionally identical to a
blanket f90 skip. This re-exposes GCC PR 88432 prologue/line-number
breakage for gdb.fortran tests on Debian/Ubuntu, where
-fstack-protector-strong is enabled by default.
Match the identity that lib/compiler.F90 actually emits for gfortran
("gfortran-*") instead. With this change:
- f90 + gfortran : test_compiler_info {gfortran-*} f90 -> true,
so the flag is added (workaround preserved).
- f90 + flang/ifx/etc.: identity is "flang-llvm-*",
"flang-classic-*", "ifx-*", "ifort-*", etc.;
test_compiler_info {gfortran-*} f90 -> false,
so the flag is skipped (avoids unknown-arg
errors from non-GCC drivers).
- non-Fortran compiles: unaffected (the f90 sub-clause is false).
Verified on a host with both gfortran 11.4.0 and AMD flang 23.0.0git
by preprocessing lib/compiler.F90 with each driver:
gfortran: set compiler_info [join {gfortran 11 4 0} -]
amdflang: set compiler_info [join "flang-llvm $major $minor $patch" -]
Also re-ran the gdb.rocm/omp-target-*.exp suite under amdflang:
unchanged at 47 PASS / 0 FAIL, and the amdflang command line still
contains no -fno-stack-protector argument.
Reported on PR #134.
gdb_compile auto-injects -fno-stack-protector when the host C compiler
reports as gcc-* (GCC PR 88432 workaround). Non-GNU Fortran drivers
(flang, amdflang, ifx, ifort) reject this unknown argument:
flang-23: error: unknown argument: '-fno-stack-protector'
Skip the flag when "f77" is in options (get_compiler_info has no entry
for f77 and the language is effectively unused in the modern testsuite)
and when "f90" is in options together with a non-gfortran-* F90
compiler, as detected via lib/compiler.F90. gfortran ("f90" +
gfortran-*) keeps receiving the workaround, so gdb.fortran tests on
Debian/Ubuntu (where -fstack-protector-strong is the default) are
unaffected.
Verified:
- gdb.rocm/omp-target-fortran.exp under amdflang 23: 3 PASS / 0 FAIL.
- gdb.fortran/*.exp under gfortran 11.4: 5677 PASS / 686 FAIL,
identical to baseline (no change in test outcomes; all 164 gfortran
invocations still receive -fno-stack-protector).
Reported on PR #134.
c3b5cee to
928fc53
Compare
There was a problem hiding this comment.
Pull request overview
Adds OpenMP GPU-offload coverage to the gdb.rocm testsuite by extending the ROCm DejaGnu helpers to build/run OpenMP target-offload programs (C/C++/Fortran) and introducing new OpenMP-offload-focused testcases.
Changes:
- Extend
gdb/testsuite/lib/rocm.expwith OpenMP offload toolchain discovery, build flag construction, compile wrappers, GPU-lock aliasing, and reusable “continue/step/check wave” helpers. - Adjust
gdb_compileingdb/testsuite/lib/gdb.expto avoid adding GCC-specific flags for non-GNU Fortran drivers (notably affectingf90with flang/amdflang/etc.). - Add new
gdb.rocm/omp-target-*tests covering basic target break/locals/step, teams+waves, multi-kernel named breakpoints, target data reuse, C++ templates/functors, and a Fortran target loop.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| gdb/testsuite/lib/rocm.exp | Adds OpenMP-offload tool/flag/compile helpers and common stop/step assertions for OpenMP target regions. |
| gdb/testsuite/lib/gdb.exp | Refines -fno-stack-protector injection logic to avoid breaking non-gfortran f90 compilers. |
| gdb/testsuite/gdb.rocm/omp-target-basic.exp | New basic OpenMP target offload debugging checks (breakpoint/locals/step). |
| gdb/testsuite/gdb.rocm/omp-target-basic.c | Test program for basic target breakpoint/locals/step coverage. |
| gdb/testsuite/gdb.rocm/omp-target-teams.exp | New OpenMP teams/distribute/parallel-for wave/thread switching test. |
| gdb/testsuite/gdb.rocm/omp-target-teams.c | Test program intended to create multiple waves at a target breakpoint. |
| gdb/testsuite/gdb.rocm/omp-target-data.exp | New target data reuse test with two consecutive target regions. |
| gdb/testsuite/gdb.rocm/omp-target-data.c | Test program exercising device buffer reuse across kernels under target data. |
| gdb/testsuite/gdb.rocm/omp-target-multi-kernel.exp | New test for distinct declare target device functions hit by named breakpoints. |
| gdb/testsuite/gdb.rocm/omp-target-multi-kernel.c | Test program with square_dev and cube_dev launched from separate target regions. |
| gdb/testsuite/gdb.rocm/omp-target-cpp.exp | New C++-specific offload test for template and functor debugging. |
| gdb/testsuite/gdb.rocm/omp-target-cpp.cpp | C++ test program using a templated device function and struct functor in a target region. |
| gdb/testsuite/gdb.rocm/omp-target-fortran.exp | New Fortran OpenMP-offload breakpoint/wave test. |
| gdb/testsuite/gdb.rocm/omp-target-fortran.f90 | Fortran offload test program for !$omp target loop. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gdb_compile auto-injects -fno-stack-protector when the host C compiler
reports as gcc-* (GCC PR 88432 workaround). Non-GNU Fortran drivers
(flang, amdflang, ifx, ifort) reject this unknown argument:
flang-23: error: unknown argument: '-fno-stack-protector'
Skip the flag when "f77" is in options (get_compiler_info has no entry
for f77 and the language is effectively unused in the modern testsuite)
and when "f90" is in options together with a non-gfortran-* F90
compiler, as detected via lib/compiler.F90. gfortran ("f90" +
gfortran-*) keeps receiving the workaround, so gdb.fortran tests on
Debian/Ubuntu (where -fstack-protector-strong is the default) are
unaffected.
Verified:
- gdb.rocm/omp-target-fortran.exp under amdflang 23: 3 PASS / 0 FAIL.
- gdb.fortran/*.exp under gfortran 11.4: 5677 PASS / 686 FAIL,
identical to baseline (no change in test outcomes; all 164 gfortran
invocations still receive -fno-stack-protector).
Reported on PR #134.
4103fab to
651f91f
Compare
|
Thanks for the review @lumachad. Following your note about not blocking #62: I'll keep the OpenMP-offload series here in #134 and base it on top of #62's branch, so #62 stays independent and #134 is reviewed as close-to-final code. The OMP-specific parts (offload flags, test helpers, the Already addressed in the meantime:
|
aktemur
left a comment
There was a problem hiding this comment.
I looked at the omp-target-teams test and rocm.exp only. I think we should first resolve infrastructure questions.
|
@aktemur Agreed on settling the infrastructure. Per @lumachad's note about keeping #62 unblocked, I'll base #134 on top of #62's series and keep the OpenMP-offload infra + tests here so it's reviewed close-to-final, rather than holding it or pushing pieces into #62. The shared bits (common |
Changelog —
|
|
Set to @aktemur as he left the earlier comments. |
Add a gdb.rocm test suite that exercises debugging of OpenMP "target"
offload regions on AMD GPUs, built with the amdclang/amdclang++/amdflang
toolchain, plus the supporting testsuite framework hooks.
Framework (gdb/testsuite/lib/rocm.exp):
- Add OpenMP-offload compiler discovery: rocm_find_llvm_tool and the
find_amdclang / find_amdclangpp / find_amdflang helpers, searching
$ROCM_PATH/llvm/bin, $ROCM_PATH/lib/llvm/bin, then PATH.
- Add allow_omp_offload_tests and allow_omp_offload_fortran_tests
predicates for use with 'require' (gate on Linux, amd-dbgapi support,
toolchain availability and a usable AMD GPU). These mirror the
amd-staging allow_hip_tests gate.
- Add rocm_omp_offload_flags plus gdb_compile_omp_offload{,_cpp,_fortran}
wrappers that build with -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa
and the discovered compiler.
- Add rocm_omp_prune_benign_warnings / rocm_omp_compile to drop the
known-harmless ROCm 7.14 device ld.lld __keep_alive "local memory
global used by non-kernel function" warning on a single line, while
still logging genuine compile failures via verbose -log. This keeps
omp-target-teams from being spuriously marked UNTESTED.
- Add shared stop-report helpers (rocm_omp_continue_to_breakpoint,
rocm_omp_continue_to_function, rocm_omp_check_on_wave,
rocm_omp_continue_to_exit, rocm_omp_next) that tolerate the
multi-line stop output seen for OpenMP-offload kernels.
Tests (gdb/testsuite/gdb.rocm/omp-target-*):
- omp-target-basic: device breakpoint, stepping, and inspection of
mapped / firstprivate locals in a target region.
- omp-target-teams: target teams distribute parallel for; require at
least one AMDGPU wave at the breakpoint and a non-negative loop index.
- omp-target-data: target data regions with array maps.
- omp-target-multi-kernel: multiple kernels in one binary.
- omp-target-cpp: C++ templates / functor offload via amdclang++.
- omp-target-fortran: Fortran offload via amdflang.
gdb_compile (gdb/testsuite/lib/gdb.exp):
- Skip the GCC-specific -fno-stack-protector DWARF-line workaround
(GCC PR 88432) for non-GNU Fortran drivers, i.e. "f90" with a
compiler that does not match gfortran-* (flang, amdflang, ifx,
ifort), which reject the unknown argument even when the host C
compiler is GCC. gfortran still receives the workaround, and the
unused "f77" path is skipped unconditionally.
6ce4ae4 to
a5e145b
Compare
Rebased on amd-staging + review fixes (
|
|
|
||
| for (int i = 0; i < N; i++) | ||
| out_arr[i] = in_arr[i] + priv_val + firstpriv_val | ||
| + step_two + step_three; |
There was a problem hiding this comment.
Nit: '+' should be indented two spaces inside wrt out_arr. A preferred alternative is to parenthesize the arithmetic expression, like this:
for (int i = 0; i < N; i++)
out_arr[i] = (in_arr[i] + priv_val + firstpriv_val
+ step_two + step_three);
| gdb_breakpoint "$srcfile:$first_line" allow-pending | ||
|
|
||
| with_test_prefix "breakpoint" { | ||
| rocm_omp_continue_to_breakpoint "continue to device breakpoint" |
There was a problem hiding this comment.
I don't think using custom procs for these GDB commands will scale well. Can we please try to use the usual gdb_breakpoint, gdb_test, etc. procs? This applies to procs like rocm_omp_check_on_wave, rocm_omp_next, rocm_omp_continue_to_exit`, etc.
| # Step forward through a few statements; each step must stay on a | ||
| # GPU wave. Line numbers are not pinned because OpenMP-offload | ||
| # line tables vary across compiler versions. | ||
| with_test_prefix "step" { |
There was a problem hiding this comment.
We don't need this prefix; there is next-$which below already.
| if {[gdb_compile_omp_offload [list $srcdir/$subdir/$srcfile] \ | ||
| [standard_output_file $testfile] executable {debug}] != ""} { |
There was a problem hiding this comment.
My first expectation would be that we use the usual build_executable/prepare_for_testing by passing it the proper option (e.g. omp rocm), like we do for HIP tests. Then the testing framework finds the right compiler and sets the right flags, again similar to how HIP testing is done.
|
|
||
| # Compile via gdb_compile, prune known-harmless warnings, and log any | ||
| # remaining output (gdb_compile is quiet so benign noise is suppressed). | ||
| proc rocm_omp_compile {source dest type options} { |
There was a problem hiding this comment.
By passing the proper omp and rocm options to gdb_compile, I think all can be handled in gdb_compile. So, this custom proc and the related ones below can be removed.
| return $result | ||
| } | ||
|
|
||
| # Helpers shared by the gdb.rocm/omp-target-*.exp tests. |
There was a problem hiding this comment.
Ideally, the custom procs should all go away and we should be able to use the usual gdb_... procs in .exp files.
|
@aktemur Thank you for the recent review. On moving the OpenMP-offload tests to Since amdclang isn't the only OpenMP compiler and the driver differs by language (C -> amdclang, C++ -> amdclang++, Fortran -> amdflang), would you prefer The remaining comments are clear and I'll address them in the next revision (fold the compile wrappers into |
Hi @spatrang, as the first approach, I'd suggest having two arguments: (1) language, (2) |
Summary
Add OpenMP GPU offload coverage to the
gdb.rocm/testsuite.The existing
gdb.rocm/tests cover HIP-style kernels (__global__functions launched via
hipLaunchKernelGGL), but there is no coveragefor OpenMP
targetoffload — an increasingly common way of programmingAMD GPUs from C, C++ and Fortran. Without these tests, regressions in
GDB's handling of:
__omp_offloading_<hash>_<func>_l<line>outliner-frame symbols,libomptargetplugins,not
libamdhip64),map-clause variables,can land silently while the HIP path keeps working.
Motivation
gdb.threads/already has CPU-side OpenMP tests (omp-par-scope.exp,omp-task.exp), but nothing in the testsuite exercises thetargetconstruct on an actual GPU. This PR adds those tests and the dejagnu
framework hooks needed to drive an OpenMP-offload-capable Clang/Flang
toolchain.
What changed
Framework hooks in
gdb/testsuite/lib/rocm.exp(+186 lines)Reusable procs that future OpenMP-offload tests can also rely on:
then `$ROCM_PATH/lib/llvm/bin`, then `PATH`.
wrappers for the three offload-capable compiler drivers.
`require`-compatible predicates: amd-dbgapi support, toolchain
availability, ≥ 1 AMD GPU.
`-fopenmp -fopenmp-targets=amdgcn-amd-amdhsa --offload-arch=…`
flag set; omits the Clang-only `-Wno-unused-command-line-argument`
for Fortran (the Flang driver rejects that diagnostic option).
`gdb_compile_omp_offload_fortran` — `gdb_compile` wrappers that
swap in the right offload-capable driver and add the offload flags.
OpenMP tests serialize with HIP tests on the GPU.
New tests under `gdb/testsuite/gdb.rocm/` (16 files)
`file:line`, AMDGPU wave check.
keeps the program on a wave.
`firstprivate` and a device-local automatic variable.
produces multiple AMDGPU waves at one breakpoint; `thread N`
switches to a wave; `print i` works inside it.
`target` regions; the device buffer is reused between kernels
(verified via `c[0] == 100` in the second kernel).
launched from separate target regions; named breakpoints land on the
right kernel.
struct functor (`multiplier::operator()`) compiled with the C++
driver; `print this->factor` works.
driver; breakpoint inside the loop hits an AMDGPU wave.
Each `.exp` follows the established `gdb.rocm/` patterns:
`load_lib rocm.exp`, `require allow_omp_offload_tests`,
`with_rocm_omp_gpu_lock { … }`, and uses the `gdb_test_multiple` +
`exp_continue` idiom (same as `gdb.rocm/shared-memory.exp`) so the
patterns survive multi-line GDB output.
Testing
```
make -C testsuite check TESTS="gdb.rocm/omp-target-*.exp"
…
of expected passes 47
of unexpected failures 0
```
Per-test PASS / FAIL counts:
On hosts without an offload-capable Clang/Flang toolchain or without an
AMD GPU, the `require allow_omp_offload_tests` /
`allow_omp_offload_fortran_tests` gates report the tests as
`UNSUPPORTED` rather than `FAIL`, so this PR is safe to land in CI
immediately.
Backwards compatibility
no signature changes. Existing HIP tests are unaffected.
`find_hipcc`) so there is no collision.