Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
use threaddata scratch as aio and vector buffer (#667)
Browse files Browse the repository at this point in the history
Signed-off-by: cqy123456 <[email protected]>
  • Loading branch information
cqy123456 authored Feb 8, 2023
1 parent 4124cab commit 354c19e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
7 changes: 4 additions & 3 deletions thirdparty/DiskANN/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ namespace diskann {
#else
::_aligned_free(ptr);
#endif
if (malloc_trim(0) == 0) {
LOG(DEBUG) << "Failed to release free memory from the heap.";
}
// Note: malloc_trim() combines with jemalloc/tcmalloc may cause crash
// if (malloc_trim(0) == 0) {
// LOG(DEBUG) << "Failed to release free memory from the heap.";
// }
}

inline void GenRandom(std::mt19937& rng, unsigned* addr, unsigned size,
Expand Down
21 changes: 10 additions & 11 deletions thirdparty/DiskANN/src/pq_flash_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,44 +470,43 @@ namespace diskann {
num_medoids * aligned_dim * sizeof(float), 32);
std::memset(centroid_data, 0, num_medoids * aligned_dim * sizeof(float));

// borrow ctx
ThreadData<T> data = this->thread_data.pop();

while (data.scratch.sector_scratch == nullptr) {
this->thread_data.wait_for_push_notify();
data = this->thread_data.pop();
}
// borrow ctx
IOContext &ctx = data.ctx;
// borrow buf
auto scratch = &(data.scratch);
scratch->reset();
char *sector_scratch = scratch->sector_scratch;
T* medoid_coords = scratch->coord_scratch;

LOG(INFO) << "Loading centroid data from medoids vector data of "
<< num_medoids << " medoid(s)";
for (uint64_t cur_m = 0; cur_m < num_medoids; cur_m++) {
auto medoid = medoids[cur_m];
// read medoid nhood
char *medoid_buf = nullptr;
alloc_aligned((void **) &medoid_buf, read_len_for_node, SECTOR_LEN);
std::vector<AlignedRead> medoid_read(1);
medoid_read[0].len = read_len_for_node;
medoid_read[0].buf = medoid_buf;
medoid_read[0].buf = sector_scratch;
medoid_read[0].offset = get_node_sector_offset(medoid);
reader->read(medoid_read, ctx);

// all data about medoid
char *medoid_node_buf = get_offset_to_node(medoid_buf, medoid);
char *medoid_node_buf = get_offset_to_node(sector_scratch, medoid);

// add medoid coords to `coord_cache`
T *medoid_coords = new T[data_dim];
T *medoid_disk_coords = OFFSET_TO_NODE_COORDS(medoid_node_buf);
memcpy(medoid_coords, medoid_disk_coords, disk_bytes_per_point);

if (!use_disk_index_pq) {
for (uint32_t i = 0; i < data_dim; i++)
centroid_data[cur_m * aligned_dim + i] = medoid_coords[i];
} else {
disk_pq_table.inflate_vector((_u8 *) medoid_coords,
(centroid_data + cur_m * aligned_dim));
}

aligned_free(medoid_buf);
delete[] medoid_coords;
}

// return ctx
Expand Down

0 comments on commit 354c19e

Please sign in to comment.