Skip to content

Commit 41e59a6

Browse files
committed
debug_log_from_routines should only happen when log_level > 1
1 parent ccf03e0 commit 41e59a6

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

arrayjit/lib/backend_utils.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ struct
114114
| _ -> ()));
115115
fprintf ppf "@,@]";
116116
is_global
117-
117+
118118
let compile_main ~traced_store ppf llc : unit =
119119
let open Stdlib.Format in
120120
let visited = Hash_set.create (module Tn) in
@@ -129,7 +129,7 @@ struct
129129
| For_loop { index = i; from_; to_; body; trace_it = _ } ->
130130
fprintf ppf "@[<2>for (int@ %a = %d;@ %a <= %d;@ ++%a) {@ " pp_index i from_ pp_index i
131131
to_ pp_index i;
132-
if Utils.settings.debug_log_from_routines then
132+
if Utils.debug_log_from_routines () then
133133
if B.logs_to_stdout then
134134
fprintf ppf {|printf(@[<h>"%s%%d: index %a = %%d\n",@] log_id, %a);@ |}
135135
!Utils.captured_log_prefix pp_index i pp_index i
@@ -149,7 +149,7 @@ struct
149149
let loop_debug_f = debug_float tn.prec in
150150
let num_closing_braces = pp_top_locals ppf llv in
151151
let num_typ = Ops.cuda_typ_of_prec tn.prec in
152-
if Utils.settings.debug_log_from_routines then (
152+
if Utils.debug_log_from_routines () then (
153153
fprintf ppf "@[<2>{@ @[<2>%s new_set_v =@ %a;@]@ " num_typ loop_f llv;
154154
let v_code, v_idcs = loop_debug_f llv in
155155
let pp_args =
@@ -186,7 +186,7 @@ struct
186186
fprintf ppf "@]@ }@,"
187187
done
188188
| Comment message ->
189-
if Utils.settings.debug_log_from_routines then
189+
if Utils.debug_log_from_routines () then
190190
if B.logs_to_stdout then
191191
fprintf ppf {|printf(@[<h>"%s%%d: COMMENT: %s\n",@] log_id);@ |}
192192
!Utils.captured_log_prefix
@@ -321,7 +321,7 @@ struct
321321
("int " ^ Indexing.symbol_ident s.Indexing.static_symbol, Static_idx s))
322322
in
323323
let log_file =
324-
if Utils.settings.debug_log_from_routines then
324+
if Utils.debug_log_from_routines () then
325325
[
326326
((if B.logs_to_stdout then "int log_id" else "const char* log_file_name"), Log_file_name);
327327
]
@@ -346,7 +346,7 @@ struct
346346
(* FIXME: we should also close the file. *)
347347
if (not (List.is_empty log_file)) && not B.logs_to_stdout then
348348
fprintf ppf {|FILE* log_file = fopen(log_file_name, "w");@ |};
349-
if Utils.settings.debug_log_from_routines && Utils.settings.log_level > 1 then (
349+
if Utils.debug_log_from_routines () then (
350350
fprintf ppf "/* Debug initial parameter state. */@ ";
351351
List.iter
352352
~f:(function

arrayjit/lib/cc_backend.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ let%diagn_sexp link_compiled ~merge_buffer (prior_context : context) (code : pro
282282
[%log_result name];
283283
Backend_utils.check_merge_buffer ~merge_buffer ~code_node:code.lowered.merge_node;
284284
Indexing.apply run_variadic ();
285-
if Utils.settings.debug_log_from_routines then (
285+
if Utils.debug_log_from_routines () then (
286286
Utils.log_trace_tree (Stdio.In_channel.read_lines log_file_name);
287287
Stdlib.Sys.remove log_file_name)
288288
in

arrayjit/lib/cuda_backend.cudajit.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ let compile ~name bindings ({ Low_level.traced_store; _ } as lowered) =
328328
let idx_params = Indexing.bound_symbols bindings in
329329
let b = Buffer.create 4096 in
330330
let ppf = Stdlib.Format.formatter_of_buffer b in
331-
if Utils.settings.debug_log_from_routines then
331+
if Utils.debug_log_from_routines () then
332332
Stdlib.Format.fprintf ppf "@,__device__ int printf (const char * format, ... );@,";
333333
let is_global = Hash_set.create (module Tn) in
334334
let params = Syntax.compile_proc ~name ~is_global ppf idx_params lowered in
@@ -425,12 +425,12 @@ let link_proc ~prior_context ~name ~(params : (string * param_source) list) ~glo
425425
(* Map.iteri global_arrays ~f:(fun ~key ~data:ptr -> if key.Low_level.zero_initialized then
426426
Cu.memset_d8_async ptr Unsigned.UChar.zero ~length:(Tn.size_in_bytes key.Low_level.tn)); *)
427427
[%log "launching the kernel"];
428-
(if Utils.settings.debug_log_from_routines then
428+
(if Utils.debug_log_from_routines () then
429429
Utils.add_log_processor ~prefix:log_id_prefix @@ fun _output ->
430430
[%log_block
431431
context.label;
432432
Utils.log_trace_tree _output]);
433-
(* if Utils.settings.debug_log_from_routines then Cu.ctx_set_limit CU_LIMIT_PRINTF_FIFO_SIZE
433+
(* if Utils.debug_log_from_routines () then Cu.ctx_set_limit CU_LIMIT_PRINTF_FIFO_SIZE
434434
4096; *)
435435
Cu.launch_kernel func ~grid_dim_x:1 ~block_dim_x:1 ~shared_mem_bytes:0 context.device.stream
436436
args;

arrayjit/lib/gcc_backend.gccjit.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ let%diagn_sexp compile_proc ~name ~opt_ctx_arrays ctx bindings ~get_ident
627627
let fkind = Function.Exported in
628628
let c_str = Type.(get ctx Const_char_ptr) in
629629
let log_file_name =
630-
if Utils.settings.debug_log_from_routines then
630+
if Utils.debug_log_from_routines () then
631631
Some (Param.create ctx c_str "log_file_name", Log_file_name)
632632
else None
633633
in
@@ -857,7 +857,7 @@ let%diagn_sexp link_compiled ~merge_buffer (prior_context : context) (code : pro
857857
[%log_result name];
858858
Backend_utils.check_merge_buffer ~merge_buffer ~code_node:code.expected_merge_node;
859859
Indexing.apply run_variadic ();
860-
if Utils.settings.debug_log_from_routines then (
860+
if Utils.debug_log_from_routines () then (
861861
Utils.log_trace_tree (Stdio.In_channel.read_lines log_file_name);
862862
Stdlib.Sys.remove log_file_name)
863863
in

arrayjit/lib/utils.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ let mref_add_missing mref key ~f =
2828
type settings = {
2929
mutable log_level : int;
3030
mutable debug_log_from_routines : bool;
31+
(** If the [debug_log_from_routines] flag is true _and_ the flag [log_level > 1], backends
32+
should generate code (e.g. fprintf statements) to log the execution, and arrange for the
33+
logs to be emitted via ppx_minidebug. *)
3134
mutable debug_memory_locations : bool;
3235
mutable output_debug_files_in_build_directory : bool;
3336
(** Writes compilation related files in the [build_files] subdirectory of the run directory
@@ -315,6 +318,7 @@ let restore_settings () =
315318

316319
let () = restore_settings ()
317320
let with_runtime_debug () = settings.output_debug_files_in_build_directory && settings.log_level > 1
321+
let debug_log_from_routines () = settings.debug_log_from_routines && settings.log_level > 1
318322

319323
let enable_runtime_debug () =
320324
settings.output_debug_files_in_build_directory <- true;
@@ -505,7 +509,7 @@ let add_log_processor ~prefix process_logs =
505509
{ log_processor_prefix = prefix; process_logs } :: !captured_log_processors
506510

507511
let capture_stdout_logs ?(never_skip = false) arg =
508-
if (not never_skip) && not settings.debug_log_from_routines then arg ()
512+
if (not never_skip) && not (debug_log_from_routines ()) then arg ()
509513
else (
510514
Stdlib.flush Stdlib.stdout;
511515
let exitp, entrancep = Unix.pipe () and backup = Unix.dup Unix.stdout in

lib/train.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module CDSL = struct
2323
let virtualize_settings = Arrayjit.Low_level.virtualize_settings
2424

2525
let enable_all_debugs ?(debug_logs = false) ?(hosted_only = true) () =
26-
Utils.set_log_level @@ max 1 @@ Utils.settings.log_level;
26+
Utils.set_log_level @@ max 2 @@ Utils.settings.log_level;
2727
Utils.settings.output_debug_files_in_build_directory <- true;
2828
if hosted_only then virtualize_settings.enable_device_only <- false;
2929
if debug_logs then Utils.settings.debug_log_from_routines <- true

0 commit comments

Comments
 (0)