Skip to content

Commit 030860a

Browse files
committed
Add run-valgrind
This partially addresses tensorflow#69, but it requires us to build TensorFlow from source, which is too slow to do on Travis.
1 parent e110f23 commit 030860a

File tree

7 files changed

+63
-0
lines changed

7 files changed

+63
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*~
2+
*.log
23
Cargo.lock
34
target
45
travis-ci/travis_rsa

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ random = "0.12"
1919

2020
[features]
2121
tensorflow_unstable = []
22+
# This is for testing purposes; users should not use this.
23+
nightly = []
2224

2325
[workspace]
2426

examples/addition.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![cfg_attr(feature="nightly", feature(alloc_system))]
2+
#[cfg(feature="nightly")]
3+
extern crate alloc_system;
14
extern crate tensorflow;
25

36
use std::error::Error;

examples/expressions.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![cfg_attr(feature="nightly", feature(alloc_system))]
2+
#[cfg(feature="nightly")]
3+
extern crate alloc_system;
14
extern crate random;
25
extern crate tensorflow;
36

examples/regression.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![cfg_attr(feature="nightly", feature(alloc_system))]
2+
#[cfg(feature="nightly")]
3+
extern crate alloc_system;
14
extern crate random;
25
extern crate tensorflow;
36

examples/regression_savedmodel.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![cfg_attr(feature="nightly", feature(alloc_system))]
2+
#[cfg(feature="nightly")]
3+
extern crate alloc_system;
14
extern crate random;
25
extern crate tensorflow;
36

run-valgrind

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Runs valgrind and reports results.
4+
#
5+
# Since jemalloc dropped support for valgrind
6+
# (https://github.com/jemalloc/jemalloc/issues/369), and both Rust and TensorFlow
7+
# use jemalloc by default, we need to compile both without it. Unfortunately,
8+
# compiling TensorFlow from source is expensive, so this script takes a long
9+
# time to run.
10+
11+
set -e
12+
13+
cd $(dirname $(readlink -f "$0"))
14+
15+
tensorflow_version=1.1.0
16+
17+
valgrind_log=valgrind.log
18+
truncate --size=0 "$valgrind_log"
19+
20+
# Disable jemalloc in TensorFlow.
21+
export TF_NEED_JEMALLOC=0
22+
23+
# Disable jemalloc in Rust.
24+
export TF_RUST_BUILD_FROM_SRC=true
25+
26+
# Don't need to rebuild the world, and `cargo clean --package tensorflow-sys` doesn't seem to do the job.
27+
rm -rf tensorflow-sys/target
28+
29+
# This is the very expensive step.
30+
cargo +nightly build --features=nightly -p tensorflow-sys -vvv
31+
32+
# Run valgrind against all the things.
33+
export LD_LIBRARY_PATH="$(echo "$PWD"/target/debug/build/tensorflow-sys-*/out/lib-v$tensorflow_version)"
34+
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
35+
for example in addition regression expressions; do
36+
cargo +nightly build --features='nightly tensorflow_unstable' --example="$example"
37+
valgrind --leak-check=full target/debug/examples/"$example" >> "$valgrind_log" 2>&1
38+
done
39+
40+
rel_log=$(readlink -f "$PWD"/"$valgrind_log")
41+
if grep -i 'error summary' < "$valgrind_log" > /dev/null; then
42+
echo "Error running valgrind. See $rel_log"
43+
fi
44+
45+
# Aggregate results.
46+
lost_bytes=$(awk '/(definitely|indirectly) lost:/{sum+=gensub(",","","g",$4)}END{print sum}' < "$valgrind_log")
47+
echo "Lost bytes: $lost_bytes"
48+
echo "For details, see $rel_log"

0 commit comments

Comments
 (0)