Skip to content

Commit

Permalink
Add run-valgrind
Browse files Browse the repository at this point in the history
This partially addresses tensorflow#69, but it requires us to build TensorFlow from source, which is too slow to do on Travis.
  • Loading branch information
adamcrume committed Jun 17, 2017
1 parent 73ed289 commit ddb684e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 0 deletions.
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
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ random = "0.12"

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

[workspace]

Expand Down
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;
Expand Down
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;

Expand Down
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;

Expand Down
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;

Expand Down
41 changes: 41 additions & 0 deletions run-valgrind
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/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.

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/target tensorflow-sys/target

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

# Run valgrind against all the things.
export LD_LIBRARY_PATH="$PWD"/tensorflow-sys/target/libtensorflow-cpu-linux-x86_64-$tensorflow_version/lib
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

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

0 comments on commit ddb684e

Please sign in to comment.