elixir-nx / ortex

ONNX Runtime bindings for Elixir
MIT License
134 stars 16 forks source link

Building on macOS M2 #1

Closed JesseStimpson closed 1 year ago

JesseStimpson commented 1 year ago
   Compiling ort v1.14.6
The following warnings were emitted during compilation:

warning: Provider not available for this strategy and/or target: CUDA
warning: Provider not available for this strategy and/or target: TENSORRT
warning: Provider not available for this strategy and/or target: CUDA
warning: Provider not available for this strategy and/or target: TENSORRT
warning: Provider not available for this strategy and/or target: CUDA
warning: Provider not available for this strategy and/or target: TENSORRT

error: failed to run custom build command for `ort v1.14.6`

Caused by:
  process didn't exit successfully: `/Users/jstimpson/dev/elixir/ortex/_build/dev/lib/ortex/native/ortex/debug/build/ort-c81d1256a1916c1c/build-script-build` (exit status: 101)
  --- stdout
  [ort] strategy: "unknown"
  cargo:warning=Provider not available for this strategy and/or target: CUDA
  cargo:warning=Provider not available for this strategy and/or target: TENSORRT
  cargo:warning=Provider not available for this strategy and/or target: CUDA
  cargo:warning=Provider not available for this strategy and/or target: TENSORRT
  cargo:rerun-if-env-changed=ORT_STRATEGY
  cargo:warning=Provider not available for this strategy and/or target: CUDA
  cargo:warning=Provider not available for this strategy and/or target: TENSORRT

  --- stderr
  thread 'main' panicked at 'Microsoft does not provide ONNX Runtime downloads for triplet: osx-arm64-gpu; you may have to use the `system` strategy instead', /Users/jstimpson/.asdf/installs/rust/1.69.0/registry/src/github.com-1ecc6299db9ec823/ort-1.14.6/build.rs:164:18
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

== Compilation error in file lib/ortex/native.ex ==
** (RuntimeError) Rust NIF compile error (rustc exit code 101)
    (rustler 0.26.0) lib/rustler/compiler.ex:41: Rustler.Compiler.compile_crate/2
    lib/ortex/native.ex:7: (module)

Workaround

index 635c517..c349099 100644
--- a/native/ortex/Cargo.toml
+++ b/native/ortex/Cargo.toml
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]

 [dependencies]
 rustler = "0.26.0"
-ort = {version = "1.14.6", features = ["cuda", "tensorrt"]}
+ort = {version = "1.14.6", features = []}
 ndarray = "0.15.6"
 half = "2.2.1"
 tracing-subscriber = { version = "0.3", features = [ "env-filter", "fmt" ] }
JesseStimpson commented 1 year ago

I also needed to add the loader_path of libortex.so to the rpath list. This could be addressed in a different way, but this is what got things working for me

install_name_tool -add_rpath @loader_path/. _build/test/lib/ortex/priv/native/libortex.so
mortont commented 1 year ago

Since ort requires the execution providers to be enabled by cargo features, I'll look into a way to make this dynamic depending on the host (MacOS vs Linux in this case). Also thanks for the catch on rpath, I'll make those changes.

mortont commented 1 year ago

These should be fixed in v0.1.1, let me know if you run into any other issues!