Initial commit: GKERN glyph kernel
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
#include "hal.h"
|
||||
#include "../substrate/substrate_engine.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
void hal_init(HAL_Context *ctx) { memset(ctx, 0, sizeof(HAL_Context)); hal_register(ctx, hal_cpu_backend()); ctx->active = ctx->backends[0]; }
|
||||
int hal_register(HAL_Context *ctx, HAL_Backend *backend) { if (ctx->backend_count >= HAL_MAX_BACKENDS) return -1; ctx->backends[ctx->backend_count++] = backend; return 0; }
|
||||
void hal_select_best(HAL_Context *ctx, uint32_t required_caps) { HAL_Backend *best = NULL; int best_priority = -1; for (uint32_t i = 0; i < ctx->backend_count; i++) { HAL_Backend *b = ctx->backends[i]; if ((b->capabilities & required_caps) == required_caps) { if (b->priority > best_priority) { best = b; best_priority = b->priority; } } } if (best) ctx->active = best; }
|
||||
int hal_select_by_name(HAL_Context *ctx, const char *name) { for (uint32_t i = 0; i < ctx->backend_count; i++) { if (strcmp(ctx->backends[i]->name, name) == 0) { ctx->active = ctx->backends[i]; return 0; } } return -1; }
|
||||
uint32_t hal_query_caps(HAL_Context *ctx) { if (ctx->active) return ctx->active->capabilities; return 0; }
|
||||
uint32_t hal_query_arch(HAL_Context *ctx) { if (ctx->active) return ctx->active->arch_id; return HAL_ARCH_NATIVE; }
|
||||
int hal_dispatch(HAL_Context *ctx, struct VM_s *vm, GlyphInstr *ins) { return -1; }
|
||||
float hal_resonance(HAL_Context *ctx, uint32_t similarity) { if (ctx->active && ctx->active->resonance) return ctx->active->resonance(similarity); return substrate_resonance(similarity); }
|
||||
float hal_stability(HAL_Context *ctx, float t) { if (ctx->active && ctx->active->stability) return ctx->active->stability(t); return substrate_stability(t); }
|
||||
TraitMask hal_traits_propagate(HAL_Context *ctx, TraitMask a, TraitMask b) { if (ctx->active && ctx->active->traits_propagate) return ctx->active->traits_propagate(a, b); return substrate_traits_propagate(a, b); }
|
||||
float hal_neural_energy(HAL_Context *ctx, const uint8_t *a, const uint8_t *b, size_t len) { if (ctx->active && ctx->active->neural_energy) return ctx->active->neural_energy(a, b, len); return substrate_neural_energy(a, b, len); }
|
||||
@@ -0,0 +1,38 @@
|
||||
#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
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "hal.h"
|
||||
#include "../substrate/substrate_engine.h"
|
||||
static HAL_Backend cpu_backend = { .name = "cpu", .capabilities = HAL_CAP_CPU | HAL_CAP_SUBSTRATE, .arch_id = HAL_ARCH_NATIVE, .priority = 0, .exec_mem = NULL, .exec_cmp = NULL, .exec_ctl = NULL, .exec_ipc = NULL, .exec_sys = NULL, .exec_app = NULL, .resonance = substrate_resonance, .stability = substrate_stability, .traits_propagate = substrate_traits_propagate, .neural_energy = substrate_neural_energy };
|
||||
HAL_Backend *hal_cpu_backend(void) { return &cpu_backend; }
|
||||
Reference in New Issue
Block a user