uwplse / herbgrind

A Valgrind tool for Herbie
GNU General Public License v3.0
90 stars 7 forks source link

Herbgrind cannot handle Haswell instructions #5

Closed peddie closed 6 years ago

peddie commented 6 years ago

I realize this might be out of scope for the current development focus of herbgrind, but I thought I'd report it anyway for completeness.

I've run the following example program:

#include <cstdlib>
#include <iostream>

#include <Eigen/Core>
#include <Eigen/Cholesky>

#include <herbgrind.h>

int main(int argc __attribute__((unused)),
         char **argv __attribute__((unused))) {
  // Make sure we get consistent results from the RNG
  std::srand(22);

  // This succeeds with a 2x2 matrix and fails with a 3x3 matrix.
  const Eigen::MatrixXd A(Eigen::MatrixXd::Random(3, 3));
  const Eigen::MatrixXd ATA(A.transpose() * A);
  HERBGRIND_BEGIN();
  const Eigen::LDLT<Eigen::MatrixXd> Achol(ATA);
  HERBGRIND_END();

  std::cout << "D: " << Achol.vectorD().transpose() << std::endl;
  std::cout << "L:" << std::endl
            << Eigen::MatrixXd(Achol.matrixL()) << std::endl;

  return 0;
}

built with the following command:

g++-6 -Wall -Weffc++ -std=c++14 -Wextra -O3 -isystem/home/peddie/software/numerical/herbgrind/valgrind/herbgrind//include/ -isystem/usr/include/eigen3 -o foo foo.cc

and I receive the expected output:

D:    1.36011   0.423706 0.00554178
L:
        1         0         0
-0.382097         1         0
-0.185461 -0.943135         1

If I add -march=ivybridge to my compile command, all is well, but if I go one more step to -march=haswell, herbgrind dies with a failed assertion (full transcript below):

Herbgrind: instrument/instrument-op.c:127 (instrumentOp): Assertion '!hasStaticShadow(argExprs[i])' failed.

It would be nice to be able to run the exact binary I want to use in production under herbgrind.

Here is the full error transcript:

peddie@subutai:gaussianprocesses $ /home/peddie/software/numerical/herbgrind/valgrind/herbgrind-install/bin/valgrind --tool=herbgrind --start-off ./foo==1011== Herbgrind, a valgrind tool for Herbie
==1011== Copyright (C) 2016-2017, and GNU GPL'd, by Alex Sanchez-Stern
==1011== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==1011== Command: ./foo
==1011== 
--1011-- WARNING: Serious error when reading debug info
--1011-- When reading debug info from /lib/x86_64-linux-gnu/ld-2.24.so:
--1011-- Ignoring non-Dwarf2/3/4 block in .debug_info
--1011-- WARNING: Serious error when reading debug info
--1011-- When reading debug info from /lib/x86_64-linux-gnu/ld-2.24.so:
--1011-- Last block truncated in .debug_info; ignoring
--1011-- WARNING: Serious error when reading debug info
--1011-- When reading debug info from /lib/x86_64-linux-gnu/libm-2.24.so:
--1011-- Ignoring non-Dwarf2/3/4 block in .debug_info
--1011-- WARNING: Serious error when reading debug info
--1011-- When reading debug info from /lib/x86_64-linux-gnu/libm-2.24.so:
--1011-- Last block truncated in .debug_info; ignoring
--1011-- WARNING: Serious error when reading debug info
--1011-- When reading debug info from /lib/x86_64-linux-gnu/libgcc_s.so.1:
--1011-- Ignoring non-Dwarf2/3/4 block in .debug_info
--1011-- WARNING: Serious error when reading debug info
--1011-- When reading debug info from /lib/x86_64-linux-gnu/libgcc_s.so.1:
--1011-- Last block truncated in .debug_info; ignoring
--1011-- WARNING: Serious error when reading debug info
--1011-- When reading debug info from /lib/x86_64-linux-gnu/libc-2.24.so:
--1011-- Ignoring non-Dwarf2/3/4 block in .debug_info
--1011-- WARNING: Serious error when reading debug info
--1011-- When reading debug info from /lib/x86_64-linux-gnu/libc-2.24.so:
--1011-- Last block truncated in .debug_info; ignoring
64x4toV256 on t17

