Skip to content

Commit

Permalink
Migrate to ppx_minidebug 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Aug 26, 2024
1 parent e4b82ab commit d52f710
Show file tree
Hide file tree
Showing 26 changed files with 250 additions and 283 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
profile = default
margin = 100
parse-docstrings = true
wrap-comments = true
wrap-comments = true
2 changes: 1 addition & 1 deletion arrayjit.opam
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ depends: [
"ppxlib"
"ppx_jane"
"ppx_expect"
"ppx_minidebug" {>= "1.5.1"}
"ppx_minidebug" {>= "2.0.0"}
"odoc" {with-doc}
]
depopts: [
Expand Down
2 changes: 1 addition & 1 deletion arrayjit/lib/assignments.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Debug_runtime = Utils.Debug_runtime

let _get_local_debug_runtime = Utils._get_local_debug_runtime

[%%global_debug_log_level Nothing]
[%%global_debug_log_level 0]
[%%global_debug_log_level_from_env_var "OCANNL_LOG_LEVEL"]

type buffer = Node of Tn.t | Merge_buffer of Tn.t [@@deriving sexp_of]
Expand Down
4 changes: 2 additions & 2 deletions arrayjit/lib/backend_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Debug_runtime = Utils.Debug_runtime

let _get_local_debug_runtime = Utils._get_local_debug_runtime

[%%global_debug_log_level Nothing]
[%%global_debug_log_level 0]
[%%global_debug_log_level_from_env_var "OCANNL_LOG_LEVEL"]

module Types = struct
Expand Down Expand Up @@ -346,7 +346,7 @@ struct
(* FIXME: we should also close the file. *)
if (not (List.is_empty log_file)) && not B.logs_to_stdout then
fprintf ppf {|FILE* log_file = fopen(log_file_name, "w");@ |};
if Utils.settings.debug_log_from_routines && Utils.settings.with_debug_level > 1 then (
if Utils.settings.debug_log_from_routines && Utils.settings.log_level > 1 then (
fprintf ppf "/* Debug initial parameter state. */@ ";
List.iter
~f:(function
Expand Down
146 changes: 67 additions & 79 deletions arrayjit/lib/backends.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Debug_runtime = Utils.Debug_runtime

let _get_local_debug_runtime = Utils._get_local_debug_runtime

[%%global_debug_log_level Nothing]
[%%global_debug_log_level 0]
[%%global_debug_log_level_from_env_var "OCANNL_LOG_LEVEL"]

module type No_device_backend = sig
Expand Down Expand Up @@ -275,7 +275,7 @@ module Multicore_backend (Backend : No_device_backend) : Backend = struct
host_is_waiting = false;
}
in
let%diagn_this_l_sexp worker (() : unit) : unit =
let%diagn_l_sexp worker (() : unit) : unit =
try
while state.keep_spinning do
(* Stdlib.Printf.printf "DEBUG: worker loop start is_idle=%b host_is_waiting=%b
Expand Down Expand Up @@ -329,7 +329,7 @@ module Multicore_backend (Backend : No_device_backend) : Backend = struct
}

let%diagn_sexp make_work device (Tnode.Task { description; _ } as task) =
let%diagn_this_l_sexp work () = schedule_task device task in
let%diagn_l_sexp work () = schedule_task device task in
Tnode.Task
{
context_lifetime = task;
Expand Down Expand Up @@ -387,19 +387,17 @@ module Multicore_backend (Backend : No_device_backend) : Backend = struct
@@ Option.map (Backend.get_buffer tn context.ctx) ~f:(fun c_arr ->
match tn.Tnode.array with
| (lazy (Some h_arr)) ->
let%diagn_this_l_sexp work () =
let%diagn_l_sexp work () =
Backend.host_to_buffer h_arr ~dst:c_arr;
if Utils.settings.with_debug_level > 0 then
[%diagn_sexp
[%log_entry
"from_host " ^ Tnode.debug_name tn;
[%log "copied", Tnode.debug_name tn, "from host"];
if Utils.settings.with_debug_level > 1 then
[%log_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]]
[%diagn_sexp
[%log_block
"from_host " ^ Tnode.debug_name tn;
[%log "copied", Tnode.debug_name tn, "from host"];
[%log2_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]]
in
schedule_task context.device
(Tnode.Task
Expand All @@ -413,7 +411,7 @@ module Multicore_backend (Backend : No_device_backend) : Backend = struct
true
| (lazy None) ->
[%diagn_sexp
[%log_entry
[%log_block
"nothing to copy from host";
[%log "for", Tnode.debug_name tn]]];
false)
Expand All @@ -423,19 +421,17 @@ module Multicore_backend (Backend : No_device_backend) : Backend = struct
@@ Option.map (Backend.get_buffer tn context.ctx) ~f:(fun c_arr ->
match tn.Tnode.array with
| (lazy (Some h_arr)) ->
let%diagn_this_l_sexp work () =
let%diagn_l_sexp work () =
Backend.buffer_to_host h_arr ~src:c_arr;
if Utils.settings.with_debug_level > 0 then
[%diagn_sexp
[%log_entry
"to_host " ^ Tnode.debug_name tn;
[%log "copied to host"];
if Utils.settings.with_debug_level > 1 then
[%log_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]]
[%diagn_sexp
[%log_block
"to_host " ^ Tnode.debug_name tn;
[%log "copied to host"];
[%log2_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]]
in
schedule_task context.device
(Tnode.Task
Expand All @@ -449,7 +445,7 @@ module Multicore_backend (Backend : No_device_backend) : Backend = struct
true
| (lazy None) ->
[%diagn_sexp
[%log_entry
[%log_block
"nothing to copy to host";
[%log "for", Tnode.debug_name tn]]];
false)
Expand Down Expand Up @@ -630,7 +626,7 @@ module Pipes_multicore_backend (Backend : No_device_backend) : Backend = struct
state.keep_spinning && is_dev_queue_empty state && not (host_wait_for_idle.is_waiting ())
in
let wait_by_dev = state.dev_wait.await ~keep_waiting in
let%diagn_this_l_sexp worker (() : unit) : unit =
let%diagn_l_sexp worker (() : unit) : unit =
try
while state.keep_spinning do
match state.dev_pos with
Expand Down Expand Up @@ -665,7 +661,7 @@ module Pipes_multicore_backend (Backend : No_device_backend) : Backend = struct
}

let%diagn_sexp make_work device (Tnode.Task { context_lifetime; description; _ } as task) =
let%diagn_this_l_sexp work () = schedule_task device task in
let%diagn_l_sexp work () = schedule_task device task in
Tnode.Task
{
context_lifetime;
Expand Down Expand Up @@ -723,18 +719,16 @@ module Pipes_multicore_backend (Backend : No_device_backend) : Backend = struct
@@ Option.map (Backend.get_buffer tn context.ctx) ~f:(fun c_arr ->
match tn.Tnode.array with
| (lazy (Some h_arr)) ->
let%diagn_this_l_sexp work () =
let%diagn_l_sexp work () =
Backend.host_to_buffer h_arr ~dst:c_arr;
if Utils.settings.with_debug_level > 0 then
[%log_entry
"from_host " ^ Tnode.debug_name tn;
[%log "copied", Tnode.debug_name tn, "from host"];
if Utils.settings.with_debug_level > 1 then
[%log_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]
[%log_block
"from_host " ^ Tnode.debug_name tn;
[%log "copied", Tnode.debug_name tn, "from host"];
[%log2_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]
in
schedule_task context.device
(Tnode.Task
Expand All @@ -748,7 +742,7 @@ module Pipes_multicore_backend (Backend : No_device_backend) : Backend = struct
true
| (lazy None) ->
[%diagn_sexp
[%log_entry
[%log_block
"nothing to copy from host";
[%log "for", Tnode.debug_name tn]]];
false)
Expand All @@ -758,18 +752,16 @@ module Pipes_multicore_backend (Backend : No_device_backend) : Backend = struct
@@ Option.map (Backend.get_buffer tn context.ctx) ~f:(fun c_arr ->
match tn.Tnode.array with
| (lazy (Some h_arr)) ->
let%diagn_this_l_sexp work () =
let%diagn_l_sexp work () =
Backend.buffer_to_host h_arr ~src:c_arr;
if Utils.settings.with_debug_level > 0 then
[%log_entry
"to_host " ^ Tnode.debug_name tn;
[%log "copied to host"];
if Utils.settings.with_debug_level > 1 then
[%log_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]
[%log_block
"to_host " ^ Tnode.debug_name tn;
[%log "copied to host"];
[%log2_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]
in
schedule_task context.device
(Tnode.Task
Expand All @@ -783,7 +775,7 @@ module Pipes_multicore_backend (Backend : No_device_backend) : Backend = struct
true
| (lazy None) ->
[%diagn_sexp
[%log_entry
[%log_block
"nothing to copy to host";
[%log "for", Tnode.debug_name tn]]];
false)
Expand Down Expand Up @@ -948,21 +940,19 @@ module Sync_backend (Backend : No_device_backend) (* : Backend *) = struct
match tn.Tnode.array with
| (lazy (Some h_arr)) ->
Backend.host_to_buffer h_arr ~dst:c_arr;
if Utils.settings.with_debug_level > 0 then
[%diagn_l_sexp
[%log_entry
"from_host for " ^ Tnode.debug_name tn;
[%log "copied", Tnode.debug_name tn, "from host to", get_name context.device];
if Utils.settings.with_debug_level > 2 then
[%log_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]];
[%diagn_l_sexp
[%log_block
"from_host for " ^ Tnode.debug_name tn;
[%log "copied", Tnode.debug_name tn, "from host to", get_name context.device];
[%log3_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]];
true
| (lazy None) ->
[%diagn_sexp
[%log_entry
[%log_block
"nothing to copy from host for " ^ Tnode.debug_name tn;
[%log "to", get_name context.device]]];
false)
Expand All @@ -973,21 +963,19 @@ module Sync_backend (Backend : No_device_backend) (* : Backend *) = struct
match tn.Tnode.array with
| (lazy (Some h_arr)) ->
Backend.buffer_to_host h_arr ~src:c_arr;
if Utils.settings.with_debug_level > 0 then
[%diagn_l_sexp
[%log_entry
"to_host for " ^ Tnode.debug_name tn;
[%log "copied to host from", get_name context.device];
if Utils.settings.with_debug_level > 1 then
[%log_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]];
[%diagn_l_sexp
[%log_block
"to_host for " ^ Tnode.debug_name tn;
[%log "copied to host from", get_name context.device];
[%log2_printbox
let indices =
Array.init (Array.length @@ Lazy.force tn.dims) ~f:(fun i -> i - 5)
in
Ndarray.render_array ~indices h_arr]]];
true
| (lazy None) ->
[%diagn_sexp
[%log_entry
[%log_block
"nothing to copy to host for " ^ Tnode.debug_name tn;
[%log "from", get_name context.device]]];
false)
Expand Down
6 changes: 3 additions & 3 deletions arrayjit/lib/cc_backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Debug_runtime = Utils.Debug_runtime

let _get_local_debug_runtime = Utils._get_local_debug_runtime

[%%global_debug_log_level Nothing]
[%%global_debug_log_level 0]
[%%global_debug_log_level_from_env_var "OCANNL_LOG_LEVEL"]

open Backend_utils.Types
Expand Down Expand Up @@ -243,7 +243,7 @@ let%diagn_sexp link_compiled ~merge_buffer (prior_context : context) (code : pro
let log_file_name = Utils.diagn_log_file [%string "debug-%{label}-%{code.name}.log"] in
let run_variadic =
[%log_level
Nothing;
0;
let rec link :
'a 'b 'idcs.
'idcs Indexing.bindings ->
Expand Down Expand Up @@ -274,7 +274,7 @@ let%diagn_sexp link_compiled ~merge_buffer (prior_context : context) (code : pro
let params = List.rev_map code.params ~f:(fun (_, p) -> p) in
link code.bindings params Ctypes.(void @-> returning void)]
in
let%diagn_this_l_sexp work () : unit =
let%diagn_l_sexp work () : unit =
[%log_result name];
Backend_utils.check_merge_buffer ~merge_buffer ~code_node:code.lowered.merge_node;
Indexing.apply run_variadic ();
Expand Down
Loading

0 comments on commit d52f710

Please sign in to comment.