diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-09-06 09:41:45 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-09-15 16:19:22 -0400 |
commit | 607c90c7389f2b9a887a638613f6a311311d42b5 (patch) | |
tree | 20d08e56100eaae4fede5969116493e047399c5f /gdb/testsuite/gdb.rocm | |
parent | 947e047fac434621264f7212bbaa97580490d4fd (diff) | |
download | binutils-607c90c7389f2b9a887a638613f6a311311d42b5.zip binutils-607c90c7389f2b9a887a638613f6a311311d42b5.tar.gz binutils-607c90c7389f2b9a887a638613f6a311311d42b5.tar.bz2 |
gdb/amdgpu: add precise-memory support
The amd-dbgapi library exposes a setting called "memory precision" for
AMD GPUs [1]. Here's a copy of the description of the setting:
The AMD GPU can overlap the execution of memory instructions with other
instructions. This can result in a wave stopping due to a memory violation
or hardware data watchpoint hit with a program counter beyond the
instruction that caused the wave to stop.
Some architectures allow the hardware to be configured to always wait for
memory operations to complete before continuing. This will result in the
wave stopping at the instruction immediately after the one that caused the
stop event. Enabling this mode can make execution of waves significantly
slower.
Expose this option through a new "amdgpu precise-memory" setting.
The precise memory setting is per inferior. The setting is transferred
from one inferior to another when using the clone-inferior command, or
when a new inferior is created following an exec or a fork.
It can be set before starting the inferior, in which case GDB will
attempt to apply what the user wants when attaching amd-dbgapi. If the
user has requested to enable precise memory, but it can't be enabled
(not all hardware supports it), GDB prints a warning.
If precise memory is disabled, GDB prints a warning when hitting a
memory exception (translated into GDB_SIGNAL_SEGV or GDB_SIGNAL_BUS),
saying that the stop location may not be precise.
Note that the precise memory setting also affects memory watchpoint
reporting, but the watchpoint support for AMD GPUs hasn't been
upstreamed to GDB yet. When we do upstream watchpoint support, GDB will
produce a similar warning message when stopping due to a watchpoint if
precise memory is disabled.
Add a handful of tests. Add a util proc
"hip_devices_support_precise_memory", which indicates if all devices
used for testing support that feature.
[1] https://github.com/ROCm-Developer-Tools/ROCdbgapi/blob/687374258a27b5aab1309a7e8ded719e2f1ed3b1/include/amd-dbgapi.h.in#L6300-L6317
Change-Id: Ife1a99c0e960513da375ced8f8afaf8e47a61b3f
Approved-By: Lancelot Six <lancelot.six@amd.com>
Diffstat (limited to 'gdb/testsuite/gdb.rocm')
-rw-r--r-- | gdb/testsuite/gdb.rocm/precise-memory-exec.c | 44 | ||||
-rw-r--r-- | gdb/testsuite/gdb.rocm/precise-memory-exec.exp | 58 | ||||
-rw-r--r-- | gdb/testsuite/gdb.rocm/precise-memory-fork.c | 41 | ||||
-rw-r--r-- | gdb/testsuite/gdb.rocm/precise-memory-fork.exp | 50 | ||||
-rw-r--r-- | gdb/testsuite/gdb.rocm/precise-memory-multi-inferiors.exp | 87 | ||||
-rw-r--r-- | gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp | 33 | ||||
-rw-r--r-- | gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.exp | 45 | ||||
-rw-r--r-- | gdb/testsuite/gdb.rocm/precise-memory.cpp | 32 | ||||
-rw-r--r-- | gdb/testsuite/gdb.rocm/precise-memory.exp | 57 |
9 files changed, 447 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.rocm/precise-memory-exec.c b/gdb/testsuite/gdb.rocm/precise-memory-exec.c new file mode 100644 index 0000000..a1f941d --- /dev/null +++ b/gdb/testsuite/gdb.rocm/precise-memory-exec.c @@ -0,0 +1,44 @@ +/* Copyright 2021-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +static void +second (void) +{ +} + +int +main (int argc, char **argv) +{ + if (argc == 1) + { + /* First invocation. */ + int ret = execl (argv[0], argv[0], "Hello", NULL); + perror ("exec"); + abort (); + } + else + { + /* Second invocation. */ + second (); + } + + return 0; +} diff --git a/gdb/testsuite/gdb.rocm/precise-memory-exec.exp b/gdb/testsuite/gdb.rocm/precise-memory-exec.exp new file mode 100644 index 0000000..601f30b --- /dev/null +++ b/gdb/testsuite/gdb.rocm/precise-memory-exec.exp @@ -0,0 +1,58 @@ +# Copyright 2021-2023 Free Software Foundation, Inc. + +# This file is part of GDB. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test that the "set amdgpu precise-memory" setting is inherited by an inferior +# created following an exec. + +load_lib rocm.exp + +require allow_hipcc_tests + +standard_testfile .c + +if {[build_executable "failed to prepare $testfile" $testfile $srcfile {debug}]} { + return +} + +proc do_test { follow-exec-mode } { + clean_restart $::binfile + + with_rocm_gpu_lock { + if ![runto_main] { + return + } + + # Set precise-memory on the inferior before exec. + gdb_test "show amdgpu precise-memory" " is off.*" \ + "show amdgpu precise-memory before set" + gdb_test "set amdgpu precise-memory on" + gdb_test "show amdgpu precise-memory" " is on.*" \ + "show amdgpu precise-memory after set" + + # Continue past exec. The precise-memory setting should + # be on. + gdb_test_no_output "set follow-exec-mode ${follow-exec-mode}" + gdb_test "break second" + gdb_test "continue" "Breakpoint 1(\.$::decimal)?, main .*" + gdb_test "show amdgpu precise-memory" " is on.*" \ + "show amdgpu precise-memory after exec" + } +} + +foreach_with_prefix follow-exec-mode {same new} { + do_test ${follow-exec-mode} +} diff --git a/gdb/testsuite/gdb.rocm/precise-memory-fork.c b/gdb/testsuite/gdb.rocm/precise-memory-fork.c new file mode 100644 index 0000000..67ce09f --- /dev/null +++ b/gdb/testsuite/gdb.rocm/precise-memory-fork.c @@ -0,0 +1,41 @@ +/* Copyright 2021-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <unistd.h> + +static void +parent (void) +{ +} + +static void +child (void) +{ +} + +int +main (void) +{ + int pid = fork (); + + if (pid != 0) + parent (); + else + child (); + + return 0; +} diff --git a/gdb/testsuite/gdb.rocm/precise-memory-fork.exp b/gdb/testsuite/gdb.rocm/precise-memory-fork.exp new file mode 100644 index 0000000..347b62b --- /dev/null +++ b/gdb/testsuite/gdb.rocm/precise-memory-fork.exp @@ -0,0 +1,50 @@ +# Copyright 2021-2023 Free Software Foundation, Inc. + +# This file is part of GDB. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test that the "set amdgpu precise-memory" setting is inherited by a fork +# child. + +load_lib rocm.exp + +require allow_hipcc_tests + +standard_testfile .c + +if {[prepare_for_testing "failed to prepare $testfile" $testfile $srcfile {debug}]} { + return +} + +with_rocm_gpu_lock { + if ![runto_main] { + return + } + + # Set precise-memory on in the parent, before fork. + gdb_test "show amdgpu precise-memory" " is off.*" \ + "show amdgpu precise-memory before set" + gdb_test "set amdgpu precise-memory on" + gdb_test "show amdgpu precise-memory" " is on.*" \ + "show amdgpu precise-memory after set" + + # Continue past fork, following the child. The precise-memory setting should + # be on. + gdb_test "set follow-fork-mode child" + gdb_test "break child" + gdb_test "continue" "Thread 2.1 .* hit Breakpoint .*" + gdb_test "show amdgpu precise-memory" " is on.*" \ + "show amdgpu precise-memory after fork" +} diff --git a/gdb/testsuite/gdb.rocm/precise-memory-multi-inferiors.exp b/gdb/testsuite/gdb.rocm/precise-memory-multi-inferiors.exp new file mode 100644 index 0000000..9968b42 --- /dev/null +++ b/gdb/testsuite/gdb.rocm/precise-memory-multi-inferiors.exp @@ -0,0 +1,87 @@ +# Copyright 2021-2023 Free Software Foundation, Inc. + +# This file is part of GDB. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test that the "set amdgpu precise-memory" setting is per-inferior, and +# inherited by an inferior created using the clone-inferior command. + +load_lib rocm.exp + +require allow_hipcc_tests + +clean_restart + +set test_python [allow_python_tests] + +proc test_per_inferior { } { + gdb_test "show amdgpu precise-memory" \ + "AMDGPU precise memory access reporting is off \\(currently disabled\\)." \ + "show initial value, inferior 1" + if $::test_python { + gdb_test "python print(gdb.parameter(\"amdgpu precise-memory\"))" \ + "False" \ + "show initial value using Python, inferior 1" + } + gdb_test_no_output "set amdgpu precise-memory" \ + "set on inferior 1" + gdb_test "show amdgpu precise-memory" \ + "AMDGPU precise memory access reporting is on \\(currently disabled\\)." \ + "show new value, inferior 1" + if $::test_python { + gdb_test "python print(gdb.parameter(\"amdgpu precise-memory\"))" \ + "True" \ + "show new value using Python, inferior 1" + } + + gdb_test "add-inferior" "Added inferior 2" + gdb_test "inferior 2" "Switching to inferior 2 .*" + + gdb_test "show amdgpu precise-memory" \ + "AMDGPU precise memory access reporting is off \\(currently disabled\\)." \ + "show initial value, inferior 2" + if $::test_python { + gdb_test "python print(gdb.parameter(\"amdgpu precise-memory\"))" \ + "False" \ + "show initial value using Python, inferior 2" + } +} + +proc test_copy_precise_memory_on_clone {precise_memory} { + set value $precise_memory + if {$precise_memory == "unspecified"} { + set value off + } + + clean_restart + gdb_test "show amdgpu precise-memory" "is off.*" \ + "show default amdgpu precise-memory" + if {$precise_memory != "unspecified"} { + gdb_test_no_output "set amdgpu precise-memory $value" + gdb_test "show amdgpu precise-memory" "is $value.*" \ + "show amdgpu precise-memory on original inferior" + } + + gdb_test "clone-inferior" "Added inferior 2.*" + gdb_test "inferior 2" + gdb_test "show amdgpu precise-memory" "is $value.*" \ + "show amdgpu precise-memory on cloned inferior" +} + +test_per_inferior + +foreach_with_prefix precise_memory { unspecified on off } { + test_copy_precise_memory_on_clone $precise_memory +} diff --git a/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp b/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp new file mode 100644 index 0000000..bf1451a --- /dev/null +++ b/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.cpp @@ -0,0 +1,33 @@ +/* Copyright 2021-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <hip/hip_runtime.h> + +__global__ void +kernel () +{ + int *p = nullptr; + *p = 1; +} + +int +main (int argc, char* argv[]) +{ + kernel<<<1, 1>>> (); + hipDeviceSynchronize (); + return 0; +} diff --git a/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.exp b/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.exp new file mode 100644 index 0000000..2813ca7 --- /dev/null +++ b/gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.exp @@ -0,0 +1,45 @@ +# Copyright 2021-2023 Free Software Foundation, Inc. + +# This file is part of GDB. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test that when "amdgpu precise-memory" is off, hitting a SIGSEGV shows a +# warning about the stop location maybe being inaccurate. + +load_lib rocm.exp + +require allow_hipcc_tests + +standard_testfile .cpp + +if {[build_executable "failed to prepare" $testfile $srcfile {debug hip}]} { + return +} + +proc do_test { } { + clean_restart $::binfile + + with_rocm_gpu_lock { + if ![runto_main] { + return + } + + gdb_test_no_output "set amdgpu precise-memory off" + gdb_test "continue" \ + "SIGSEGV, Segmentation fault.*Warning: precise memory violation signal reporting is not enabled.*" + } +} + +do_test diff --git a/gdb/testsuite/gdb.rocm/precise-memory.cpp b/gdb/testsuite/gdb.rocm/precise-memory.cpp new file mode 100644 index 0000000..034f023 --- /dev/null +++ b/gdb/testsuite/gdb.rocm/precise-memory.cpp @@ -0,0 +1,32 @@ +/* Copyright 2021-2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <hip/hip_runtime.h> + +__global__ void +kernel () +{ + __builtin_amdgcn_s_sleep (1); +} + +int +main (int argc, char* argv[]) +{ + kernel<<<1, 1>>> (); + hipDeviceSynchronize (); + return 0; +} diff --git a/gdb/testsuite/gdb.rocm/precise-memory.exp b/gdb/testsuite/gdb.rocm/precise-memory.exp new file mode 100644 index 0000000..62b7515 --- /dev/null +++ b/gdb/testsuite/gdb.rocm/precise-memory.exp @@ -0,0 +1,57 @@ +# Copyright 2022-2023 Free Software Foundation, Inc. + +# This file is part of GDB. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test showing the "amdgpu precise-memory" setting. + +load_lib rocm.exp + +require allow_hipcc_tests + +standard_testfile .cpp + +if {[build_executable "failed to prepare" $testfile $srcfile {debug hip}]} { + return +} + +proc do_test { } { + clean_restart $::binfile + + with_rocm_gpu_lock { + if ![runto_main] { + return + } + + gdb_test "show amdgpu precise-memory" \ + "AMDGPU precise memory access reporting is off \\(currently disabled\\)." \ + "show precise-memory setting in CLI before" + + if {[hip_devices_support_precise_memory]} { + gdb_test_no_output "set amdgpu precise-memory on" + set cli_effective_value "enabled" + } else { + gdb_test "set amdgpu precise-memory on" \ + "warning: AMDGPU precise memory access reporting could not be enabled." + set cli_effective_value "disabled" + } + + gdb_test "show amdgpu precise-memory" \ + "AMDGPU precise memory access reporting is on \\(currently ${cli_effective_value}\\)." \ + "show precise-memory setting in CLI after" + } +} + +do_test |