Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions c/src/neighbors/brute_force.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -10,6 +10,7 @@

#include <raft/core/error.hpp>
#include <raft/core/mdspan_types.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/resources.hpp>
#include <raft/core/serialize.hpp>

Expand Down Expand Up @@ -238,9 +239,13 @@ extern "C" cuvsError_t cuvsBruteForceDeserialize(cuvsResources_t res,
// read the numpy dtype from the beginning of the file
std::ifstream is(filename, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", filename); }
char dtype_string[4];
is.read(dtype_string, 4);
auto dtype = raft::detail::numpy_serializer::parse_descr(std::string(dtype_string, 4));
char dtype_string[4]{};
if (!is.read(dtype_string, sizeof(dtype_string))) {
RAFT_FAIL("Invalid or truncated index header in file %s", filename);
}
auto dtype =
raft::numpy_serializer::parse_descr(std::string(dtype_string, sizeof(dtype_string)));
is.close();

index->dtype.bits = dtype.itemsize * 8;
if (dtype.kind == 'f' && dtype.itemsize == 4) {
Expand Down
11 changes: 8 additions & 3 deletions c/src/neighbors/cagra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <raft/core/error.hpp>
#include <raft/core/mdspan_types.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/resources.hpp>
#include <raft/core/serialize.hpp>

Expand Down Expand Up @@ -873,9 +874,13 @@ extern "C" cuvsError_t cuvsCagraDeserialize(cuvsResources_t res,
// read the numpy dtype from the beginning of the file
std::ifstream is(filename, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", filename); }
char dtype_string[4];
is.read(dtype_string, 4);
auto dtype = raft::detail::numpy_serializer::parse_descr(std::string(dtype_string, 4));
char dtype_string[4]{};
if (!is.read(dtype_string, sizeof(dtype_string))) {
RAFT_FAIL("Invalid or truncated index header in file %s", filename);
}
auto dtype =
raft::numpy_serializer::parse_descr(std::string(dtype_string, sizeof(dtype_string)));
is.close();

index->dtype.bits = dtype.itemsize * 8;
if (dtype.kind == 'f' && dtype.itemsize == 4) {
Expand Down
13 changes: 9 additions & 4 deletions c/src/neighbors/ivf_flat.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -9,6 +9,7 @@

#include <raft/core/error.hpp>
#include <raft/core/mdspan_types.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/resources.hpp>
#include <raft/core/serialize.hpp>
#include <raft/util/cudart_utils.hpp>
Expand Down Expand Up @@ -299,9 +300,13 @@ extern "C" cuvsError_t cuvsIvfFlatDeserialize(cuvsResources_t res,
// read the numpy dtype from the beginning of the file
std::ifstream is(filename, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", filename); }
char dtype_string[4];
is.read(dtype_string, 4);
auto dtype = raft::detail::numpy_serializer::parse_descr(std::string(dtype_string, 4));
char dtype_string[4]{};
if (!is.read(dtype_string, sizeof(dtype_string))) {
RAFT_FAIL("Invalid or truncated index header in file %s", filename);
}
auto dtype =
raft::numpy_serializer::parse_descr(std::string(dtype_string, sizeof(dtype_string)));
is.close();

index->dtype.bits = dtype.itemsize * 8;
if (dtype.kind == 'f' && dtype.itemsize == 4) {
Expand Down
21 changes: 14 additions & 7 deletions c/src/neighbors/mg_cagra.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -10,6 +10,7 @@
#include <cuvs/neighbors/common.hpp>
#include <dlpack/dlpack.h>
#include <raft/core/error.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/serialize.hpp>

#include "../core/exceptions.hpp"
Expand Down Expand Up @@ -399,9 +400,12 @@ extern "C" cuvsError_t cuvsMultiGpuCagraDeserialize(cuvsResources_t res,
return cuvs::core::translate_exceptions([=] {
std::ifstream is(filename, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", filename); }
char dtype_string[4];
is.read(dtype_string, 4);
auto dtype = raft::detail::numpy_serializer::parse_descr(std::string(dtype_string, 4));
char dtype_string[4]{};
if (!is.read(dtype_string, sizeof(dtype_string))) {
RAFT_FAIL("Invalid or truncated index header in file %s", filename);
}
auto dtype =
raft::numpy_serializer::parse_descr(std::string(dtype_string, sizeof(dtype_string)));
is.close();

index->dtype.bits = dtype.itemsize * 8;
Expand Down Expand Up @@ -430,9 +434,12 @@ extern "C" cuvsError_t cuvsMultiGpuCagraDistribute(cuvsResources_t res,
return cuvs::core::translate_exceptions([=] {
std::ifstream is(filename, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", filename); }
char dtype_string[4];
is.read(dtype_string, 4);
auto dtype = raft::detail::numpy_serializer::parse_descr(std::string(dtype_string, 4));
char dtype_string[4]{};
if (!is.read(dtype_string, sizeof(dtype_string))) {
RAFT_FAIL("Invalid or truncated index header in file %s", filename);
}
auto dtype =
raft::numpy_serializer::parse_descr(std::string(dtype_string, sizeof(dtype_string)));
is.close();

index->dtype.bits = dtype.itemsize * 8;
Expand Down
21 changes: 14 additions & 7 deletions c/src/neighbors/mg_ivf_flat.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -10,6 +10,7 @@
#include <cuvs/neighbors/ivf_flat.hpp>
#include <dlpack/dlpack.h>
#include <raft/core/error.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/serialize.hpp>

#include "../core/exceptions.hpp"
Expand Down Expand Up @@ -396,9 +397,12 @@ extern "C" cuvsError_t cuvsMultiGpuIvfFlatDeserialize(cuvsResources_t res,
return cuvs::core::translate_exceptions([=] {
std::ifstream is(filename, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", filename); }
char dtype_string[4];
is.read(dtype_string, 4);
auto dtype = raft::detail::numpy_serializer::parse_descr(std::string(dtype_string, 4));
char dtype_string[4]{};
if (!is.read(dtype_string, sizeof(dtype_string))) {
RAFT_FAIL("Invalid or truncated index header in file %s", filename);
}
auto dtype =
raft::numpy_serializer::parse_descr(std::string(dtype_string, sizeof(dtype_string)));
is.close();

index->dtype.bits = dtype.itemsize * 8;
Expand Down Expand Up @@ -427,9 +431,12 @@ extern "C" cuvsError_t cuvsMultiGpuIvfFlatDistribute(cuvsResources_t res,
return cuvs::core::translate_exceptions([=] {
std::ifstream is(filename, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", filename); }
char dtype_string[4];
is.read(dtype_string, 4);
auto dtype = raft::detail::numpy_serializer::parse_descr(std::string(dtype_string, 4));
char dtype_string[4]{};
if (!is.read(dtype_string, sizeof(dtype_string))) {
RAFT_FAIL("Invalid or truncated index header in file %s", filename);
}
auto dtype =
raft::numpy_serializer::parse_descr(std::string(dtype_string, sizeof(dtype_string)));
is.close();

index->dtype.bits = dtype.itemsize * 8;
Expand Down
12 changes: 8 additions & 4 deletions c/src/neighbors/mg_ivf_pq.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -10,6 +10,7 @@
#include <cuvs/neighbors/ivf_pq.hpp>
#include <dlpack/dlpack.h>
#include <raft/core/error.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/serialize.hpp>

#include "../core/exceptions.hpp"
Expand Down Expand Up @@ -388,9 +389,12 @@ extern "C" cuvsError_t cuvsMultiGpuIvfPqDeserialize(cuvsResources_t res,
return cuvs::core::translate_exceptions([=] {
std::ifstream is(filename, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", filename); }
char dtype_string[4];
is.read(dtype_string, 4);
auto dtype = raft::detail::numpy_serializer::parse_descr(std::string(dtype_string, 4));
char dtype_string[4]{};
if (!is.read(dtype_string, sizeof(dtype_string))) {
RAFT_FAIL("Invalid or truncated index header in file %s", filename);
}
auto dtype =
raft::numpy_serializer::parse_descr(std::string(dtype_string, sizeof(dtype_string)));
is.close();

index->dtype.bits = dtype.itemsize * 8;
Expand Down
6 changes: 3 additions & 3 deletions cpp/cmake/thirdparty/get_raft.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# =============================================================================
# cmake-format: off
# SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
# cmake-format: on

# Use RAPIDS_VERSION_MAJOR_MINOR from rapids_config.cmake
set(RAFT_VERSION "${RAPIDS_VERSION_MAJOR_MINOR}")
set(RAFT_FORK "rapidsai")
set(RAFT_PINNED_TAG "${rapids-cmake-checkout-tag}")
set(RAFT_FORK "julianmi")
set(RAFT_PINNED_TAG "expose-public-npy-helpers")
Comment thread
julianmi marked this conversation as resolved.

function(find_and_configure_raft)
set(oneValueArgs VERSION FORK PINNED_TAG BUILD_STATIC_DEPS ENABLE_NVTX ENABLE_MNMG_DEPENDENCIES CLONE_ON_PIN)
Expand Down
7 changes: 4 additions & 3 deletions cpp/include/cuvs/neighbors/cagra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <raft/core/host_mdspan.hpp>
#include <raft/core/mdspan.hpp>
#include <raft/core/mdspan_types.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/resource/stream_view.hpp>
#include <raft/core/serialize.hpp>

Expand Down Expand Up @@ -764,7 +765,7 @@ struct index : cuvs::neighbors::index {
if (lseek(fd.get(), 0, SEEK_SET) == -1) {
RAFT_FAIL("Failed to seek to beginning of dataset file");
}
auto header = raft::detail::numpy_serializer::read_header(stream);
auto header = raft::numpy_serializer::read_header(stream);
RAFT_EXPECTS(header.shape.size() == 2,
"Dataset file should be 2D, got %zu dimensions",
header.shape.size());
Expand Down Expand Up @@ -799,7 +800,7 @@ struct index : cuvs::neighbors::index {
if (lseek(fd.get(), 0, SEEK_SET) == -1) {
RAFT_FAIL("Failed to seek to beginning of graph file");
}
auto header = raft::detail::numpy_serializer::read_header(stream);
auto header = raft::numpy_serializer::read_header(stream);
RAFT_EXPECTS(
header.shape.size() == 2, "Graph file should be 2D, got %zu dimensions", header.shape.size());

Expand Down Expand Up @@ -840,7 +841,7 @@ struct index : cuvs::neighbors::index {
if (lseek(fd.get(), 0, SEEK_SET) == -1) {
RAFT_FAIL("Failed to seek to beginning of mapping file");
}
auto header = raft::detail::numpy_serializer::read_header(stream);
auto header = raft::numpy_serializer::read_header(stream);
RAFT_EXPECTS(header.shape.size() == 1,
"Mapping file should be 1D, got %zu dimensions",
header.shape.size());
Expand Down
9 changes: 5 additions & 4 deletions cpp/include/cuvs/util/file_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <raft/core/error.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/serialize.hpp>

#include <algorithm>
Expand Down Expand Up @@ -187,12 +188,12 @@ std::pair<file_descriptor, size_t> create_numpy_file(const std::string& path,
file_descriptor fd(path, O_CREAT | O_RDWR | O_TRUNC, 0644);

// Build header
const auto dtype = raft::detail::numpy_serializer::get_numpy_dtype<T>();
const bool fortran_order = false;
const raft::detail::numpy_serializer::header_t header = {dtype, fortran_order, shape};
const auto dtype = raft::numpy_serializer::get_numpy_dtype<T>();
const bool fortran_order = false;
const raft::numpy_serializer::header_t header = {dtype, fortran_order, shape};

std::stringstream ss;
raft::detail::numpy_serializer::write_header(ss, header);
raft::numpy_serializer::write_header(ss, header);
std::string header_str = ss.str();
size_t header_size = header_str.size();

Expand Down
5 changes: 3 additions & 2 deletions cpp/src/neighbors/brute_force_serialize.cu
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

#include <cuvs/neighbors/brute_force.hpp>
#include <raft/core/copy.cuh>
#include <raft/core/host_mdarray.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/resources.hpp>
#include <raft/core/serialize.hpp>

Expand All @@ -24,7 +25,7 @@ void serialize(raft::resources const& handle,
RAFT_LOG_DEBUG(
"Saving brute force index, size %zu, dim %u", static_cast<size_t>(index.size()), index.dim());

auto dtype_string = raft::detail::numpy_serializer::get_numpy_dtype<T>().to_string();
auto dtype_string = raft::numpy_serializer::get_numpy_dtype<T>().to_string();
dtype_string.resize(4);
os << dtype_string;

Expand Down
5 changes: 3 additions & 2 deletions cpp/src/neighbors/detail/cagra/cagra_build.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <raft/core/host_mdarray.hpp>
#include <raft/core/host_mdspan.hpp>
#include <raft/core/logger.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/resource/cuda_stream.hpp>
#include <raft/util/integer_utils.hpp>

Expand Down Expand Up @@ -726,14 +727,14 @@ void ace_load_partition_dataset_from_disk(
std::ifstream is(reordered_dataset_path, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", reordered_dataset_path.c_str()); }
auto start_pos = is.tellg();
raft::detail::numpy_serializer::read_header(is);
raft::numpy_serializer::read_header(is);
core_header_size = static_cast<size_t>(is.tellg() - start_pos);
}
{
std::ifstream is(augmented_dataset_path, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", augmented_dataset_path.c_str()); }
auto start_pos = is.tellg();
raft::detail::numpy_serializer::read_header(is);
raft::numpy_serializer::read_header(is);
augmented_header_size = static_cast<size_t>(is.tellg() - start_pos);
}

Expand Down
3 changes: 2 additions & 1 deletion cpp/src/neighbors/detail/cagra/cagra_serialize.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <raft/core/logger.hpp>
#include <raft/core/mdarray.hpp>
#include <raft/core/mdspan_types.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/resource/cuda_stream.hpp>
#include <raft/core/serialize.hpp>
#include <raft/util/cudart_utils.hpp>
Expand Down Expand Up @@ -54,7 +55,7 @@ void serialize(raft::resources const& res,
RAFT_LOG_DEBUG(
"Saving CAGRA index, size %zu, dim %u", static_cast<size_t>(index_.size()), index_.dim());

std::string dtype_string = raft::detail::numpy_serializer::get_numpy_dtype<T>().to_string();
std::string dtype_string = raft::numpy_serializer::get_numpy_dtype<T>().to_string();
dtype_string.resize(4);
os << dtype_string;

Expand Down
8 changes: 4 additions & 4 deletions cpp/src/neighbors/detail/hnsw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <cuvs/util/file_io.hpp>

#include <raft/core/copy.cuh>
#include <raft/core/detail/mdspan_numpy_serializer.hpp>
#include <raft/core/host_mdspan.hpp>
#include <raft/core/logger.hpp>
#include <raft/core/numpy_serializer.hpp>
#include <raft/core/pinned_mdarray.hpp>
#include <raft/util/cudart_utils.hpp>

Expand Down Expand Up @@ -399,7 +399,7 @@ void serialize_to_hnswlib_from_disk(raft::resources const& res,
std::ifstream graph_stream(graph_path, std::ios::binary);
RAFT_EXPECTS(graph_stream.good(), "Failed to open graph file: %s", graph_path.c_str());

auto header = raft::detail::numpy_serializer::read_header(graph_stream);
auto header = raft::numpy_serializer::read_header(graph_stream);
graph_header_size = static_cast<size_t>(graph_stream.tellg());
RAFT_EXPECTS(
header.shape.size() == 2, "Graph file should be 2D, got %zu dimensions", header.shape.size());
Expand All @@ -419,7 +419,7 @@ void serialize_to_hnswlib_from_disk(raft::resources const& res,
std::ifstream dataset_stream(dataset_path, std::ios::binary);
RAFT_EXPECTS(dataset_stream.good(), "Failed to open dataset file: %s", dataset_path.c_str());

auto header = raft::detail::numpy_serializer::read_header(dataset_stream);
auto header = raft::numpy_serializer::read_header(dataset_stream);
dataset_header_size = static_cast<size_t>(dataset_stream.tellg());
RAFT_EXPECTS(header.shape.size() == 2,
"Dataset file should be 2D, got %zu dimensions",
Expand All @@ -439,7 +439,7 @@ void serialize_to_hnswlib_from_disk(raft::resources const& res,
std::ifstream mapping_stream(mapping_path, std::ios::binary);
RAFT_EXPECTS(mapping_stream.good(), "Failed to open mapping file: %s", mapping_path.c_str());

auto header = raft::detail::numpy_serializer::read_header(mapping_stream);
auto header = raft::numpy_serializer::read_header(mapping_stream);
label_header_size = static_cast<size_t>(mapping_stream.tellg());
RAFT_EXPECTS(header.shape.size() == 1,
"Mapping file should be 1D, got %zu dimensions",
Expand Down
Loading
Loading