From 1ab276d0a8ab88ff385d9a096425af676c26c9e9 Mon Sep 17 00:00:00 2001 From: Lukasz Stafiniak Date: Sat, 7 Dec 2024 18:23:29 +0100 Subject: [PATCH] Streamline missing backend mock maintenance --- arrayjit/lib/backend_impl.ml | 10 +-- arrayjit/lib/cuda_backend.missing.ml | 77 +----------------- arrayjit/lib/dune | 2 + arrayjit/lib/gcc_backend.missing.ml | 40 +--------- arrayjit/lib/lowered_backend_missing.ml | 90 ++++++++++++++++++++++ arrayjit/lib/lowered_backend_missing.mli | 1 + arrayjit/lib/no_device_backend_missing.ml | 45 +++++++++++ arrayjit/lib/no_device_backend_missing.mli | 1 + 8 files changed, 143 insertions(+), 123 deletions(-) create mode 100644 arrayjit/lib/lowered_backend_missing.ml create mode 100644 arrayjit/lib/lowered_backend_missing.mli create mode 100644 arrayjit/lib/no_device_backend_missing.ml create mode 100644 arrayjit/lib/no_device_backend_missing.mli diff --git a/arrayjit/lib/backend_impl.ml b/arrayjit/lib/backend_impl.ml index 4276ace4..613fd692 100644 --- a/arrayjit/lib/backend_impl.ml +++ b/arrayjit/lib/backend_impl.ml @@ -77,14 +77,8 @@ end module Device_types (Device_config : Device_config) = struct include Device_config - type nonrec device = - (Device_config.buffer_ptr, Device_config.dev, Device_config.runner, Device_config.event) device - [@@deriving sexp_of] - - type nonrec stream = - (Device_config.buffer_ptr, Device_config.dev, Device_config.runner, Device_config.event) stream - [@@deriving sexp_of] - + type nonrec device = (buffer_ptr, dev, runner, event) device [@@deriving sexp_of] + type nonrec stream = (buffer_ptr, dev, runner, event) stream [@@deriving sexp_of] type nonrec context = (buffer_ptr, stream) context [@@deriving sexp_of] end diff --git a/arrayjit/lib/cuda_backend.missing.ml b/arrayjit/lib/cuda_backend.missing.ml index 0dca487b..377d544a 100644 --- a/arrayjit/lib/cuda_backend.missing.ml +++ b/arrayjit/lib/cuda_backend.missing.ml @@ -1,76 +1 @@ -open Base - -type buffer_ptr = Unimplemented_buffer_ptr [@@deriving sexp_of] -type context = Unimplemented_ctx [@@deriving sexp_of] -type code = Indexing.unit_bindings [@@deriving sexp_of] -type code_batch = Indexing.unit_bindings array [@@deriving sexp_of] -type ctx_array = | [@@deriving sexp_of] -type ctx_arrays = ctx_array Map.M(Tnode).t [@@deriving sexp_of] -type event = unit - -let sync () = () -let is_done () = true -let will_wait_for _ctx () = () -let initialize _config = () -let is_initialized () = true -let finalize _context = () -let compile ?shared:_ ~name:_ bindings _optimized = bindings - -let compile_batch ?shared:_ ~names:_ (bindings : Indexing.unit_bindings) optimized : code_batch = - Array.map optimized ~f:(fun _ -> bindings) - -let use_host_memory = false -let ctx_arrays Unimplemented_ctx = Map.empty (module Tnode) - -let link (Unimplemented_ctx : context) (code : code) = - let lowered_bindings = List.map ~f:(fun s -> (s, ref 0)) @@ Indexing.bound_symbols code in - let task = - Task.Task - { - context_lifetime = (); - description = "CUDA missing: install cudajit"; - work = (fun () -> ()); - } - in - ((Unimplemented_ctx : context), lowered_bindings, task) - -let link_batch (Unimplemented_ctx : context) (code_batch : code_batch) = - let lowered_bindings = - if Array.is_empty code_batch then [] - else List.map ~f:(fun s -> (s, ref 0)) @@ Indexing.bound_symbols code_batch.(0) - in - let task = - Array.map code_batch ~f:(fun _ -> - Some - (Task.Task - { - context_lifetime = (); - description = "CUDA missing: install cudajit"; - work = (fun () -> ()); - })) - in - ((Unimplemented_ctx : context), lowered_bindings, task) - -let from_host _context _tn = false -let to_host _context _tn = false -let device_to_device _tn ~into_merge_buffer:_ ~dst:_ ~src:_ = false - -type stream = Unimplemented_stream [@@deriving sexp_of] -type device = Unimplemented_device [@@deriving sexp_of] - -let init Unimplemented_stream = Unimplemented_ctx -let buffer_ptr _ctx_array = Unimplemented_buffer_ptr -let alloc_buffer ?old_buffer:_ ~size_in_bytes:_ Unimplemented_stream = Unimplemented_buffer_ptr -let await _stream = () -let is_idle _stream = true -let all_work _stream = () -let get_device ~ordinal:_ = failwith "CUDA missing: install cudajit" -let new_stream Unimplemented_device = Unimplemented_stream -let get_stream_device Unimplemented_stream = Unimplemented_device -let num_devices () = 0 -let suggested_num_streams Unimplemented_device = 0 -let get_ctx_stream Unimplemented_ctx = Unimplemented_stream -let to_ordinal _stream = 0 -let get_global_debug_info () = Sexp.message "global_debug" [] -let get_debug_info Unimplemented_stream = Sexp.message "stream_debug" [] -let name = "cuda" +include Lowered_backend_missing diff --git a/arrayjit/lib/dune b/arrayjit/lib/dune index 1646ca98..5da1033a 100644 --- a/arrayjit/lib/dune +++ b/arrayjit/lib/dune @@ -50,6 +50,8 @@ cc_backend gcc_backend cuda_backend + lowered_backend_missing + no_device_backend_missing schedulers backends) (modes byte native)) diff --git a/arrayjit/lib/gcc_backend.missing.ml b/arrayjit/lib/gcc_backend.missing.ml index 12c3284f..11524383 100644 --- a/arrayjit/lib/gcc_backend.missing.ml +++ b/arrayjit/lib/gcc_backend.missing.ml @@ -1,39 +1 @@ -type procedure = Unimplemented_proc [@@deriving sexp_of] - -include Backend_impl.No_device_buffer_and_copying () - -let expected_merge_node Unimplemented_proc = - failwith "gcc backend missing: install the optional dependency gccjit" - -let use_host_memory = true - -let to_buffer _tn ~dst:_ ~src:_ = - failwith "gcc backend missing: install the optional dependency gccjit" - -let host_to_buffer _src ~dst:_ = - failwith "gcc backend missing: install the optional dependency gccjit" - -let buffer_to_host _dst ~src:_ = - failwith "gcc backend missing: install the optional dependency gccjit" - -let alloc_buffer ?old_buffer:_ ~size_in_bytes:_ () = - failwith "gcc backend missing: install the optional dependency gccjit" - -let alloc_zero_init_array _prec ~dims:_ () = - failwith "gcc backend missing: install the optional dependency gccjit" - -let compile ~name:_ ~opt_ctx_arrays:_ _bindings _code = Unimplemented_proc - -let compile_batch ~names:_ ~opt_ctx_arrays:_ _bindings _codes = - failwith "gcc backend missing: install the optional dependency gccjit" - -let link_compiled ~merge_buffer:_ _ctx_arrays Unimplemented_proc = - failwith "gcc backend missing: install the optional dependency gccjit" - -let device_to_device _tn ~into_merge_buffer:_ ~dst:_ ~src:_ = - failwith "gcc backend missing: install the optional dependency gccjit" - -let physical_merge_buffers = false -let name = "gccjit" -let initialize () = () -let is_initialized () = true +include No_device_backend_missing diff --git a/arrayjit/lib/lowered_backend_missing.ml b/arrayjit/lib/lowered_backend_missing.ml new file mode 100644 index 00000000..e23c1018 --- /dev/null +++ b/arrayjit/lib/lowered_backend_missing.ml @@ -0,0 +1,90 @@ +type buffer_ptr +type dev +type runner +type event + +let use_host_memory = false +let sexp_of_dev _dev = failwith "Backend missing -- install the corresponding library" +let sexp_of_runner _runner = failwith "Backend missing -- install the corresponding library" +let sexp_of_event _event = failwith "Backend missing -- install the corresponding library" +let name = "Backend missing" + +type nonrec device = (buffer_ptr, dev, runner, event) Backend_intf.device + +let sexp_of_device _device = failwith "Backend missing -- install the corresponding library" + +type nonrec stream = (buffer_ptr, dev, runner, event) Backend_intf.stream + +let sexp_of_stream _stream = failwith "Backend missing -- install the corresponding library" + +type nonrec context = (buffer_ptr, stream) Backend_intf.context + +let sexp_of_context _context = failwith "Backend missing -- install the corresponding library" + +let alloc_buffer ?old_buffer:_ ~size_in_bytes:_ _stream = + failwith "Backend missing -- install the corresponding library" + +let alloc_zero_init_array _prec ~dims:_ _stream = + failwith "Backend missing -- install the corresponding library" + +let free_buffer = None +let make_device _dev = failwith "Backend missing -- install the corresponding library" +let make_stream _device = failwith "Backend missing -- install the corresponding library" + +let make_context ?ctx_arrays:_ _stream = + failwith "Backend missing -- install the corresponding library" + +let make_child ?ctx_arrays:_ _context = + failwith "Backend missing -- install the corresponding library" + +let get_name _stream = failwith "Backend missing -- install the corresponding library" +let sexp_of_buffer_ptr _buffer_ptr = failwith "Backend missing -- install the corresponding library" +let c_ptr_to_string = None + +type nonrec buffer = buffer_ptr Backend_intf.buffer + +let sexp_of_buffer _buffer = failwith "Backend missing -- install the corresponding library" + +type nonrec ctx_arrays = buffer_ptr Backend_intf.ctx_arrays + +let sexp_of_ctx_arrays _ctx_arrays = failwith "Backend missing -- install the corresponding library" +let initialize _config = failwith "Backend missing -- install the corresponding library" +let is_initialized () = failwith "Backend missing -- install the corresponding library" +let sync _event = failwith "Backend missing -- install the corresponding library" +let is_done _event = failwith "Backend missing -- install the corresponding library" +let will_wait_for _context = failwith "Backend missing -- install the corresponding library" +let get_used_memory _device = failwith "Backend missing -- install the corresponding library" +let get_global_debug_info () = failwith "Backend missing -- install the corresponding library" +let get_debug_info _stream = failwith "Backend missing -- install the corresponding library" +let await _stream = failwith "Backend missing -- install the corresponding library" +let all_work _stream = failwith "Backend missing -- install the corresponding library" +let is_idle _stream = failwith "Backend missing -- install the corresponding library" +let get_device ~ordinal:_ = failwith "Backend missing -- install the corresponding library" +let num_devices () = 0 +let suggested_num_streams _device = failwith "Backend missing -- install the corresponding library" +let new_stream _device = failwith "Backend missing -- install the corresponding library" + +let from_host ~dst_ptr:_ ~dst:_ _nd = + failwith "Backend missing -- install the corresponding library" + +let to_host ~src_ptr:_ ~src:_ _nd = failwith "Backend missing -- install the corresponding library" +let device_to_device _tn = failwith "Backend missing -- install the corresponding library" + +type code + +let sexp_of_code _code = failwith "Backend missing -- install the corresponding library" + +type code_batch + +let sexp_of_code_batch _code_batch = failwith "Backend missing -- install the corresponding library" + +let compile ?shared:_ ~name:_ _unit_bindings _optimized = + failwith "Backend missing -- install the corresponding library" + +let compile_batch ?shared:_ ~names:_ _unit_bindings _optimizeds = + failwith "Backend missing -- install the corresponding library" + +let link _context _code = failwith "Backend missing -- install the corresponding library" + +let link_batch _context _code_batch = + failwith "Backend missing -- install the corresponding library" diff --git a/arrayjit/lib/lowered_backend_missing.mli b/arrayjit/lib/lowered_backend_missing.mli new file mode 100644 index 00000000..375d56ab --- /dev/null +++ b/arrayjit/lib/lowered_backend_missing.mli @@ -0,0 +1 @@ +include Backend_impl.Lowered_backend diff --git a/arrayjit/lib/no_device_backend_missing.ml b/arrayjit/lib/no_device_backend_missing.ml new file mode 100644 index 00000000..172b0c3b --- /dev/null +++ b/arrayjit/lib/no_device_backend_missing.ml @@ -0,0 +1,45 @@ +type buffer_ptr + +let use_host_memory = false +let initialize _config = failwith "Backend missing -- install the corresponding library" +let is_initialized () = failwith "Backend missing -- install the corresponding library" +let name = "Backend missing" + +type procedure + +let sexp_of_procedure _procedure = failwith "Backend missing -- install the corresponding library" + +let compile ~name:_ ~opt_ctx_arrays:_ _unit_bindings _optimized = + failwith "Backend missing -- install the corresponding library" + +let compile_batch ~names:_ ~opt_ctx_arrays:_ _unit_bindings _optimizeds = + failwith "Backend missing -- install the corresponding library" + +let link_compiled ~merge_buffer:_ ~runner_label:_ _ctx_arrays _procedure = + failwith "Backend missing -- install the corresponding library" + +let sexp_of_buffer_ptr _buffer_ptr = failwith "Backend missing -- install the corresponding library" +let c_ptr_to_string = None + +type nonrec buffer = buffer_ptr Backend_intf.buffer + +let sexp_of_buffer _buffer = failwith "Backend missing -- install the corresponding library" + +type nonrec ctx_arrays = buffer_ptr Backend_intf.ctx_arrays + +let sexp_of_ctx_arrays _ctx_arrays = failwith "Backend missing -- install the corresponding library" + +let alloc_buffer ?old_buffer:_ ~size_in_bytes:_ () = + failwith "Backend missing -- install the corresponding library" + +let alloc_zero_init_array _prec ~dims:_ () = + failwith "Backend missing -- install the corresponding library" + +let free_buffer = None +let get_used_memory () = failwith "Backend missing -- install the corresponding library" + +let buffer_to_buffer ~dst:_ ~src:_ ~size_in_bytes:_ = + failwith "Backend missing -- install the corresponding library" + +let host_to_buffer _nd = failwith "Backend missing -- install the corresponding library" +let buffer_to_host _nd = failwith "Backend missing -- install the corresponding library" diff --git a/arrayjit/lib/no_device_backend_missing.mli b/arrayjit/lib/no_device_backend_missing.mli new file mode 100644 index 00000000..eaf76ea1 --- /dev/null +++ b/arrayjit/lib/no_device_backend_missing.mli @@ -0,0 +1 @@ +include Backend_impl.Lowered_no_device_backend