Module Backend_error.Make

Helper module for creating backend-specific error interfaces. Each backend can instantiate this functor with their name.

Parameters

module B : sig ... end

Signature

val backend : string

Codegen Errors

val unknown_intrinsic : string -> t
val invalid_arg_count : string -> int -> int -> t
val unsupported_construct : string -> string -> t
val type_error : string -> string -> string -> t
val invalid_memory_space : string -> string -> t
val unsupported_type : string -> t

Runtime Errors

val no_device_selected : string -> t
val device_not_found : int -> int -> t
val compilation_failed : string -> string -> t
val module_load_failed : int -> string -> t
val kernel_launch_failed : string -> string -> t
val memory_allocation_failed : int64 -> string -> t
val memory_copy_failed : string -> int -> string -> t
val context_error : string -> string -> t
val synchronization_failed : string -> t
val check : is_success:('a -> bool) -> to_string:('a -> string) -> string -> 'a -> unit

Shared FFI check funnel

Generic replacement for each backend's hand-rolled check ctx result function (e.g. Cuda_api.check, Opencl_api.check, Metal_api.check, Vulkan_api_base.check). Backends supply their own success predicate and stringifier since the underlying result types differ (CUDA cu_result, OpenCL cl_error, Metal mtl_error, Vulkan vk_result); this folds the raw code/message into a canonical Backend_error via context_error instead of a backend-specific exception, so every backend's FFI funnel raises the same exception shape and callers only ever need to catch Backend_error.

Plugin Errors

val unsupported_source_lang : string -> t
val backend_unavailable : string -> t
val library_not_found : string -> string list -> t
val initialization_failed : string -> t
val feature_not_supported : string -> t

Re-export common utilities

val raise_error : t -> 'a
val print_error : t -> unit
val with_default : default:'a -> (unit -> 'a) -> 'a
val to_result : (unit -> 'a) -> ('a, t) Stdlib.result
val to_string : t -> string