Skip to content

Commit

Permalink
Allow jitted functions to work across nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Sep 2, 2024
1 parent fb2d4b3 commit ab82611
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions exla/lib/exla/executable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ defmodule EXLA.Executable do

@doc """
Runs the given executable with a list of lists as inputs and the given options.
Works across nodes.
"""
def run(%Executable{} = executable, [subinputs | _] = inputs, options \\ [])
def run(executable, inputs, options \\ [])

def run(%Executable{ref: ref, client: client} = executable, inputs, options)
when node(ref) != node() do
client
|> load(dump(executable))
|> run(inputs, options)
end

def run(%Executable{} = executable, [subinputs | _] = inputs, options)
when is_list(subinputs) do
%{client: client, device_id: device_id, output_typespecs: output_typespecs, ref: ref} =
executable
Expand All @@ -25,17 +36,20 @@ defmodule EXLA.Executable do
@doc """
Dumps the executable to a data structure that can be serialized
with `term_to_binary`.
Works across nodes.
"""
# If you change this function, you must bump the version in EXLA.Defn.Disk.
def dump(%Executable{
ref: executable,
ref: ref,
output_typespecs: output_typespecs,
num_replicas: num_replicas,
num_partitions: num_partitions,
device_id: device_id
}) do
})
when node(ref) == node() do
serialized_exec =
executable
ref
|> EXLA.NIF.serialize_executable()
|> unwrap!()
|> IO.iodata_to_binary()
Expand All @@ -49,6 +63,10 @@ defmodule EXLA.Executable do
}
end

def dump(%Executable{ref: ref} = executable) do
:erpc.call(node(ref), __MODULE__, :dump, [executable])
end

@doc """
Loads a previously dumped executable.
"""
Expand Down

0 comments on commit ab82611

Please sign in to comment.