Skip to content

Commit

Permalink
Streamline missing backend mock maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Dec 7, 2024
1 parent 772bea0 commit 1ab276d
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 123 deletions.
10 changes: 2 additions & 8 deletions arrayjit/lib/backend_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
77 changes: 1 addition & 76 deletions arrayjit/lib/cuda_backend.missing.ml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions arrayjit/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
cc_backend
gcc_backend
cuda_backend
lowered_backend_missing
no_device_backend_missing
schedulers
backends)
(modes byte native))
Expand Down
40 changes: 1 addition & 39 deletions arrayjit/lib/gcc_backend.missing.ml
Original file line number Diff line number Diff line change
@@ -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
90 changes: 90 additions & 0 deletions arrayjit/lib/lowered_backend_missing.ml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions arrayjit/lib/lowered_backend_missing.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include Backend_impl.Lowered_backend
45 changes: 45 additions & 0 deletions arrayjit/lib/no_device_backend_missing.ml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions arrayjit/lib/no_device_backend_missing.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include Backend_impl.Lowered_no_device_backend

0 comments on commit 1ab276d

Please sign in to comment.