Module Spoc_framework.Backend_error

Error Type Definitions

type codegen_error =
  1. | Unknown_intrinsic of {
    1. name : string;
    }
    (*

    Intrinsic function not recognized by this backend

    *)
  2. | Invalid_arg_count of {
    1. intrinsic : string;
    2. expected : int;
    3. got : int;
    }
    (*

    Wrong number of arguments to intrinsic

    *)
  3. | Unsupported_construct of {
    1. construct : string;
    2. reason : string;
    }
    (*

    IR construct not supported by this backend

    *)
  4. | Type_error of {
    1. expr : string;
    2. expected : string;
    3. got : string;
    }
    (*

    Type mismatch in expression

    *)
  5. | Invalid_memory_space of {
    1. decl : string;
    2. space : string;
    }
    (*

    Invalid memory space qualifier for declaration

    *)
  6. | Unsupported_type of {
    1. type_name : string;
    2. backend : string;
    }
    (*

    Type not supported by backend (e.g., fp64 without cl_khr_fp64)

    *)

Error types for backend code generation (IR → source translation)

type runtime_error =
  1. | No_device_selected of {
    1. operation : string;
    }
    (*

    Operation requires a device but none is set

    *)
  2. | Device_not_found of {
    1. device_id : int;
    2. max_devices : int;
    }
    (*

    Device ID out of range

    *)
  3. | Compilation_failed of {
    1. source : string;
    2. log : string;
    }
    (*

    Kernel compilation failed

    *)
  4. | Module_load_failed of {
    1. size : int;
    2. reason : string;
    }
    (*

    Failed to load compiled module/program

    *)
  5. | Kernel_launch_failed of {
    1. kernel_name : string;
    2. reason : string;
    }
    (*

    Failed to launch kernel on device

    *)
  6. | Memory_allocation_failed of {
    1. bytes : int64;
    2. reason : string;
    }
    (*

    Device memory allocation failed

    *)
  7. | Memory_copy_failed of {
    1. direction : string;
    2. bytes : int;
    3. reason : string;
    }
    (*

    Memory transfer between host and device failed

    *)
  8. | Context_error of {
    1. operation : string;
    2. reason : string;
    }
    (*

    GPU context creation/management failed

    *)
  9. | Synchronization_failed of {
    1. reason : string;
    }
    (*

    Device synchronization failed

    *)

Error types for backend runtime operations

type plugin_error =
  1. | Unsupported_source_lang of {
    1. lang : string;
    2. backend : string;
    }
    (*

    Source language not supported by backend

    *)
  2. | Backend_unavailable of {
    1. reason : string;
    }
    (*

    Backend not available (missing drivers, no devices, etc.)

    *)
  3. | Library_not_found of {
    1. library : string;
    2. paths : string list;
    }
    (*

    Required backend library not found

    *)
  4. | Initialization_failed of {
    1. backend : string;
    2. reason : string;
    }
    (*

    Backend initialization failed

    *)
  5. | Feature_not_supported of {
    1. feature : string;
    2. backend : string;
    }
    (*

    Feature not supported by this backend

    *)

Error types for backend plugin operations

Parameterized Error Type

type t =
  1. | Codegen of {
    1. backend : string;
    2. error : codegen_error;
    }
  2. | Runtime of {
    1. backend : string;
    2. error : runtime_error;
    }
  3. | Plugin of {
    1. backend : string;
    2. error : plugin_error;
    }

Union type for backend errors, parameterized by backend name

exception Backend_error of t

Exception wrapper for backend errors

Error Construction Helpers

val codegen : backend:string -> codegen_error -> t

Create codegen error for a specific backend

val runtime : backend:string -> runtime_error -> t

Create runtime error for a specific backend

val plugin : backend:string -> plugin_error -> t

Create plugin error for a specific backend

Codegen Error Constructors

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

Runtime Error Constructors

val no_device_selected : backend:string -> string -> t
val device_not_found : backend:string -> int -> int -> t
val compilation_failed : backend:string -> string -> string -> t
val module_load_failed : backend:string -> int -> string -> t
val kernel_launch_failed : backend:string -> string -> string -> t
val memory_allocation_failed : backend:string -> int64 -> string -> t
val memory_copy_failed : backend:string -> string -> int -> string -> t
val context_error : backend:string -> string -> string -> t
val synchronization_failed : backend:string -> string -> t

Plugin Error Constructors

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

Error Conversion and Display

val to_string : t -> string

Convert error to human-readable string

val raise_error : t -> 'a

Raise backend error as exception

val print_error : t -> unit

Print error to stderr

val with_default : default:'a -> (unit -> 'a) -> 'a

Execute function with default fallback on error

val to_result : (unit -> 'a) -> ('a, t) Stdlib.result

Convert error to Result type

val result_to_string : ('a, t) Stdlib.result -> ('a, string) Stdlib.result

Map Result error to string

Backend-Specific Modules

module Make (B : sig ... end) : sig ... end

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