Skip to content

Commit ddb684e

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 73ed289 commit ddb684e

File tree

7 files changed

+56
-0
lines changed

7 files changed

+56
-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

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
cd $(dirname $(readlink -f "$0"))
12+
13+
tensorflow_version=1.1.0
14+
15+
valgrind_log=valgrind.log
16+
truncate --size=0 "$valgrind_log"
17+
18+
# Disable jemalloc in TensorFlow.
19+
export TF_NEED_JEMALLOC=0
20+
21+
# Disable jemalloc in Rust.
22+
export TF_RUST_BUILD_FROM_SRC=true
23+
24+
# Don't need to rebuild the world, and `cargo clean --package tensorflow-sys` doesn't seem to do the job.
25+
rm -rf tensorflow/target tensorflow-sys/target
26+
27+
# This is the very expensive step.
28+
cargo +nightly build --features=nightly -p tensorflow-sys -vv
29+
30+
# Run valgrind against all the things.
31+
export LD_LIBRARY_PATH="$PWD"/tensorflow-sys/target/libtensorflow-cpu-linux-x86_64-$tensorflow_version/lib
32+
for example in addition regression expressions; do
33+
cargo +nightly build --features='nightly tensorflow_unstable' --example="$example"
34+
valgrind --leak-check=full target/debug/examples/"$example" >> "$valgrind_log" 2>&1
35+
done
36+
37+
# Aggregate results.
38+
lost_bytes=$(awk '/(definitely|indirectly) lost:/{sum+=gensub(",","","g",$4)}END{print sum}' < "$valgrind_log")
39+
echo "Lost bytes: $lost_bytes"
40+
rel_log=$(readlink -f "$PWD"/"$valgrind_log")
41+
echo "For details, see $rel_log"

0 commit comments

Comments
 (0)