#pragma once #include "libkar.h" #include #include #include #include #include namespace strata::kar { // Parts cover one global PLE table in row order. The archive and its mapped // bytes must outlive the cache. The caller verifies the archive before open(). struct PlePart { uint64_t row_base; const kar_tensor_info* tensor; }; struct PleCacheStats { uint64_t hits = 0; uint64_t misses = 0; uint64_t compressed_bytes = 0; uint64_t host_to_device_bytes = 0; }; // Experimental level-2, group-32 PLE cache. Each 160-value row occupies one // 64-byte compressed VRAM slot; enqueue() decodes requested rows to caller VRAM. // Calls are serialized. A CUDA event guards the reusable pinned staging buffers // and slots until the previous launch has completed, even across streams. class PleRowCache { public: PleRowCache(); ~PleRowCache(); PleRowCache(const PleRowCache&) = delete; PleRowCache& operator=(const PleRowCache&) = delete; bool open(const uint8_t* archive_map, size_t archive_bytes, const std::vector& parts, uint32_t cache_mib, uint32_t max_batch_rows, std::string& err); bool enqueue(const uint32_t* rows, size_t count, float* device_output, cudaStream_t stream, std::string& err); void close(); PleCacheStats stats() const; uint32_t slots() const; private: struct Impl; std::unique_ptr impl_; }; } // namespace strata::kar