-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
593 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
namespace diskann | ||
{ | ||
|
||
template <typename data_t> class PQScratch; | ||
|
||
// By somewhat more than a coincidence, it seems that both InMemQueryScratch | ||
// and SSDQueryScratch have the aligned query and PQScratch objects. So we | ||
// can put them in a neat hierarchy and keep PQScratch as a standalone class. | ||
template <typename data_t> class AbstractScratch | ||
{ | ||
public: | ||
AbstractScratch() = default; | ||
// This class does not take any responsibilty for memory management of | ||
// its members. It is the responsibility of the derived classes to do so. | ||
virtual ~AbstractScratch() = default; | ||
|
||
// Scratch objects should not be copied | ||
AbstractScratch(const AbstractScratch &) = delete; | ||
AbstractScratch &operator=(const AbstractScratch &) = delete; | ||
|
||
data_t *aligned_query_T() | ||
{ | ||
return _aligned_query_T; | ||
} | ||
PQScratch<data_t> *pq_scratch() | ||
{ | ||
return _pq_scratch; | ||
} | ||
|
||
protected: | ||
data_t *_aligned_query_T = nullptr; | ||
PQScratch<data_t> *_pq_scratch = nullptr; | ||
}; | ||
} // namespace diskann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <sstream> | ||
|
||
#define NUM_PQ_BITS 8 | ||
#define NUM_PQ_CENTROIDS (1 << NUM_PQ_BITS) | ||
#define MAX_OPQ_ITERS 20 | ||
#define NUM_KMEANS_REPS_PQ 12 | ||
#define MAX_PQ_TRAINING_SET_SIZE 256000 | ||
#define MAX_PQ_CHUNKS 512 | ||
|
||
namespace diskann | ||
{ | ||
inline std::string get_quantized_vectors_filename(const std::string &prefix, bool use_opq, uint32_t num_chunks) | ||
{ | ||
return prefix + (use_opq ? "_opq" : "pq") + std::to_string(num_chunks) + "_compressed.bin"; | ||
} | ||
|
||
inline std::string get_pivot_data_filename(const std::string &prefix, bool use_opq, uint32_t num_chunks) | ||
{ | ||
return prefix + (use_opq ? "_opq" : "pq") + std::to_string(num_chunks) + "_pivots.bin"; | ||
} | ||
|
||
inline std::string get_rotation_matrix_suffix(const std::string &pivot_data_filename) | ||
{ | ||
return pivot_data_filename + "_rotation_matrix.bin"; | ||
} | ||
|
||
} // namespace diskann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
#include <cstdint> | ||
#include "pq_common.h" | ||
#include "utils.h" | ||
|
||
namespace diskann | ||
{ | ||
|
||
template <typename T> class PQScratch | ||
{ | ||
public: | ||
float *aligned_pqtable_dist_scratch = nullptr; // MUST BE AT LEAST [256 * NCHUNKS] | ||
float *aligned_dist_scratch = nullptr; // MUST BE AT LEAST diskann MAX_DEGREE | ||
uint8_t *aligned_pq_coord_scratch = nullptr; // AT LEAST [N_CHUNKS * MAX_DEGREE] | ||
float *rotated_query = nullptr; | ||
float *aligned_query_float = nullptr; | ||
|
||
PQScratch(size_t graph_degree, size_t aligned_dim); | ||
void initialize(size_t dim, const T *query, const float norm = 1.0f); | ||
}; | ||
|
||
} // namespace diskann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.