Module Spoc_core.Error

Structured Exceptions

exception No_device_available

No compute device available

exception Device_not_found of string

Device with given name not found

exception Invalid_block_size of {
  1. requested : int;
  2. max : int;
}

Requested block size exceeds device limit

exception Invalid_grid_size of {
  1. requested : int;
  2. max : int;
}

Requested grid size exceeds device limit

exception Out_of_memory of {
  1. requested : int64;
  2. available : int64;
}

Not enough memory for allocation

exception Compilation_error of {
  1. device : string;
  2. message : string;
}

Kernel compilation failed

exception Transfer_error of {
  1. direction : [ `To_device | `To_host ];
  2. message : string;
}

Data transfer failed

exception Kernel_error of {
  1. name : string;
  2. message : string;
}

Kernel execution failed

exception Invalid_argument of {
  1. func : string;
  2. message : string;
}

Invalid argument to runtime function

exception Backend_error of {
  1. backend : string;
  2. code : int;
  3. message : string;
}

Backend-specific error

Exception Helpers

val string_of_direction : [< `To_device | `To_host ] -> string
val pp_exn : Stdlib.Format.formatter -> exn -> unit
val to_string : exn -> string

Debug Mode (delegates to Log.ml)

type log_level =
  1. | Silent
  2. | Errors
  3. | Warnings
  4. | Info
  5. | Trace
val current_level : log_level Stdlib.ref
val to_log_level : log_level -> Log.level
val level_to_int : log_level -> int
val should_log : log_level -> bool
val set_level : log_level -> unit
val get_level : unit -> log_level

Logging Functions

val log : log_level -> ('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 -> 'a
val error : ('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 -> 'a
val warn : ('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 -> 'a
val info : ('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 -> 'a
val trace : ('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 -> 'a

Runtime Validation

val validate_kernel_args : bool Stdlib.ref
val validate_bounds : bool Stdlib.ref
val trace_transfers : bool Stdlib.ref
val trace_kernels : bool Stdlib.ref
val enable_validation : unit -> unit
val disable_validation : unit -> unit
val enable_tracing : unit -> unit
val disable_tracing : unit -> unit

Debug Helpers

val check_block_size : requested:int -> max:int -> unit

Check block size against device limits

val check_grid_size : requested:int -> max:int -> unit

Check grid size against device limits

val check_memory : requested:int64 -> available:int64 -> unit

Check memory availability

val with_context : func:string -> (unit -> 'a) -> 'a

Wrap function with error context

Result Type Helpers

type 'a result = ('a, exn) Stdlib.Result.t
val ok : 'a -> ('a, 'b) Stdlib.Result.t
val error_result : 'a -> ('b, 'a) Stdlib.Result.t
val try_with : (unit -> 'a) -> ('a, exn) Stdlib.Result.t
val (let*) : ('a, 'b) Stdlib.result -> ('a -> ('c, 'b) Stdlib.result) -> ('c, 'b) Stdlib.result
val map_error : ('a -> 'b) -> ('c, 'a) Stdlib.Result.t -> ('c, 'b) Stdlib.Result.t

Debug Output

val debug_vector : ('a, 'b) Vector.t -> unit

Print debug info about a vector

val debug_device : Device.t -> unit

Print debug info about a device

Assertions

val assert_arg : func:string -> cond:bool -> message:string -> unit

Assert condition or raise Invalid_argument

val assert_on_cpu : func:string -> ('a, 'b) Vector.t -> unit

Assert vector is on CPU

val assert_on_gpu : func:string -> ('a, 'b) Vector.t -> unit

Assert vector is on GPU