Skip to content

Commit 5f3cdc6

Browse files
Lizhe Jifacebook-github-bot
authored andcommitted
Add MetaHeader parity test addressing D108793458 review comment (#5935)
Summary: X-link: facebookresearch/FBGEMM#2853 This diff addresses the review comment in D108793458 inline 1189-1193 about hardcoded magic number 16 in values[j].size() >= 16 and sizeof(int64_t) offset baking in MetaHeader layout assumptions. Adds SSDTableBatchedEmbeddingsTest.MetaHeaderParityWithDRAM to verify SSD hard-coded 16-byte header parsing produces identical output to DRAM FixedBlockPool::get_metaheader_raw for same MetaHeader bytes. Keeps production ssd_table_batched_embeddings.h unchanged per follow-up discussion — hard-coded 16 / 8 remains with comment, test is source of truth for cross-backend parity. Updates test BUCK dep to include dram_kv_embedding_inference for FixedBlockPool header access. No production behavior change. Differential Revision: D109084819
1 parent defd174 commit 5f3cdc6

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

fbgemm_gpu/src/ssd_split_embeddings_cache/test/ssd_table_batched_embeddings_test.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <gtest/gtest.h>
1111
#include <cstring>
1212
#include <filesystem>
13+
#include "deeplearning/fbgemm/fbgemm_gpu/src/dram_kv_embedding_cache/fixed_block_pool.h"
1314
#include "deeplearning/fbgemm/fbgemm_gpu/src/ssd_split_embeddings_cache/ssd_table_batched_embeddings.h"
1415

1516
using namespace ::testing;
@@ -641,3 +642,39 @@ TEST(
641642
EXPECT_TRUE(mock->is_metadata_cf_initialized(0));
642643
}
643644
}
645+
646+
TEST(SSDTableBatchedEmbeddingsTest, MetaHeaderParityWithDRAM) {
647+
// Verify SSD helper produces same output as DRAM FixedBlockPool helper
648+
// for identical MetaHeader bytes. Ensures cross-backend compatibility.
649+
// SSD-side helper defined locally to mirror production SSD logic without
650+
// modifying production header per user request — hard-coded 16-byte header,
651+
// 8-byte offset as in ssd_table_batched_embeddings.h original.
652+
auto ssd_get_zch_eviction_metadata_from_raw =
653+
[](const void* data) -> uint64_t {
654+
const char* ptr = static_cast<const char*>(data);
655+
ptr += 8; // sizeof(int64_t) offset to skip key
656+
uint64_t result = 0;
657+
memcpy(&result, ptr, sizeof(uint64_t));
658+
return result;
659+
};
660+
661+
kv_mem::FixedBlockPool::MetaHeader dram_hdr{};
662+
dram_hdr.key = 0x1122334455667788LL;
663+
dram_hdr.timestamp = 0xAABBCCDD;
664+
dram_hdr.count = 0x1234567;
665+
dram_hdr.used = true;
666+
667+
uint64_t dram_out = kv_mem::FixedBlockPool::get_metaheader_raw(&dram_hdr);
668+
669+
// SSD helper lives locally in test, expects validated size
670+
uint64_t ssd_out = ssd_get_zch_eviction_metadata_from_raw(&dram_hdr);
671+
672+
EXPECT_EQ(dram_out, ssd_out);
673+
674+
// unpack matches Python test expectation
675+
uint32_t ts = static_cast<uint32_t>(dram_out & 0xFFFFFFFFu);
676+
uint32_t count_used = static_cast<uint32_t>(dram_out >> 32);
677+
EXPECT_EQ(ts, 0xAABBCCDDu);
678+
EXPECT_EQ(count_used & 0x7FFFFFFFu, 0x1234567u);
679+
EXPECT_EQ(count_used >> 31, 1u);
680+
}

0 commit comments

Comments
 (0)