39 lines
2.2 KiB
C
39 lines
2.2 KiB
C
|
|
#ifndef GLYPH_HAL_H
|
||
|
|
#define GLYPH_HAL_H
|
||
|
|
#include "../common/glyph_types.h"
|
||
|
|
#include "../common/glyph_decode.h"
|
||
|
|
#define HAL_MAX_BACKENDS 8
|
||
|
|
#define HAL_CAP_CPU (1 << 0)
|
||
|
|
#define HAL_CAP_GPU (1 << 1)
|
||
|
|
#define HAL_CAP_NPU (1 << 2)
|
||
|
|
#define HAL_CAP_FPGA (1 << 3)
|
||
|
|
#define HAL_CAP_WASM (1 << 4)
|
||
|
|
#define HAL_CAP_SUBSTRATE (1 << 5)
|
||
|
|
#define HAL_ARCH_NATIVE 0
|
||
|
|
struct VM_s;
|
||
|
|
typedef int (*hal_exec_mem_fn)(struct VM_s *vm, GlyphInstr *ins);
|
||
|
|
typedef int (*hal_exec_cmp_fn)(struct VM_s *vm, GlyphInstr *ins);
|
||
|
|
typedef int (*hal_exec_ctl_fn)(struct VM_s *vm, GlyphInstr *ins);
|
||
|
|
typedef int (*hal_exec_ipc_fn)(struct VM_s *vm, GlyphInstr *ins);
|
||
|
|
typedef int (*hal_exec_sys_fn)(struct VM_s *vm, GlyphInstr *ins);
|
||
|
|
typedef int (*hal_exec_app_fn)(struct VM_s *vm, GlyphInstr *ins);
|
||
|
|
typedef float (*hal_resonance_fn)(uint32_t similarity);
|
||
|
|
typedef float (*hal_stability_fn)(float t);
|
||
|
|
typedef TraitMask (*hal_traits_propagate_fn)(TraitMask a, TraitMask b);
|
||
|
|
typedef float (*hal_neural_energy_fn)(const uint8_t *a, const uint8_t *b, size_t len);
|
||
|
|
typedef struct { const char *name; uint32_t capabilities; uint32_t arch_id; int priority; hal_exec_mem_fn exec_mem; hal_exec_cmp_fn exec_cmp; hal_exec_ctl_fn exec_ctl; hal_exec_ipc_fn exec_ipc; hal_exec_sys_fn exec_sys; hal_exec_app_fn exec_app; hal_resonance_fn resonance; hal_stability_fn stability; hal_traits_propagate_fn traits_propagate; hal_neural_energy_fn neural_energy; } HAL_Backend;
|
||
|
|
typedef struct { HAL_Backend *backends[HAL_MAX_BACKENDS]; uint32_t backend_count; HAL_Backend *active; } HAL_Context;
|
||
|
|
void hal_init(HAL_Context *ctx);
|
||
|
|
int hal_register(HAL_Context *ctx, HAL_Backend *backend);
|
||
|
|
void hal_select_best(HAL_Context *ctx, uint32_t required_caps);
|
||
|
|
int hal_select_by_name(HAL_Context *ctx, const char *name);
|
||
|
|
uint32_t hal_query_caps(HAL_Context *ctx);
|
||
|
|
uint32_t hal_query_arch(HAL_Context *ctx);
|
||
|
|
int hal_dispatch(HAL_Context *ctx, struct VM_s *vm, GlyphInstr *ins);
|
||
|
|
float hal_resonance(HAL_Context *ctx, uint32_t similarity);
|
||
|
|
float hal_stability(HAL_Context *ctx, float t);
|
||
|
|
TraitMask hal_traits_propagate(HAL_Context *ctx, TraitMask a, TraitMask b);
|
||
|
|
float hal_neural_energy(HAL_Context *ctx, const uint8_t *a, const uint8_t *b, size_t len);
|
||
|
|
HAL_Backend *hal_cpu_backend(void);
|
||
|
|
#endif
|