Skip to content

Commit cae9852

Browse files
author
Denis Deyneko
committed
Add a macro for whether use map of file when saving snapshot
Nuget version is dummy.
1 parent 1f3a83a commit cae9852

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

nuget/DiskANN-preview.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
33
<metadata>
44
<id>DiskANN-preview.win-x64</id>
5-
<version>0.13.725.1</version>
5+
<version>0.13.729.3-temp</version>
66
<authors>DiskANN team</authors>
77
<owners>DiskANN team</owners>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>

src/index.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#define MAX_POINTS_FOR_USING_BITSET 10000000
2626

27+
#define USE_MAP_OF_FILE 1
28+
2729
namespace diskann
2830
{
2931

@@ -223,7 +225,7 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
223225
// If not compacted, saving the whole data as the points may be spread around.
224226
const unsigned node_count = _data_compacted ? _nd + _num_frozen_pts : _max_points + _num_frozen_pts;
225227

226-
#ifdef _WINDOWS
228+
#ifdef USE_MAP_OF_FILE
227229

228230
const size_t size_of_data = node_count * _aligned_dim * sizeof(T);
229231
const size_t total_size = 2 * sizeof(uint32_t) + size_of_data;
@@ -241,6 +243,10 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
241243

242244
return size_of_data;
243245
#else
246+
Log(logging::Info,
247+
"save_data",
248+
"Saving data using ofstream");
249+
244250
return save_data_in_base_dimensions(data_file, _data, node_count, _dim, _aligned_dim);
245251
#endif
246252
}
@@ -250,7 +256,7 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
250256
// 4 byte unsigned)
251257
template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT>::save_graph(const std::string& graph_file) const
252258
{
253-
#if _WINDOWS
259+
#if USE_MAP_OF_FILE
254260

255261
Log(logging::Info, "save_graph", "Saving graph data using file map");
256262

@@ -322,6 +328,8 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
322328
return index_size;
323329

324330
#else
331+
Log(logging::Info, "save_graph", "Saving graph data using ofstream");
332+
325333
std::ofstream out;
326334
open_file_to_write(out, graph_file);
327335

@@ -337,12 +345,12 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
337345
out.write((char *)&_start, sizeof(_start));
338346
out.write((char *)&_num_frozen_pts, sizeof(_num_frozen_pts));
339347

340-
size_t data_compacted_output = _data_compacted ? 1 : 0;
348+
const size_t data_compacted_output = _data_compacted ? 1 : 0;
341349
out.write((char *)&data_compacted_output, sizeof(data_compacted_output));
342350

343-
const _u64 header_size = sizeof(index_size) + sizeof(_max_observed_degree)
344-
+ sizeof(_start) + sizeof(_num_frozen_pts)
345-
+ sizeof(data_compacted_output);
351+
const _u64 header_size = sizeof(index_size) + sizeof(_max_observed_degree) + sizeof(_start) +
352+
sizeof(_num_frozen_pts) + sizeof(data_compacted_output);
353+
346354
index_size = header_size;
347355

348356
// If the graph is compacted, either _nd == _max_points or any frozen points have been
@@ -378,7 +386,9 @@ template <typename T, typename TagT, typename LabelT> _u64 Index<T, TagT, LabelT
378386
Log(logging::Info,
379387
"save_graph",
380388
"Graph data saved, total points: %u, empty out nodes: %u, max_degree: %u",
381-
total_points, empty_out_neighbors, max_degree);
389+
total_points,
390+
empty_out_neighbors,
391+
max_degree);
382392

383393
return index_size; // number of bytes written
384394
#endif
@@ -470,10 +480,10 @@ void Index<T, TagT, LabelT>::save(const char *filename, bool compact_before_save
470480
}
471481
}
472482

473-
std::string graph_file = std::string(filename);
474-
std::string tags_file = std::string(filename) + ".tags";
475-
std::string data_file = std::string(filename) + ".data";
476-
std::string delete_list_file = std::string(filename) + ".del";
483+
const std::string graph_file = std::string(filename);
484+
const std::string tags_file = std::string(filename) + ".tags";
485+
const std::string data_file = std::string(filename) + ".data";
486+
const std::string delete_list_file = std::string(filename) + ".del";
477487

478488
// Because the save_* functions use append mode, ensure that
479489
// the files are deleted before save. Ideally, we should check

0 commit comments

Comments
 (0)