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

Commit

Permalink
Refine mmap implement for HNSW (#1015)
Browse files Browse the repository at this point in the history
Signed-off-by: yah01 <yang.cen@zilliz.com>
  • Loading branch information
yah01 authored Jul 31, 2023
1 parent 4acecef commit b7d0b0a
Show file tree
Hide file tree
Showing 4 changed files with 494 additions and 27 deletions.
6 changes: 6 additions & 0 deletions include/knowhere/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ hash_binary_vec(const uint8_t* x, size_t d) {
return h;
}

template <typename T>
inline T
round_down(const T value, const T align) {
return value / align * align;
}

} // namespace knowhere
37 changes: 24 additions & 13 deletions src/io/fileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,57 @@

namespace knowhere {
struct FileReader {
int fd;
size_t size;

FileReader(const std::string& filename, bool auto_remove = false) {
fd = open(filename.data(), O_RDONLY);
if (fd < 0) {
std::runtime_error("Cannot open file");
fd_ = open(filename.data(), O_RDONLY);
if (fd_ < 0) {
throw std::runtime_error("Cannot open file");
}

size = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
size_ = lseek(fd_, 0, SEEK_END);
lseek(fd_, 0, SEEK_SET);

if (auto_remove) {
unlink(filename.data());
}
}

int
descriptor() const {
return fd_;
}

size_t
size() const {
return size_;
}

ssize_t
read(char* dst, size_t n) {
return ::read(fd, dst, n);
return ::read(fd_, dst, n);
}

off_t
seek(off_t offset) {
return lseek(fd, offset, SEEK_SET);
return lseek(fd_, offset, SEEK_SET);
}

off_t
advance(off_t offset) {
return lseek(fd, offset, SEEK_CUR);
return lseek(fd_, offset, SEEK_CUR);
}

off_t
offset() {
return lseek(fd, 0, SEEK_CUR);
return lseek(fd_, 0, SEEK_CUR);
}

int
close() {
return ::close(fd);
return ::close(fd_);
}

private:
int fd_;
size_t size_;
};
} // namespace knowhere
Loading

0 comments on commit b7d0b0a

Please sign in to comment.