Skip to content

Commit 417aeb3

Browse files
authored
Merge pull request #25 from gregszumel/ort_upgrade
upgrading to ort 2.0.0-rc.0, onnxruntime 1.17
2 parents 1495fec + d00092f commit 417aeb3

File tree

8 files changed

+460
-389
lines changed

8 files changed

+460
-389
lines changed

lib/ortex/util.ex

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
defmodule Ortex.Util do
22
@moduledoc false
3+
@doc """
4+
Copies the libraries downloaded during the ORT build into a path that
5+
Elixir can use
6+
"""
37
def copy_ort_libs() do
48
build_root = Path.absname(:code.priv_dir(:ortex)) |> Path.dirname()
59

@@ -9,46 +13,38 @@ defmodule Ortex.Util do
913
_ -> "debug"
1014
end
1115

12-
case :os.type() do
13-
{:win32, _} ->
14-
Path.wildcard(
15-
Path.join([
16-
build_root,
17-
"native/ortex",
18-
rust_env,
19-
"libonnxruntime*.dll*"
20-
])
21-
)
16+
# where the libonnxruntime files are stored
17+
rust_path = Path.join([build_root, "native/ortex", rust_env])
2218

23-
{:unix, :darwin} ->
24-
Path.wildcard(
25-
Path.join([
26-
build_root,
27-
"native/ortex",
28-
rust_env,
29-
"libonnxruntime*.dylib*"
30-
])
31-
)
19+
onnx_runtime_paths =
20+
case :os.type() do
21+
{:win32, _} -> Path.join([rust_path, "libonnxruntime*.dll*"])
22+
{:unix, :darwin} -> Path.join([rust_path, "libonnxruntime*.dylib*"])
23+
{:unix, _} -> Path.join([rust_path, "libonnxruntime*.so*"])
24+
end
25+
|> Path.wildcard()
3226

33-
{:unix, _} ->
34-
Path.wildcard(
35-
Path.join([
36-
build_root,
37-
"native/ortex",
38-
rust_env,
39-
"libonnxruntime*.so*"
40-
])
41-
)
42-
end
27+
# where we need to copy the paths
28+
destination_dir = Path.join([:code.priv_dir(:ortex), "native"])
29+
30+
onnx_runtime_paths
4331
|> Enum.map(fn x ->
44-
File.cp!(
45-
x,
46-
Path.join([
47-
:code.priv_dir(:ortex),
48-
"native",
49-
Path.basename(x)
50-
])
51-
)
32+
File.cp!(x, Path.join([destination_dir, Path.basename(x)]))
5233
end)
34+
35+
# Currently ORT doesn't write the .so file we need (fix incoming https://github.com/pykeio/ort/commit/634e49ab7c960782cc2fb83d84cc219e7bb4ae1f),
36+
# so we're hacking a fix here
37+
onnx_runtime_filenames = Enum.map(onnx_runtime_paths, &Path.basename/1)
38+
39+
case "libonnxruntime.so.1.17.0" in onnx_runtime_filenames do
40+
true ->
41+
nil
42+
43+
false ->
44+
File.cp!(
45+
Path.join([destination_dir, "libonnxruntime.so"]),
46+
Path.join([destination_dir, "libonnxruntime.so.1.17.0"])
47+
)
48+
end
5349
end
5450
end

0 commit comments

Comments
 (0)