Skip to content

Commit a58eabb

Browse files
committed
Turn off automatic host transfers on demand
1 parent 6d41b75 commit a58eabb

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

CHANGES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [0.5.1] -- current
1+
## [0.5.1] -- 2024-12-31
22

33
## Added
44

@@ -7,7 +7,7 @@
77

88
## Fixed
99

10-
- Added `#` as alternative to `~~` for comment lines in `ocannl_config` files, and a bug in parsing.
10+
- Added `#` as alternative to `~~` for comment lines in `ocannl_config` files, and fixed a bug in their parsing.
1111

1212
## [0.5.0] -- 2024-12-18
1313

arrayjit/lib/backends.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ module Add_buffer_retrieval_and_syncing (Backend : No_buffer_retrieval_or_syncin
144144
let hosted_inputs = Set.filter r.inputs ~f:(fun tn -> Tn.is_hosted_force tn 47) in
145145
let pre () =
146146
assert (Domain.is_main_domain ());
147-
Set.iter hosted_inputs ~f:(fun tn -> if tn.host_modified then assert (from_host r.context tn));
147+
if Utils.settings.automatic_host_transfers then
148+
Set.iter hosted_inputs ~f:(fun tn ->
149+
if tn.host_modified then assert (from_host r.context tn));
148150
Set.iter r.inputs ~f:(fun tn ->
149151
if Tn.potentially_cross_stream tn then
150152
Option.iter (Hashtbl.find s.device.shared_writer_streams tn) ~f:(fun data ->

arrayjit/lib/tnode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ let do_read tn =
589589
Option.iter
590590
~f:(fun p ->
591591
p.sync ();
592-
p.transfer ())
592+
if Utils.settings.automatic_host_transfers then p.transfer ())
593593
tn.prepare_read;
594594
tn.prepare_read <- None
595595

arrayjit/lib/utils.ml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ type settings = {
4242
mutable check_half_prec_constants_cutoff : float option;
4343
(** If given, generic code optimization should fail if a half precision FP16 constant exceeds
4444
the cutoff. *)
45+
mutable automatic_host_transfers : bool;
46+
(** If true, [from_host] and [to_host] happen automatically in specific situations.
47+
- When a host array is about to be read, we transfer to host from the context that most
48+
recently updated the node.
49+
- When a routine is about to be run, we transfer the routine's inputs from host to the
50+
routine's context if the host array was not yet transfered since its creation or most
51+
recent modification. *)
4552
}
4653
[@@deriving sexp]
4754

@@ -53,6 +60,7 @@ let settings =
5360
fixed_state_for_init = None;
5461
print_decimals_precision = 2;
5562
check_half_prec_constants_cutoff = Some (2. **. 14.);
63+
automatic_host_transfers = true;
5664
}
5765

5866
let accessed_global_args = Hash_set.create (module String)
@@ -364,7 +372,9 @@ let restore_settings () =
364372
Int.of_string @@ get_global_arg ~arg_name:"print_decimals_precision" ~default:"2";
365373
settings.check_half_prec_constants_cutoff <-
366374
Float.of_string_opt
367-
@@ get_global_arg ~arg_name:"check_half_prec_constants_cutoff" ~default:"16384.0"
375+
@@ get_global_arg ~arg_name:"check_half_prec_constants_cutoff" ~default:"16384.0";
376+
settings.automatic_host_transfers <-
377+
Bool.of_string @@ get_global_arg ~arg_name:"automatic_host_transfers" ~default:"true"
368378

369379
let () = restore_settings ()
370380
let with_runtime_debug () = settings.output_debug_files_in_build_directory && settings.log_level > 1

ocannl_config.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ print_decimals_precision=2
3535
# Complains if a half-precision tensor node is a constant with absolute value exceeding this.
3636
check_half_prec_constants_cutoff=16384.0
3737

38+
# If true, [from_host] and [to_host] happen automatically in specific situations:
39+
# - When a host array is about to be read, we transfer to host from the context that most
40+
# recently updated the node.
41+
# - When a routine is about to be run, we transfer the routine's inputs from host to the
42+
# routine's context if the host array was not yet transfered since its creation or most
43+
# recent modification.
44+
automatic_host_transfers=true
45+
3846
# Other configurations:
3947

4048
# If true, stdout capturing is disabled, so some logs meant for the ppx_minidebug log files

todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is for tasks with a smaller granularity than issues, typically immediate tasks.
2-
(A) Ensure that reading from host on CPU performs required synchronization
2+
(A) Ensure that reading from host on CPU performs required synchronization {cm:2024-12-31}
33

44
Update `anatomy_of_a_backend.md`
55
Update introductory slides {cm:2024-12-17}

0 commit comments

Comments
 (0)