Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
feat(packages): Support exla package in livebook_bumblebee on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
shanesveller committed Mar 7, 2024
1 parent 4a9687b commit a53ab3f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
23 changes: 23 additions & 0 deletions dev/notebooks/exla-test.livemd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# EXLA Compiler test

```elixir
Mix.install(
[
{:exla, "~> 0.7.1"},
{:nx, "~> 0.7.1"}
],
config: [nx: [default_backend: EXLA.Backend]]
)
```

## Section

```elixir
defmodule NxExlaTest do
import Nx.Defn

defn(softmax(t), do: Nx.exp(t) / Nx.sum(Nx.exp(t)))
end

Nx.Defn.jit_apply(&NxExlaTest.softmax/1, [Nx.tensor([1, 2, 3])], compiler: EXLA)
```
41 changes: 31 additions & 10 deletions local-parts/packages/livebook.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,38 @@
meta.mainProgram = "livebook";
};

livebook_bumblebee = pkgs.symlinkJoin {
name = "livebook-with-gcc";
paths = with pkgs; [cmake gcc gnumake config.packages.livebook];
buildInputs = [pkgs.makeWrapper];
postBuild = ''
wrapProgram $out/bin/livebook \
--prefix PATH : ${lib.makeBinPath (with pkgs; [cmake gcc gnumake])}
'';
livebook_bumblebee = let
# NOTE: MacOS EXLA build process apparently ignores the Nix-provided GCC
# for `clang++` from PATH
compiler =
if pkgs.stdenv.isLinux
then pkgs.gcc
else pkgs.clang;
inherit (pkgs.darwin.apple_sdk) frameworks;
# NOTE: Can't use lib.optionalString in tail position due to eval errors on Linux
frameworkFlags =
if pkgs.stdenv.isDarwin
then
lib.trivial.pipe [frameworks.Foundation]
[
(builtins.map (p: "-F${p}/Library/Frameworks"))
(builtins.concatStringsSep " ")
lib.escapeShellArg
]
else "";
in
pkgs.symlinkJoin {
name = "livebook-with-bumblee-compiler";
paths = [config.packages.livebook];
buildInputs = [pkgs.makeWrapper];
postBuild = ''
wrapProgram $out/bin/livebook \
--prefix NIX_LDFLAGS ' ' ${frameworkFlags} \
--prefix PATH : ${lib.makeBinPath (with pkgs; [cmake compiler gnumake])}
'';

meta.mainProgram = "livebook";
};
meta.mainProgram = "livebook";
};
};
};
}

0 comments on commit a53ab3f

Please sign in to comment.