Skip to content

Add run-valgrind #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*~
*.log
Cargo.lock
target
travis-ci/travis_rsa
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ random = "0.12"

[features]
tensorflow_unstable = []
# This is for testing purposes; users should not use this.
nightly = []

[workspace]

3 changes: 3 additions & 0 deletions examples/addition.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg_attr(feature="nightly", feature(alloc_system))]
#[cfg(feature="nightly")]
extern crate alloc_system;
extern crate tensorflow;

use std::error::Error;
3 changes: 3 additions & 0 deletions examples/expressions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg_attr(feature="nightly", feature(alloc_system))]
#[cfg(feature="nightly")]
extern crate alloc_system;
extern crate random;
extern crate tensorflow;

3 changes: 3 additions & 0 deletions examples/regression.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg_attr(feature="nightly", feature(alloc_system))]
#[cfg(feature="nightly")]
extern crate alloc_system;
extern crate random;
extern crate tensorflow;

3 changes: 3 additions & 0 deletions examples/regression_savedmodel.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg_attr(feature="nightly", feature(alloc_system))]
#[cfg(feature="nightly")]
extern crate alloc_system;
extern crate random;
extern crate tensorflow;

48 changes: 48 additions & 0 deletions run-valgrind
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Runs valgrind and reports results.
#
# Since jemalloc dropped support for valgrind
# (https://github.com/jemalloc/jemalloc/issues/369), and both Rust and TensorFlow
# use jemalloc by default, we need to compile both without it. Unfortunately,
# compiling TensorFlow from source is expensive, so this script takes a long
# time to run.

set -e

cd $(dirname $(readlink -f "$0"))

tensorflow_version=1.1.0

valgrind_log=valgrind.log
truncate --size=0 "$valgrind_log"

# Disable jemalloc in TensorFlow.
export TF_NEED_JEMALLOC=0

# Disable jemalloc in Rust.
export TF_RUST_BUILD_FROM_SRC=true

# Don't need to rebuild the world, and `cargo clean --package tensorflow-sys` doesn't seem to do the job.
rm -rf tensorflow-sys/target

# This is the very expensive step.
cargo +nightly build --features=nightly -p tensorflow-sys -vvv

# Run valgrind against all the things.
export LD_LIBRARY_PATH="$(echo "$PWD"/target/debug/build/tensorflow-sys-*/out/lib-v$tensorflow_version)"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
for example in addition regression expressions; do
cargo +nightly build --features='nightly tensorflow_unstable' --example="$example"
valgrind --leak-check=full target/debug/examples/"$example" >> "$valgrind_log" 2>&1
done

rel_log=$(readlink -f "$PWD"/"$valgrind_log")
if grep -i 'error summary' < "$valgrind_log" > /dev/null; then
echo "Error running valgrind. See $rel_log"
fi

# Aggregate results.
lost_bytes=$(awk '/(definitely|indirectly) lost:/{sum+=gensub(",","","g",$4)}END{print sum}' < "$valgrind_log")
echo "Lost bytes: $lost_bytes"
echo "For details, see $rel_log"