Files
leleka/gpu/kar/include/kar_expert.hpp
T
Pavlo Ratushnyi 92e611bad5
KAR CUDA compile (GPU hidden) / kar-cuda-compile (push) Failing after 4s
KAR CUDA compile (GPU hidden) / kar-cuda-compile (pull_request) Failing after 4s
feat(kar): add bounded compressed expert LRU
2026-10-07 13:38:15 +02:00

42 lines
1.6 KiB
C++

#pragma once
#include "libkar.h"
#include "kar_expert_cache.hpp"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
namespace strata::kar {
// Experimental component. The caller owns an immutable, verified archive mapping.
// A byte-bounded set of compressed experts shares one reusable decoded matrix;
// it never creates a full decoded 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,
uint64_t compressed_cache_budget_bytes=0);
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;
ExpertCacheStats cache_stats() const;
private:
struct Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace strata::kar