Memory Access Violations and Valgrind - 2025.2 English - UG1076

AI Engine Tools and Flows User Guide (UG1076)

Document ID
UG1076
Release Date
2025-11-20
Version
2025.2 English

Memory access violations occur when a kernel is reading or writing out of bounds of an object or reading uninitialized memory. Violations can manifest in multiple ways such as a simulator crash or hang. Violations can also cause simulator results to be non-repeatable. You can use the x86simulator --valgrind option to find memory access violations in kernel source code.

Note: You need to install Valgrind for this feature to work. AMD recommends using Valgrind version 3.16.1 and above.

This option allows detection of memory access violations in kernel source code during x86 simulation with Valgrind. The system can detect the following types of access violations:

  • Out-of-bounds write
  • Out-of-bounds read
  • Read of uninitialized memory

You can use this option in the following two ways:

x86simulator --valgrind
This option runs the simulation with access violation detection turned on. At the end of the simulation, Valgrind prints a report on access violations. If there are none, the report ends with ERROR SUMMARY: 0 errors from 0 contexts. Otherwise, the report lists each access violation found. The report includes a stack trace, which highlights the line number in the kernel source code where the access violations occurred.
x86simulator --valgrind-gdb
This option runs the simulation with access violation detection turned on and debug with GDB. The simulation comes up in GDB and is halted at main(). At this point you can set additional breakpoints. After continuing, the simulation stops if it detects an access violation. At this point you can inspect local variables and the stack to diagnose the problem.

In either case, you can add arguments to the Valgrind command using flag --valgrind-args='list of arguments for valgrind'.

The following example uses arguments to specify not to track memory leakage, and to display the overall stack when discovering an access violation. The example uses the following command:

--valgrind-args='-v --leak-check=no --track-origins=yes'

The snippet below shows the simulation running this command.

Figure 1. Simulation with Valgrind Arguments
Note: Running the x86simulator with the Valgrind option increases the simulation runtime.
Note: There are cases where Valgrind can report use of uninitialized memory associated with certain intrinsics. However, it is possible that there is no real problem because the results that depend on uninitialized memory are discarded.