@@ -11,8 +11,19 @@ defmodule EXLA.Executable do
11
11
12
12
@ doc """
13
13
Runs the given executable with a list of lists as inputs and the given options.
14
+
15
+ Works across nodes.
14
16
"""
15
- def run ( % Executable { } = executable , [ subinputs | _ ] = inputs , options \\ [ ] )
17
+ def run ( executable , inputs , options \\ [ ] )
18
+
19
+ def run ( % Executable { ref: ref , client: client } = executable , inputs , options )
20
+ when node ( ref ) != node ( ) do
21
+ client
22
+ |> load ( dump ( executable ) )
23
+ |> run ( inputs , options )
24
+ end
25
+
26
+ def run ( % Executable { } = executable , [ subinputs | _ ] = inputs , options )
16
27
when is_list ( subinputs ) do
17
28
% { client: client , device_id: device_id , output_typespecs: output_typespecs , ref: ref } =
18
29
executable
@@ -25,17 +36,20 @@ defmodule EXLA.Executable do
25
36
@ doc """
26
37
Dumps the executable to a data structure that can be serialized
27
38
with `term_to_binary`.
39
+
40
+ Works across nodes.
28
41
"""
29
42
# If you change this function, you must bump the version in EXLA.Defn.Disk.
30
43
def dump ( % Executable {
31
- ref: executable ,
44
+ ref: ref ,
32
45
output_typespecs: output_typespecs ,
33
46
num_replicas: num_replicas ,
34
47
num_partitions: num_partitions ,
35
48
device_id: device_id
36
- } ) do
49
+ } )
50
+ when node ( ref ) == node ( ) do
37
51
serialized_exec =
38
- executable
52
+ ref
39
53
|> EXLA.NIF . serialize_executable ( )
40
54
|> unwrap! ( )
41
55
|> IO . iodata_to_binary ( )
@@ -49,6 +63,10 @@ defmodule EXLA.Executable do
49
63
}
50
64
end
51
65
66
+ def dump ( % Executable { ref: ref } = executable ) do
67
+ :erpc . call ( node ( ref ) , __MODULE__ , :dump , [ executable ] )
68
+ end
69
+
52
70
@ doc """
53
71
Loads a previously dumped executable.
54
72
"""
0 commit comments