Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gen_fbin_file.cpp to support binary data type #211

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions benchmark/hdf5/gen_fbin_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class Create_FBIN : public Benchmark_hdf5, public ::testing::Test {
writer((void*)data, rows * dim * sizeof(float));
}

void
fbin_write_binary(const std::string& filename, const uint32_t rows, const uint32_t dim, const void* data) {
FileIOWriter writer(filename);
writer((void*)&rows, sizeof(rows));
writer((void*)&dim, sizeof(dim));
writer((void*)data, rows * (dim / 8) * sizeof(uint8_t));
}

void
fbin_read(const std::string& filename, uint32_t& rows, uint32_t& dim, void* data) {
FileIOReader reader(filename);
Expand All @@ -60,6 +68,14 @@ class Create_FBIN : public Benchmark_hdf5, public ::testing::Test {
reader((void*)data, rows * dim * sizeof(float));
}

void
fbin_read_binary(const std::string& filename, uint32_t& rows, uint32_t& dim, void* data) {
FileIOReader reader(filename);
reader((void*)&rows, sizeof(rows));
reader((void*)&dim, sizeof(dim));
reader((void*)data, rows * (dim / 8) * sizeof(uint8_t));
}

void
fbin_result_write(const std::string& filename, const uint32_t rows, const uint32_t topk, const uint32_t* ids,
const float* dist) {
Expand Down Expand Up @@ -173,3 +189,45 @@ TEST_F(Create_FBIN, HDF5_RANGE_TO_FBIN) {

free_all();
}

TEST_F(Create_FBIN, HDF5_BIN_TO_FBIN) {
set_ann_test_name("rand-1024-hamming");
parse_ann_test_name();
load_hdf5_data<true>();

std::string prefix = dataset_name_ + "-" + std::to_string(dim_) + "-";
std::string postfix = ".fbin";
std::string filename;

filename = prefix + "base" + postfix;
fbin_write_binary(filename, nb_, dim_, xb_);

filename = prefix + "query" + postfix;
fbin_write_binary(filename, nq_, dim_, xq_);

filename = prefix + metric_str_ + "-gt" + postfix;
fbin_result_write(filename, nq_, gt_k_, (uint32_t*)gt_ids_, gt_dist_);

free_all();
}

TEST_F(Create_FBIN, HDF5_BIN_RANGE_TO_FBIN) {
set_ann_test_name("rand-1024-hamming-range");
parse_ann_test_name_with_range();
load_hdf5_data_range<true>();

std::string prefix = dataset_name_ + "-" + std::to_string(dim_) + "-range-";
std::string postfix = ".fbin";
std::string filename;

filename = prefix + "base" + postfix;
fbin_write_binary(filename, nb_, dim_, xb_);

filename = prefix + "query" + postfix;
fbin_write_binary(filename, nq_, dim_, xq_);

filename = prefix + metric_str_ + "-gt" + postfix;
fbin_range_result_write(filename, nq_, *gt_radius_, (uint32_t*)gt_lims_, (uint32_t*)gt_ids_, gt_dist_);

free_all();
}
Loading