Skip to content

Commit

Permalink
change gpu install pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
kailaix committed Oct 25, 2019
1 parent cf2d9d4 commit ca57c1e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 55 deletions.
45 changes: 0 additions & 45 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ for pkg in ["zip", "unzip", "make", "cmake", "tensorflow=$tf_ver", "tensorflow-p
Conda.add(pkg)
end

if Sys.islinux() && haskey(ENV, "GPU") && !("tensorflow-gpu" in pkgs)
@info "Add tensorflow-gpu"
# Conda.add("tensorflow-gpu=$tf_ver")
run(`$PIP install tensorflow-gpu==$tf_ver`)
end

@info "Fix libtensorflow_framework.so..."
if haskey(ENV, "LD_LIBRARY_PATH")
run(setenv(`$PYTHON build.py`, "LD_LIBRARY_PATH"=>ENV["LD_LIBRARY_PATH"]*":$(Conda.LIBDIR)"))
Expand All @@ -56,49 +50,10 @@ function install_custom_op_dependency()
run(`$UNZIP $LIBDIR/eigen.zip`)
mv("eigen-eigen-323c052e1731", "$LIBDIR/eigen3", force=true)
end

# Install Torch library
#=
if Sys.isapple()
if !isfile("$LIBDIR/libtorch.zip")
download("https://download.pytorch.org/libtorch/cpu/libtorch-macos-latest.zip","$LIBDIR/libtorch.zip")
end
if !isdir("$LIBDIR/libtorch")
run(`$UNZIP $LIBDIR/libtorch.zip`)
mv("libtorch", "$LIBDIR/libtorch", force=true)
if !isdir("$LIBDIR/libtorch/lib/")
mkdir("$LIBDIR/libtorch/lib/")
end
download("https://github.com/intel/mkl-dnn/releases/download/v0.19/mklml_mac_2019.0.5.20190502.tgz","$LIBDIR/mklml_mac_2019.0.5.20190502.tgz")
run(`tar -xvzf $LIBDIR/mklml_mac_2019.0.5.20190502.tgz`)
mv("mklml_mac_2019.0.5.20190502/lib/libiomp5.dylib","$LIBDIR/libtorch/lib/libiomp5.dylib", force=true)
mv("mklml_mac_2019.0.5.20190502/lib/libmklml.dylib","$LIBDIR/libtorch/lib/libmklml.dylib", force=true)
rm("mklml_mac_2019.0.5.20190502/", force=true, recursive=true)
end
elseif Sys.islinux()
if !isfile("$LIBDIR/libtorch.zip")
download("https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-latest.zip","$LIBDIR/libtorch.zip")
end
if !isdir("$LIBDIR/libtorch")
run(`$UNZIP $LIBDIR/libtorch.zip`)
mv("libtorch", "$LIBDIR/libtorch")
if !isdir("$LIBDIR/libtorch/lib/")
mkdir("$LIBDIR/libtorch/lib/")
end
download("https://github.com/intel/mkl-dnn/releases/download/v0.19/mklml_lnx_2019.0.5.20190502.tgz","$LIBDIR/mklml_lnx_2019.0.5.20190502.tgz")
run(`tar -xvzf $LIBDIR/mklml_lnx_2019.0.5.20190502.tgz`)
mv("mklml_lnx_2019.0.5.20190502/lib/libiomp5.so", "$LIBDIR/libtorch/lib/libiomp5.so", force=true)
mv("mklml_lnx_2019.0.5.20190502/lib/libmklml_gnu.so", "$LIBDIR/libtorch/lib/libmklml_gnu.so", force=true)
mv("mklml_lnx_2019.0.5.20190502/lib/libmklml_intel.so", "$LIBDIR/libtorch/lib/libmklml_intel.so", force=true)
rm("mklml_lnx_2019.0.5.20190502/", force=true, recursive=true)
end
end
=#
end

install_custom_op_dependency()


# useful command for debug
# readelf -p .comment libtensorflow_framework.so
# strings libstdc++.so.6 | grep GLIBCXX
Expand Down
6 changes: 4 additions & 2 deletions docs/src/customop.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ It should gives you the location of `nvcc` compiler.
For quick installation, you can try
```julia
using ADCME
ADCME.install_gpu_dependencies()
enable_gpu()
```

This function basically implements the following steps
#### Manual Installation

In case

- To install CUDA toolkit (if you do not have one), you can install via conda
```julia
Expand Down
38 changes: 30 additions & 8 deletions src/extra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ xavier_init,
load_op_and_grad,
load_op,
compile_op,
test_custom_op
test_custom_op,
enable_gpu

"""
xavier_init(size, dtype=Float64)
Expand Down Expand Up @@ -251,14 +252,14 @@ function test_custom_op()
true
end

function install_gpu_dependencies()
Conda.add("cudatoolkit", channel="anaconda")
function enable_gpu()
pkgs = Conda._installed_packages()

if !("tensorflow-gpu" in Conda._installed_packages())
if !("tensorflow-gpu" in pkgs)
Conda.add("tensorflow-gpu=1.14")
end

if !("cudatoolkit" in Conda._installed_packages())
if !("cudatoolkit" in pkgs)
Conda.add("cudatoolkit", channel="anaconda")
end

Expand All @@ -272,12 +273,33 @@ function install_gpu_dependencies()
end
incpath = joinpath(splitdir(strip(read(`which nvcc`, String)))[1], "../include/")
if !isdir(joinpath(gpus, "include"))
mv(incpath, gpus)
cp(incpath, joinpath(gpus, "include"))
end

pth = joinpath(Conda.ROOTENV, "pkgs/cudatoolkit-10.1.168-0/lib/")
# compatible
files = readdir(pth)
for f in files
if f[end-2:end]==".10" && !isfile(joinpath(pth, f*".0"))
symlink(joinpath(pth, f), joinpath(pth, f*".0"))
end
if f[end-4:end]==".10.1" && !isfile(joinpath(pth, f[1:end-2]*".0"))
symlink(joinpath(pth, f), joinpath(pth, f[1:end-2]*".0"))
end
end

println("Run the following command in shell
export LD_LIBRARY_PATH=$pth:\$LD_LIBRARY_PATH >> ~/.bashrc")
end
echo 'export LD_LIBRARY_PATH=$pth:\$LD_LIBRARY_PATH' >> ~/.bashrc")
end

function use_gpu(i::Union{Nothing,Int64}=nothing)
if isnothing(i)
return
end
i = join(collect(0:i-1),',')
ENV["CUDA_VISIBLE_DEVICES"] = i
dl = pyimport("tensorflow.python.client.device_lib")
return dl.list_local_devices()
end

2 comments on commit ca57c1e

@kailaix
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/4412

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" ca57c1e49864ba19f91ea7883cacaa00c93aec05
git push origin v0.3.1

Please sign in to comment.