Skip to content

Commit d22a5e8

Browse files
Fix automatic legacy_cpu detection for polars rustler
Before: $ mix ecto.setup ==> explorer Compiling 29 files (.ex) 20:07:38.808 [debug] Copying NIF from cache and extracting to /home/nabijaczleweli/work/beambox-logbook/_build/dev/lib/explorer/priv/native/libexplorer-v0.10.1-nif-2.15-x86_64-unknown-linux-gnu.so.tar.gz Illegal instruction $ for f in fxsr sse sse2 ssse3 sse4_1 sse4_2 popcnt avx fma; do grep -m1 flags /proc/cpuinfo | grep -wq $f || echo no $f; done no avx no fma $ mix deps.get use_legacy: false is_nil(use_legacy): false needed_caps: ["fxsr", "sse", "sse2", "ssse3", "sse4_1", "sse4_2", "popcnt", "avx", "fma"] Explorer.ComptimeUtils.cpu_with_all_caps?(needed_caps): false use_legacy or (is_nil(use_legacy) and not Explorer.ComptimeUtils.cpu_with_all_caps?(needed_caps)): false After: $ mix ecto.setup ==> explorer Compiling 29 files (.ex) use_legacy: nil is_nil(use_legacy): true needed_caps: ["fxsr", "sse", "sse2", "ssse3", "sse4_1", "sse4_2", "popcnt", "avx", "fma"] Explorer.ComptimeUtils.cpu_with_all_caps?(needed_caps): false if is_nil(use_legacy), do: not Explorer.ComptimeUtils.cpu_with_all_caps?(needed_caps), else: use_legacy: true 20:32:03.923 [debug] Copying NIF from cache and extracting to /home/nabijaczleweli/work/beambox-logbook/_build/dev/lib/explorer/priv/native/libexplorer-v0.10.1-nif-2.15-x86_64-unknown-linux-gnu--legacy_cpu.so.tar.gz Sponsored-by: https://beaverlabs.net
1 parent 607ed7f commit d22a5e8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/explorer/polars_backend/native.ex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,27 @@ defmodule Explorer.PolarsBackend.Native do
88
# We want "debug" in dev and test because it's faster to compile.
99
mode = if Mix.env() in [:dev, :test], do: :debug, else: :release
1010

11-
use_legacy =
11+
use_legacy = (
12+
env = System.get_env("EXPLORER_USE_LEGACY_ARTIFACTS")
13+
1214
Application.compile_env(
1315
:explorer,
1416
:use_legacy_artifacts,
15-
System.get_env("EXPLORER_USE_LEGACY_ARTIFACTS") in ["true", "1"]
17+
(if is_nil(env), do: nil, else: env in ["true", "1"])
1618
)
19+
)
1720

1821
variants_for_linux = [
1922
legacy_cpu: fn ->
2023
# These are the same from the release workflow.
2124
# See the meaning in: https://unix.stackexchange.com/a/43540
2225
needed_caps = ~w[fxsr sse sse2 ssse3 sse4_1 sse4_2 popcnt avx fma]
2326

24-
use_legacy or
25-
(is_nil(use_legacy) and
26-
not Explorer.ComptimeUtils.cpu_with_all_caps?(needed_caps))
27+
if is_nil(use_legacy) do
28+
not Explorer.ComptimeUtils.cpu_with_all_caps?(needed_caps)
29+
else
30+
use_legacy
31+
end
2732
end
2833
]
2934

0 commit comments

Comments
 (0)