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

[opt] Optimize memory usage when saving and loading hkv #383

Merged
merged 1 commit into from
Feb 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ class RandomKVFile : public nv::merlin::BaseKVFile<K, V, S> {
size_t key_read_byte = n * sizeof(K);
size_t value_read_byte = n * sizeof(V) * dim;

key_buffer_.resize(key_read_byte);
value_buffer_.resize(value_read_byte);
key_buffer_.reserve(key_read_byte);
value_buffer_.reserve(value_read_byte);

key_reader_->ReadNBytes(key_read_byte, &key_buffer_);
value_reader_->ReadNBytes(value_read_byte, &value_buffer_);
Expand All @@ -227,16 +227,9 @@ class RandomKVFile : public nv::merlin::BaseKVFile<K, V, S> {
const V* vectors, const S* scores) override {
size_t key_write_byte = n * sizeof(K);
size_t value_write_byte = n * sizeof(V) * value_dim_;
std::vector<char> key_buffer_vector(key_buffer_byte_size_);
char* key_buffer = key_buffer_vector.data();
std::vector<char> value_buffer_vector(value_buffer_byte_size_);
char* value_buffer = value_buffer_vector.data();

memcpy(key_buffer, (void*)keys, key_write_byte);
memcpy(value_buffer, (void*)vectors, value_write_byte);

key_writer_->Append(StringPiece(key_buffer, key_write_byte));
value_writer_->Append(StringPiece(value_buffer, value_write_byte));
key_writer_->Append(StringPiece((char*)keys, key_write_byte));
value_writer_->Append(StringPiece((char*)vectors, value_write_byte));

return n;
}
Expand Down
Loading