diff --git a/.gitignore b/.gitignore index 60835d7aef..a496dcd1fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *~ +*.log Cargo.lock target travis-ci/travis_rsa diff --git a/Cargo.toml b/Cargo.toml index 8e10cf9fbe..403279abe9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,8 @@ random = "0.12" [features] tensorflow_unstable = [] +# This is for testing purposes; users should not use this. +nightly = [] [workspace] diff --git a/examples/addition.rs b/examples/addition.rs index 4f8ca5d046..31a75095d0 100644 --- a/examples/addition.rs +++ b/examples/addition.rs @@ -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; diff --git a/examples/expressions.rs b/examples/expressions.rs index 98bff3f016..c1ca09a9d6 100644 --- a/examples/expressions.rs +++ b/examples/expressions.rs @@ -1,3 +1,6 @@ +#![cfg_attr(feature="nightly", feature(alloc_system))] +#[cfg(feature="nightly")] +extern crate alloc_system; extern crate random; extern crate tensorflow; diff --git a/examples/regression.rs b/examples/regression.rs index 81b7bef42f..5cc6efbfef 100644 --- a/examples/regression.rs +++ b/examples/regression.rs @@ -1,3 +1,6 @@ +#![cfg_attr(feature="nightly", feature(alloc_system))] +#[cfg(feature="nightly")] +extern crate alloc_system; extern crate random; extern crate tensorflow; diff --git a/examples/regression_savedmodel.rs b/examples/regression_savedmodel.rs index 20b21d7197..cfef829c89 100644 --- a/examples/regression_savedmodel.rs +++ b/examples/regression_savedmodel.rs @@ -1,3 +1,6 @@ +#![cfg_attr(feature="nightly", feature(alloc_system))] +#[cfg(feature="nightly")] +extern crate alloc_system; extern crate random; extern crate tensorflow; diff --git a/run-valgrind b/run-valgrind new file mode 100755 index 0000000000..a95bc369aa --- /dev/null +++ b/run-valgrind @@ -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 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 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"