#include "kar_expert.hpp" #include #include #include #include #include namespace { void require(bool ok, const char* what) { if(!ok)throw std::runtime_error(what); } void u16(std::vector& b,size_t at,uint16_t n) { b[at]=n; b[at+1]=n>>8; } void u32(std::vector& b,size_t at,uint32_t n) { for(int i=0;i<4;++i)b[at+i]=n>>(8*i); } } int main() try { constexpr uint32_t H=64,F=32,E=2,W=H*F/32; // Independent synthetic decoded weights are +/-1 times 1/32. Each of // three roles and two experts has its own alternating bit pattern. std::vector archive(3*4096,0); kar_tensor_info tensors[3]{}; std::vector reference[3]; for(uint32_t role=0;role<3;++role) { auto& t=tensors[role]; const size_t base=role*4096; t.storage_class=KAR_NESTED;t.nesting=KAR_TOPDOWN;t.group=32;t.n_dims=3; t.dims[0]=role==2?F:H;t.dims[1]=role==2?H:F;t.dims[2]=E; t.n_elements=H*F*E;t.planes_min=t.planes_max=1;t.planes_stored=1; t.books_offset=base;t.scales_offset=base+32;t.planes_offset=base+512; t.plane_stride_bytes=W*E*4; u16(archive,base,0xbc00);u16(archive,base+2,0x3c00); // -1,+1 reference[role].resize(H*F*E); for(uint32_t word=0;word