diff --git a/ci/docker/runtime_functions.sh b/ci/docker/runtime_functions.sh index d2b0d6b0e274..6ca00c2accbf 100755 --- a/ci/docker/runtime_functions.sh +++ b/ci/docker/runtime_functions.sh @@ -1052,7 +1052,7 @@ unittest_ubuntu_gpu_R() { unittest_ubuntu_cpu_julia() { set -ex export PATH="$1/bin:$PATH" - export MXNET_HOME='/work/mxnet' + export MXNET_ROOT='/work/mxnet' export JULIA_DEPOT_PATH='/work/julia-depot' export INTEGRATION_TEST=1 @@ -1062,7 +1062,7 @@ unittest_ubuntu_cpu_julia() { export LD_PRELOAD='/usr/lib/x86_64-linux-gnu/libjemalloc.so' export LD_LIBRARY_PATH=/work/mxnet/lib:$LD_LIBRARY_PATH - # use the prebuilt binary from $MXNET_HOME/lib + # use the prebuilt binary from $MXNET_ROOT/lib julia --project=./julia -e 'using Pkg; Pkg.build("MXNet")' # run the script `julia/test/runtests.jl` @@ -1213,7 +1213,7 @@ build_docs() { # Setup environment for Julia docs export PATH="/work/julia10/bin:$PATH" - export MXNET_HOME='/work/mxnet' + export MXNET_ROOT='/work/mxnet' export JULIA_DEPOT_PATH='/work/julia-depot' julia -e 'using InteractiveUtils; versioninfo()' @@ -1425,7 +1425,7 @@ deploy_docs() { # Setup for Julia docs export PATH="/work/julia10/bin:$PATH" - export MXNET_HOME='/work/mxnet' + export MXNET_ROOT='/work/mxnet' export JULIA_DEPOT_PATH='/work/julia-depot' julia -e 'using InteractiveUtils; versioninfo()' diff --git a/ci/windows/test_jl07_cpu.ps1 b/ci/windows/test_jl07_cpu.ps1 index 6cd34ef209de..d3b77b1cbc1d 100644 --- a/ci/windows/test_jl07_cpu.ps1 +++ b/ci/windows/test_jl07_cpu.ps1 @@ -20,7 +20,7 @@ # set default output encoding to utf8 $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8' -$env:MXNET_HOME = [System.IO.Path]::GetFullPath('.\windows_package') +$env:MXNET_ROOT = [System.IO.Path]::GetFullPath('.\windows_package') $env:JULIA_URL = "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7.0-win64.exe" $env:JULIA_DEPOT_PATH = [System.IO.Path]::GetFullPath('.\julia-depot') diff --git a/ci/windows/test_jl10_cpu.ps1 b/ci/windows/test_jl10_cpu.ps1 index 96c419066354..2dbda4886c42 100644 --- a/ci/windows/test_jl10_cpu.ps1 +++ b/ci/windows/test_jl10_cpu.ps1 @@ -20,7 +20,7 @@ # set default output encoding to utf8 $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8' -$env:MXNET_HOME = [System.IO.Path]::GetFullPath('.\windows_package') +$env:MXNET_ROOT = [System.IO.Path]::GetFullPath('.\windows_package') $env:JULIA_URL = "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0.3-win64.exe" $env:JULIA_DEPOT_PATH = [System.IO.Path]::GetFullPath('.\julia-depot') diff --git a/julia/deps/build.jl b/julia/deps/build.jl index badca65be577..fd18e10351fd 100644 --- a/julia/deps/build.jl +++ b/julia/deps/build.jl @@ -26,14 +26,27 @@ libmxnet_detected = false libmxnet_curr_ver = get(ENV, "MXNET_COMMIT", "master") curr_win = "20180211" # v1.1.0 -if haskey(ENV, "MXNET_HOME") - MXNET_HOME = ENV["MXNET_HOME"] - @info("MXNET_HOME environment detected: $MXNET_HOME") +MXNET_ROOT = get(ENV, "MXNET_ROOT", "") +search_locations = if !isempty(MXNET_ROOT) + @info "env var: MXNET_ROOT -> $MXNET_ROOT" + [joinpath(MXNET_ROOT, "lib"), MXNET_ROOT] +else + [] +end + +MXNET_LIBRARY_PATH = get(ENV, "MXNET_LIBRARY_PATH", "") +println(typeof(MXNET_LIBRARY_PATH)) +# In case of macOS, if user build libmxnet from source and set the MXNET_ROOT, +# the output is still named as `libmxnet.so`. +search_names = ["libmxnet.$(Libdl.dlext)", "libmxnet.so"] +if !isempty(MXNET_LIBRARY_PATH) + @info "env var: MXNET_LIBRARY_PATH -> $MXNET_LIBRARY_PATH" + pushfirst!(search_names, MXNET_LIBRARY_PATH) +end + +if (!isempty(MXNET_ROOT)) || (!isempty(MXNET_LIBRARY_PATH)) @info("Trying to load existing libmxnet...") - # In case of macOS, if user build libmxnet from source and set the MXNET_HOME, - # the output is still named as `libmxnet.so`. - lib = Libdl.find_library(["libmxnet.$(Libdl.dlext)", "libmxnet.so"], - [joinpath(MXNET_HOME, "lib"), MXNET_HOME]) + lib = Libdl.find_library(search_names, search_locations) if !isempty(lib) @info("Existing libmxnet detected at $lib, skip building...") libmxnet_detected = true diff --git a/julia/src/base.jl b/julia/src/base.jl index 683146402620..f9ec32dcb93b 100644 --- a/julia/src/base.jl +++ b/julia/src/base.jl @@ -47,9 +47,16 @@ const grad_req_map = Dict{Symbol,GRAD_REQ}( ################################################################################ # Initialization and library API entrance ################################################################################ -const MXNET_LIB = Libdl.find_library(["libmxnet.$(Libdl.dlext)", "libmxnet.so"], # see build.jl - [joinpath(get(ENV, "MXNET_HOME", ""), "lib"), - get(ENV, "MXNET_HOME", ""), +function _get_search_names() + MXNET_LIBRARY_PATH = get(ENV, "MXNET_LIBRARY_PATH", "") + A = ["libmxnet.$(Libdl.dlext)", "libmxnet.so"] # see build.jl + !isempty(MXNET_LIBRARY_PATH) && pushfirst!(A, MXNET_LIBRARY_PATH) + A +end + +const MXNET_LIB = Libdl.find_library(_get_search_names(), + [joinpath(get(ENV, "MXNET_ROOT", ""), "lib"), + get(ENV, "MXNET_ROOT", ""), joinpath(@__DIR__, "..", "deps", "usr", "lib")]) const LIB_VERSION = Ref{Cint}(0)