#pragma once #include "libkar.h" #include #include #include #include namespace strata::kar { // Experimental component. The caller owns an immutable, verified archive mapping. // One resident compressed expert; one reusable decoded matrix, never a full bank. // Not thread safe. stage/run may only follow completion of the previous run. class ResidentExpert { public: ResidentExpert(); ~ResidentExpert(); ResidentExpert(const ResidentExpert&) = delete; ResidentExpert& operator=(const ResidentExpert&) = delete; bool open(uint32_t hidden, uint32_t intermediate, uint32_t level, uint32_t max_tokens, std::string& error); bool stage(const uint8_t* archive, size_t bytes, const kar_tensor_info& gate, const kar_tensor_info& up, const kar_tensor_info& down, uint32_t expert, std::string& error); // Input/output are host F32. Only this component's event is waited in finish. bool run(const float* input, uint32_t tokens, std::string& error); bool finish(float* output, std::string& error); // Offline qualification hook: copy one reconstructed matrix to the host. bool inspect_matrix(uint32_t role, float* output, std::string& error); uint64_t resident_bytes() const; uint64_t scratch_bytes() const; private: struct Impl; std::unique_ptr impl_; }; } // namespace strata::kar