Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 75ee1e9

Browse files
authored
julia: rename build env var MXNET_HOME to MXNET_ROOT (#15568)
* julia: rename build env var `MXNET_HOME` to `MXNET_ROOT` - Add MXNET_LIBRARY_PATH support Ref: #15561 * backward compatibility
1 parent 27a9782 commit 75ee1e9

File tree

7 files changed

+77
-25
lines changed

7 files changed

+77
-25
lines changed

ci/docker/runtime_functions.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ unittest_ubuntu_gpu_R() {
10881088
unittest_ubuntu_cpu_julia() {
10891089
set -ex
10901090
export PATH="$1/bin:$PATH"
1091-
export MXNET_HOME='/work/mxnet'
1091+
export MXNET_ROOT='/work/mxnet'
10921092
export JULIA_DEPOT_PATH='/work/julia-depot'
10931093
export INTEGRATION_TEST=1
10941094

@@ -1098,7 +1098,7 @@ unittest_ubuntu_cpu_julia() {
10981098
export LD_PRELOAD='/usr/lib/x86_64-linux-gnu/libjemalloc.so'
10991099
export LD_LIBRARY_PATH=/work/mxnet/lib:$LD_LIBRARY_PATH
11001100

1101-
# use the prebuilt binary from $MXNET_HOME/lib
1101+
# use the prebuilt binary from $MXNET_ROOT/lib
11021102
julia --project=./julia -e 'using Pkg; Pkg.build("MXNet")'
11031103

11041104
# run the script `julia/test/runtests.jl`
@@ -1253,7 +1253,7 @@ build_docs() {
12531253

12541254
# Setup environment for Julia docs
12551255
export PATH="/work/julia10/bin:$PATH"
1256-
export MXNET_HOME='/work/mxnet'
1256+
export MXNET_ROOT='/work/mxnet'
12571257
export JULIA_DEPOT_PATH='/work/julia-depot'
12581258

12591259
julia -e 'using InteractiveUtils; versioninfo()'
@@ -1465,7 +1465,7 @@ deploy_docs() {
14651465

14661466
# Setup for Julia docs
14671467
export PATH="/work/julia10/bin:$PATH"
1468-
export MXNET_HOME='/work/mxnet'
1468+
export MXNET_ROOT='/work/mxnet'
14691469
export JULIA_DEPOT_PATH='/work/julia-depot'
14701470

14711471
julia -e 'using InteractiveUtils; versioninfo()'

ci/windows/test_jl07_cpu.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# set default output encoding to utf8
2121
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
2222

23-
$env:MXNET_HOME = [System.IO.Path]::GetFullPath('.\windows_package')
23+
$env:MXNET_ROOT = [System.IO.Path]::GetFullPath('.\windows_package')
2424
$env:JULIA_URL = "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7.0-win64.exe"
2525
$env:JULIA_DEPOT_PATH = [System.IO.Path]::GetFullPath('.\julia-depot')
2626

ci/windows/test_jl10_cpu.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# set default output encoding to utf8
2121
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
2222

23-
$env:MXNET_HOME = [System.IO.Path]::GetFullPath('.\windows_package')
23+
$env:MXNET_ROOT = [System.IO.Path]::GetFullPath('.\windows_package')
2424
$env:JULIA_URL = "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0.3-win64.exe"
2525
$env:JULIA_DEPOT_PATH = [System.IO.Path]::GetFullPath('.\julia-depot')
2626

julia/NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
# v1.6.0
1919

20+
* Rename environment variable `MXNET_HOME` to `MXNET_ROOT` (#15568).
21+
22+
* Environment variable `MXNET_LIBRARY_PATH` supports (#15568).
23+
24+
```shell
25+
$ MXNET_LIBRARY_PATH=/path/to/libmxnet.so julia
26+
```
2027

2128
# v1.5.0
2229

julia/deps/build.jl

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,35 @@ libmxnet_detected = false
2626
libmxnet_curr_ver = get(ENV, "MXNET_COMMIT", "master")
2727
curr_win = "20190608" # v1.5.0
2828

29+
# TODO: remove MXNET_HOME backward compatibility in v1.7
2930
if haskey(ENV, "MXNET_HOME")
30-
MXNET_HOME = ENV["MXNET_HOME"]
31-
@info("MXNET_HOME environment detected: $MXNET_HOME")
31+
@warn "The environment variable `MXNET_HOME` has been renamed, please use `MXNET_ROOT` instead."
32+
end
33+
34+
# TODO: remove MXNET_HOME backward compatibility in v2.0
35+
MXNET_ROOT = get(ENV, "MXNET_ROOT", get(ENV, "MXNET_HOME", ""))
36+
search_locations = if !isempty(MXNET_ROOT)
37+
!isabspath(MXNET_ROOT) && error("MXNET_ROOT should be a absolute path")
38+
@info "env var: MXNET_ROOT -> $MXNET_ROOT"
39+
[joinpath(MXNET_ROOT, "lib"), MXNET_ROOT]
40+
else
41+
[]
42+
end
43+
44+
MXNET_LIBRARY_PATH = get(ENV, "MXNET_LIBRARY_PATH", "")
45+
println(typeof(MXNET_LIBRARY_PATH))
46+
# In case of macOS, if user build libmxnet from source and set the MXNET_ROOT,
47+
# the output is still named as `libmxnet.so`.
48+
search_names = ["libmxnet.$(Libdl.dlext)", "libmxnet.so"]
49+
if !isempty(MXNET_LIBRARY_PATH)
50+
!isabspath(MXNET_LIBRARY_PATH) && error("MXNET_LIBRARY_PATH should be a absolute path")
51+
@info "env var: MXNET_LIBRARY_PATH -> $MXNET_LIBRARY_PATH"
52+
pushfirst!(search_names, MXNET_LIBRARY_PATH)
53+
end
54+
55+
if (!isempty(MXNET_ROOT)) || (!isempty(MXNET_LIBRARY_PATH))
3256
@info("Trying to load existing libmxnet...")
33-
# In case of macOS, if user build libmxnet from source and set the MXNET_HOME,
34-
# the output is still named as `libmxnet.so`.
35-
lib = Libdl.find_library(["libmxnet.$(Libdl.dlext)", "libmxnet.so"],
36-
[joinpath(MXNET_HOME, "lib"), MXNET_HOME])
57+
lib = Libdl.find_library(search_names, search_locations)
3758
if !isempty(lib)
3859
@info("Existing libmxnet detected at $lib, skip building...")
3960
libmxnet_detected = true

julia/docs/src/user-guide/install.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ libmxnet.
4040

4141
There are several environment variables that change this behaviour.
4242

43-
- `MXNET_HOME`: If you already have a pre-installed version of mxnet
44-
you can use `MXNET_HOME` to point the build-process in the right direction.
45-
- `CUDA_HOME`: If the automatic cuda detection fails you can also set `CUDA_HOME`
43+
- `MXNET_ROOT`: If you already have a pre-installed version of mxnet
44+
you can use `MXNET_ROOT` to point the build-process in the right direction.
45+
Note that you should set this variable as a absolute path.
46+
- `MXNET_HOME`: This variable is replaced by `MXNET_ROOT`. It has been renamed
47+
as of v1.6.
48+
- `MXNET_LIBRARY_PATH`: The absolute path of the libmxnet share object.
49+
- `CUDA_HOME`: If the automatic CUDA detection fails you can also set `CUDA_HOME`
4650
to override the process.
4751
- `MXNET_COMMIT`: To control which version of libmxnet will be compiled,
4852
you can use the`MXNET_COMMIT` variable to point to either a version tag
@@ -80,26 +84,26 @@ to work with a separate, maybe customized libmxnet.
8084

8185
To build libmxnet, please refer to [the installation guide of
8286
libmxnet](https://mxnet.incubator.apache.org/install/index.html). After
83-
successfully installing libmxnet, set the `MXNET_HOME` *environment
87+
successfully installing libmxnet, set the `MXNET_ROOT` *environment
8488
variable* to the location of libmxnet. In other words, the compiled
85-
`libmxnet.so` should be found in `$MXNET_HOME/lib`.
89+
`libmxnet.so` should be found in `$MXNET_ROOT/lib`.
8690

8791
> **note**
8892
>
89-
> The constant `MXNET_HOME` is pre-compiled in MXNet.jl package cache.
93+
> The constant `MXNET_ROOT` is pre-compiled in MXNet.jl package cache.
9094
> If you updated the environment variable after installing MXNet.jl,
9195
> make sure to update the pre-compilation cache by
9296
> `Base.compilecache("MXNet")`.
9397
94-
When the `MXNET_HOME` environment variable is detected and the
98+
When the `MXNET_ROOT` environment variable is detected and the
9599
corresponding `libmxnet.so` could be loaded successfully, MXNet.jl will
96100
skip automatic building during installation and use the specified
97101
libmxnet instead.
98102

99103
Basically, MXNet.jl will search `libmxnet.so` or `libmxnet.dll` in the
100104
following paths (and in that order):
101105

102-
- `$MXNET_HOME/lib`: customized libmxnet builds
106+
- `$MXNET_ROOT/lib`: customized libmxnet builds
103107
- `Pkg.dir("MXNet", "deps", "usr", "lib")`: automatic builds
104108
- Any system wide library search path
105109

julia/src/base.jl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,31 @@ const grad_req_map = Dict{Symbol,GRAD_REQ}(
4747
################################################################################
4848
# Initialization and library API entrance
4949
################################################################################
50-
const MXNET_LIB = Libdl.find_library(["libmxnet.$(Libdl.dlext)", "libmxnet.so"], # see build.jl
51-
[joinpath(get(ENV, "MXNET_HOME", ""), "lib"),
52-
get(ENV, "MXNET_HOME", ""),
53-
joinpath(@__DIR__, "..",
54-
"deps", "usr", "lib")])
50+
function _get_search_names()
51+
MXNET_LIBRARY_PATH = get(ENV, "MXNET_LIBRARY_PATH", "")
52+
A = ["libmxnet.$(Libdl.dlext)", "libmxnet.so"] # see build.jl
53+
if !isempty(MXNET_LIBRARY_PATH)
54+
!isabspath(MXNET_LIBRARY_PATH) && error("MXNET_LIBRARY_PATH should be a absolute path")
55+
pushfirst!(A, MXNET_LIBRARY_PATH)
56+
end
57+
A
58+
end
59+
60+
function _get_search_dirs()
61+
# TODO: remove MXNET_HOME backward compatibility in v1.7
62+
if haskey(ENV, "MXNET_HOME")
63+
@warn "The environment variable `MXNET_HOME` has been renamed, please use `MXNET_ROOT` instead."
64+
end
65+
A = [joinpath(@__DIR__, "..", "deps", "usr", "lib")]
66+
MXNET_ROOT = get(ENV, "MXNET_ROOT", get(ENV, "MXNET_HOME", ""))
67+
if !isempty(MXNET_ROOT)
68+
!isabspath(MXNET_ROOT) && error("MXNET_ROOT should be a absolute path")
69+
prepend!(A, [joinpath(MXNET_ROOT, "lib"), MXNET_ROOT])
70+
end
71+
A
72+
end
73+
74+
const MXNET_LIB = Libdl.find_library(_get_search_names(), _get_search_dirs())
5575
const LIB_VERSION = Ref{Cint}(0)
5676

5777
if isempty(MXNET_LIB)

0 commit comments

Comments
 (0)