Skip to content

Commit

Permalink
=use Conda.jl to install python binding
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Jun 16, 2017
1 parent 80c0b0c commit 34802b0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ julia:
- 0.5
- 0.6
- nightly
env:
- PYTHON=""
notifications:
email: false
script:
- julia -e 'Pkg.clone(pwd())'
- julia deps/build_pytensorflow.jl
- julia -e 'Pkg.build("TensorFlow")'
- julia -e 'Pkg.test("TensorFlow", coverage=true)'
after_success:
Expand Down
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
julia 0.5
ProtoBuf 0.3.0
PyCall 1.7.1
Conda 0.2.3
Distributions 0.10.2
JLD 0.6.3
FileIO 0.1.2
Expand Down
97 changes: 69 additions & 28 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
using PyCall
using Conda

const cur_version = "1.1.0"
const use_gpu = "TF_USE_GPU" keys(ENV) && ENV["TF_USE_GPU"] == "1"

if use_gpu
info("Building TensorFlow.jl for use on the GPU")
else
info("Building TensorFlow.jl for CPU use only. To enable the GPU, set the TF_USE_GPU environment variable to 1 and rebuild TensorFlow.jl")
end

#############################
# Install Python TensorFlow
#############################

const python_package = use_gpu ? "tensorflow-gpu" : "tensorflow"
# Installing tensorflow-gpu via conda should install cuda and cudnn too; thanks to Conda's dependancy management


if PyCall.conda
Conda.add(python_package * "=" * cur_version)
else
try
pyimport("tensorflow")
# See if it works already
catch ee
typeof(ee) <: PyCall.PyError || rethrow(ee)
error("""
Python TensorFlow not installed
Please either:
- Rebuild PyCall to use Conda, by running in the julia REPL:
- `ENV["PYTHON"]=""; Pkg.build("PyCall"); Pkg.build("TensorFlow")`
- Or install the python binding yourself, eg by running pip
- `pip install $(python_package)`
- then rebuilding TensorFlow.jl via `Pkg.build("TensorFlow")` in the julia REPL
""")
end
end


############################
# Install libtensorflow
############################

base = dirname(@__FILE__)
download_dir = joinpath(base, "downloads")
Expand All @@ -11,17 +55,14 @@ if !isdir(bin_dir)
run(`mkdir -p $bin_dir`)
end

# When TensorFlow 1.1 is released, use the official release binaries
# of the TensorFlow C library. Do this by setting cur_version to 1.1.0
# and then replacing the blocks below with:
#=

function download_and_unpack(url)
tensorflow_zip_path = joinpath(base, "downloads/tensorflow.zip")
# Download
download(url, tensorflow_zip_path)
# Unpack
try
run(`tar -xvzf $(tensorflow_zip_path) --strip-components=2 ./lib/libtensorflow.so`)
run(`unzip -o $(tensorflow_zip_path)`)
catch err
if !isfile(joinpath(base, "libtensorflow_c.so"))
throw(err)
Expand All @@ -31,41 +72,36 @@ function download_and_unpack(url)
end
end


@static if is_apple()
if "TF_USE_GPU" ∈ keys(ENV) && ENV["TF_USE_GPU"] == "1"
info("Building TensorFlow.jl for use on the GPU")
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-darwin-x86_64-$cur_version.tar.gz"
else
info("Building TensorFlow.jl for CPU use only. To enable the GPU, set the TF_USE_GPU environment variable to 1 and rebuild TensorFlow.jl")
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-$cur_version.tar.gz"
end
download_and_unpack(url)
download_and_unpack("https://storage.googleapis.com/malmaud-stuff/tensorflow_mac_$cur_version.zip")
mv("libtensorflow.so", "usr/bin/libtensorflow.dylib", remove_destination=true)
end

@static if is_linux()
if "TF_USE_GPU" ∈ keys(ENV) && ENV["TF_USE_GPU"] == "1"
info("Building TensorFlow.jl for use on the GPU")
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-$cur_version.tar.gz"
if use_gpu
url = "https://storage.googleapis.com/malmaud-stuff/tensorflow_linux_$cur_version.zip"
else
info("Building TensorFlow.jl for CPU use only. To enable the GPU, set the TF_USE_GPU environment variable to 1 and rebuild TensorFlow.jl")
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-$cur_version.tar.gz"
url = "https://storage.googleapis.com/malmaud-stuff/tensorflow_linux_cpu_$cur_version.zip"
end
download_and_unpack(url)
mv("libtensorflow.so", "usr/bin/libtensorflow.so", remove_destination=true)
end
=#

const cur_version = "1.1.0"


# When TensorFlow issue #8669 is closed and a new version is released, use the official release binaries
# of the TensorFlow C library.
# see https://github.com/tensorflow/tensorflow/issues/8669
# and then replacing the blocks above in this section below with:
#=
function download_and_unpack(url)
tensorflow_zip_path = joinpath(base, "downloads/tensorflow.zip")
# Download
download(url, tensorflow_zip_path)
# Unpack
try
run(`unzip -o $(tensorflow_zip_path)`)
run(`tar -xvzf $(tensorflow_zip_path) --strip-components=2 ./lib/libtensorflow.so`)
catch err
if !isfile(joinpath(base, "libtensorflow_c.so"))
throw(err)
Expand All @@ -75,20 +111,25 @@ function download_and_unpack(url)
end
end

@static if is_apple()
download_and_unpack("https://storage.googleapis.com/malmaud-stuff/tensorflow_mac_$cur_version.zip")
if use_gpu
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-darwin-x86_64-$cur_version.tar.gz"
else
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-$cur_version.tar.gz"
end
download_and_unpack(url)
mv("libtensorflow.so", "usr/bin/libtensorflow.dylib", remove_destination=true)
end
@static if is_linux()
if "TF_USE_GPU" keys(ENV) && ENV["TF_USE_GPU"] == "1"
info("Building TensorFlow.jl for use on the GPU")
url = "https://storage.googleapis.com/malmaud-stuff/tensorflow_linux_$cur_version.zip"
if use_gpu
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-$cur_version.tar.gz"
else
info("Building TensorFlow.jl for CPU use only. To enable the GPU, set the TF_USE_GPU environment variable to 1 and rebuild TensorFlow.jl")
url = "https://storage.googleapis.com/malmaud-stuff/tensorflow_linux_cpu_$cur_version.zip"
url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-$cur_version.tar.gz"
end
download_and_unpack(url)
mv("libtensorflow.so", "usr/bin/libtensorflow.so", remove_destination=true)
end
=#


21 changes: 0 additions & 21 deletions deps/build_pytensorflow.jl

This file was deleted.

0 comments on commit 34802b0

Please sign in to comment.