Herbgrind: instrument/instrument-op.c:127 (instrumentOp): Assertion '!hasStaticShadow(argExprs[i])' failed.

host stacktrace:
==1011==    at 0x3807065A: show_sched_status_wrk (m_libcassert.c:343)
==1011==    by 0x38070774: report_and_quit (m_libcassert.c:415)
==1011==    by 0x3807090A: vgPlain_assert_fail (m_libcassert.c:481)
==1011==    by 0x380653B7: instrumentOp (instrument-op.c:127)
==1011==    by 0x3806457B: hg_instrument (instrument.c:79)
==1011==    by 0x3808D10F: tool_instrument_then_gdbserver_if_needed (m_translate.c:238)
==1011==    by 0x3813F50E: LibVEX_Translate (main_main.c:934)
==1011==    by 0x3808FA90: vgPlain_translate (m_translate.c:1765)
==1011==    by 0x380C2BCB: handle_chain_me (scheduler.c:1076)
==1011==    by 0x380C4957: vgPlain_scheduler (scheduler.c:1420)
==1011==    by 0x380D4850: run_a_thread_NORETURN (syswrap-linux.c:102)

sched status:
  running_tid=1

Thread 1: status = VgTs_Runnable (lwpid 1011)
==1011==    at 0x10FD50: Eigen::internal::general_matrix_vector_product<long, double, Eigen::internal::const_blas_data_mapper<double, long, 0>, 0, false, double, Eigen::internal::const_blas_data_mapper<double, long, 1>, false, 0>::run(long, long, Eigen::internal::const_blas_data_mapper<double, long, 0> const&, Eigen::internal::const_blas_data_mapper<double, long, 1> const&, double*, long, double) (in /home/peddie/programming/gaussianprocesses/foo)
==1011==    by 0x11110D: bool Eigen::internal::ldlt_inplace<1>::unblocked<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Transpositions<-1, -1, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, -1, 0, -1, -1>&, Eigen::Transpositions<-1, -1, int>&, Eigen::Matrix<double, -1, 1, 0, -1, 1>&, Eigen::internal::SignMatrix&) (in /home/peddie/programming/gaussianprocesses/foo)
==1011==    by 0x1124E2: Eigen::LDLT<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 1>& Eigen::LDLT<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 1>::compute<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::EigenBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&) (in /home/peddie/programming/gaussianprocesses/foo)
==1011==    by 0x1127BB: Eigen::LDLT<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 1>::LDLT<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::EigenBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&) (in /home/peddie/programming/gaussianprocesses/foo)
==1011==    by 0x109941: main (in /home/peddie/programming/gaussianprocesses/foo)

Note: see also the FAQ in the source distribution.
It contains workarounds to several common problems.
In particular, if Valgrind aborted or crashed after
identifying problems in your program, there's a good chance
that fixing those problems will prevent Valgrind aborting or
crashing, especially if it happened in m_mallocfree.c.

If that doesn't help, please report this bug to: www.valgrind.org

In the bug report, send all the above text, the valgrind
version, and what OS and version you are using.  Thanks.
HazardousPeach commented 6 years ago

Oops, I guess I never responded to this! I think I fixed this bug a few months back: I remember being able to reproduce this issue when I first saw this bug report, but now Herbgrind seems to run without crashing on the program in question.

Unfortunately, Herbgrind doesn't recognize the C++ idiom of using cout streams to print, so it doesn't see the outputs currently. Eventually, I'll try to fix this, but for now you could insert a "printf", or simply use the HERBGRIND_MARK_IMPORTANT macro to mark your output. I think the latter should basically have no runtime effect when not run under Herbgrind (it inserts a little block of assembly which is a no-op, but is recognized by Herbgrind).

If the output recognition is important to you, feel free to file another issue, and I'll keep it on my todo list.