@@ -529,7 +529,7 @@ static void make_host_standard_dataset_view(raft::resources*,
529529}
530530
531531template <typename T>
532- static void attach_dataset (raft::resources* res_ptr,
532+ static void update_dataset (raft::resources* res_ptr,
533533 cuvsDataset_t device_padded_dataset,
534534 cuvsCagraIndex_t index)
535535{
@@ -542,7 +542,7 @@ static void attach_dataset(raft::resources* res_ptr,
542542 auto * box = reinterpret_cast <sg_cagra_c_api_index_box*>(index->addr );
543543 RAFT_EXPECTS (device_padded_dataset->mem_type == CUVS_DATASET_MEM_TYPE_DEVICE &&
544544 device_padded_dataset->layout == CUVS_DATASET_LAYOUT_PADDED ,
545- " cuvsCagraAttachDataset : dataset must be device padded" );
545+ " cuvsCagraUpdateDataset : dataset must be device padded" );
546546
547547 using owner_t = cuvs::neighbors::device_padded_dataset<T, int64_t >;
548548 using view_t = cuvs::neighbors::device_padded_dataset_view<T, int64_t >;
@@ -552,7 +552,8 @@ static void attach_dataset(raft::resources* res_ptr,
552552 " cuvsCagraUpdateDataset: null index handle" ,
553553 " cuvsCagraUpdateDataset: host index layout is allowed for this operation" ,
554554 [&](auto & idx) {
555- auto padded_idx = cuvs::neighbors::cagra::attach_dataset (*res_ptr, idx, padded_view);
555+ auto padded_idx =
556+ cuvs::neighbors::cagra::update_dataset (*res_ptr, std::move (idx), padded_view);
556557 auto * holder =
557558 new cuvs_cagra_c_api_index_lifetime_holder<T, view_t >{std::move (padded_idx)};
558559 destroy_sg_cagra_c_api_box (index->addr );
@@ -562,53 +563,6 @@ static void attach_dataset(raft::resources* res_ptr,
562563 });
563564}
564565
565- template <typename T>
566- static void update_device_dataset_same_layout (raft::resources* res_ptr,
567- cuvsDataset_t device_dataset,
568- cuvsCagraIndex_t index)
569- {
570- RAFT_EXPECTS (device_dataset != nullptr , " cuvsCagraUpdateDataset: null dataset" );
571- RAFT_EXPECTS (index != nullptr , " cuvsCagraUpdateDataset: null index handle" );
572- RAFT_EXPECTS (index->addr != 0 , " cuvsCagraUpdateDataset: null index storage" );
573- RAFT_EXPECTS (device_dataset->addr != 0 , " cuvsCagraUpdateDataset: null dataset storage" );
574-
575- auto * box = reinterpret_cast <sg_cagra_c_api_index_box*>(index->addr );
576- if (box->layout == sg_cagra_c_api_index_box::dataset_layout::device_padded) {
577- RAFT_EXPECTS (device_dataset->mem_type == CUVS_DATASET_MEM_TYPE_DEVICE &&
578- device_dataset->layout == CUVS_DATASET_LAYOUT_PADDED ,
579- " cuvsCagraUpdateDeviceDatasetSameLayout: device-padded index "
580- " requires a "
581- " device-padded dataset" );
582- using owner_t = cuvs::neighbors::device_padded_dataset<T, int64_t >;
583- using view_t = cuvs::neighbors::device_padded_dataset_view<T, int64_t >;
584- with_dataset_view<owner_t , view_t >(device_dataset, [&](auto const & dataset_view) {
585- auto * idx =
586- reinterpret_cast <cuvs::neighbors::cagra::device_padded_index<T, uint32_t >*>(box->index_ptr );
587- RAFT_EXPECTS (idx != nullptr , " cuvsCagraUpdateDataset: null index handle" );
588- idx->update_device_dataset_same_layout (*res_ptr, dataset_view);
589- });
590- } else if (box->layout == sg_cagra_c_api_index_box::dataset_layout::device_standard) {
591- RAFT_EXPECTS (device_dataset->mem_type == CUVS_DATASET_MEM_TYPE_DEVICE &&
592- device_dataset->layout == CUVS_DATASET_LAYOUT_STANDARD ,
593- " cuvsCagraUpdateDeviceDatasetSameLayout: device-standard "
594- " index requires a "
595- " device-standard dataset" );
596- using owner_t = cuvs::neighbors::device_standard_dataset<T, int64_t >;
597- using view_t = cuvs::neighbors::device_standard_dataset_view<T, int64_t >;
598- with_dataset_view<owner_t , view_t >(device_dataset, [&](auto const & dataset_view) {
599- auto * idx =
600- reinterpret_cast <cuvs::neighbors::cagra::device_standard_index<T, uint32_t >*>(box->index_ptr );
601- RAFT_EXPECTS (idx != nullptr , " cuvsCagraUpdateDataset: null index handle" );
602- idx->update_device_dataset_same_layout (*res_ptr, dataset_view);
603- });
604- } else {
605- RAFT_FAIL (
606- " cuvsCagraUpdateDataset: C++ "
607- " update_device_dataset_same_layout "
608- " requires a device index and dataset" );
609- }
610- }
611-
612566static void _set_graph_build_params (
613567 std::variant<std::monostate,
614568 cuvs::neighbors::cagra::graph_build_params::ivf_pq_params,
@@ -716,7 +670,8 @@ void _from_args(cuvsResources_t res,
716670 auto dataset_view = cuvs::neighbors::make_device_padded_dataset_view (*res_ptr, mds);
717671 auto * raw = new cuvs::neighbors::cagra::device_padded_index<T, uint32_t >(
718672 *res_ptr, metric);
719- raw->update_device_dataset_same_layout (*res_ptr, dataset_view);
673+ *raw =
674+ cuvs::neighbors::cagra::update_dataset (*res_ptr, std::move (*raw), dataset_view);
720675 update_graph_from_dlpack (raw);
721676 wrap_CPP_index_in_lifetime_holder_and_bind_to_C_index<
722677 T,
@@ -726,7 +681,8 @@ void _from_args(cuvsResources_t res,
726681 auto dataset_view = cuvs::neighbors::make_device_standard_dataset_view (mds);
727682 auto * raw = new cuvs::neighbors::cagra::device_standard_index<T, uint32_t >(
728683 *res_ptr, metric);
729- raw->update_device_dataset_same_layout (*res_ptr, dataset_view);
684+ *raw =
685+ cuvs::neighbors::cagra::update_dataset (*res_ptr, std::move (*raw), dataset_view);
730686 update_graph_from_dlpack (raw);
731687 wrap_CPP_index_in_lifetime_holder_and_bind_to_C_index<
732688 T,
@@ -1584,7 +1540,7 @@ extern "C" cuvsError_t cuvsDatasetMakeStandardView(cuvsResources_t res,
15841540 });
15851541}
15861542
1587- static cuvsError_t dispatch_attach_dataset (cuvsResources_t res,
1543+ static cuvsError_t dispatch_update_dataset (cuvsResources_t res,
15881544 cuvsDataset_t device_padded_dataset,
15891545 cuvsCagraIndex_t index)
15901546{
@@ -1598,40 +1554,13 @@ static cuvsError_t dispatch_attach_dataset(cuvsResources_t res,
15981554 index->dtype .bits == device_padded_dataset->dtype .bits ,
15991555 " cuvsCagraUpdateDataset: dtype mismatch between index and dataset" );
16001556 if (index->dtype .code == kDLFloat && index->dtype .bits == 32 ) {
1601- attach_dataset<float >(res_ptr, device_padded_dataset, index);
1602- } else if (index->dtype .code == kDLFloat && index->dtype .bits == 16 ) {
1603- attach_dataset<half>(res_ptr, device_padded_dataset, index);
1604- } else if (index->dtype .code == kDLInt && index->dtype .bits == 8 ) {
1605- attach_dataset<int8_t >(res_ptr, device_padded_dataset, index);
1606- } else if (index->dtype .code == kDLUInt && index->dtype .bits == 8 ) {
1607- attach_dataset<uint8_t >(res_ptr, device_padded_dataset, index);
1608- } else {
1609- RAFT_FAIL (" Unsupported index dtype: %d and bits: %d" , index->dtype .code , index->dtype .bits );
1610- }
1611- });
1612- }
1613-
1614- static cuvsError_t dispatch_update_device_dataset_same_layout (cuvsResources_t res,
1615- cuvsDataset_t device_dataset,
1616- cuvsCagraIndex_t index)
1617- {
1618- return cuvs::core::translate_exceptions ([=] {
1619- auto * res_ptr = reinterpret_cast <raft::resources*>(res);
1620- RAFT_EXPECTS (index != nullptr , " cuvsCagraUpdateDataset: null index handle" );
1621- RAFT_EXPECTS (device_dataset != nullptr ,
1622- " cuvsCagraUpdateDataset: null dataset view" );
1623- RAFT_EXPECTS (index->dtype .code == device_dataset->dtype .code &&
1624- index->dtype .bits == device_dataset->dtype .bits ,
1625- " cuvsCagraUpdateDataset: dtype mismatch "
1626- " between index and dataset" );
1627- if (index->dtype .code == kDLFloat && index->dtype .bits == 32 ) {
1628- update_device_dataset_same_layout<float >(res_ptr, device_dataset, index);
1557+ update_dataset<float >(res_ptr, device_padded_dataset, index);
16291558 } else if (index->dtype .code == kDLFloat && index->dtype .bits == 16 ) {
1630- update_device_dataset_same_layout <half>(res_ptr, device_dataset , index);
1559+ update_dataset <half>(res_ptr, device_padded_dataset , index);
16311560 } else if (index->dtype .code == kDLInt && index->dtype .bits == 8 ) {
1632- update_device_dataset_same_layout <int8_t >(res_ptr, device_dataset , index);
1561+ update_dataset <int8_t >(res_ptr, device_padded_dataset , index);
16331562 } else if (index->dtype .code == kDLUInt && index->dtype .bits == 8 ) {
1634- update_device_dataset_same_layout <uint8_t >(res_ptr, device_dataset , index);
1563+ update_dataset <uint8_t >(res_ptr, device_padded_dataset , index);
16351564 } else {
16361565 RAFT_FAIL (" Unsupported index dtype: %d and bits: %d" , index->dtype .code , index->dtype .bits );
16371566 }
@@ -1656,12 +1585,7 @@ extern "C" cuvsError_t cuvsCagraUpdateDataset(cuvsResources_t res,
16561585 " cuvsCagraUpdateDataset: dtype mismatch between index and dataset" );
16571586 });
16581587 if (status != CUVS_SUCCESS ) { return status; }
1659-
1660- auto * box = reinterpret_cast <sg_cagra_c_api_index_box*>(index->addr );
1661- if (box->layout == sg_cagra_c_api_index_box::dataset_layout::device_padded) {
1662- return dispatch_update_device_dataset_same_layout (res, device_padded_dataset, index);
1663- }
1664- return dispatch_attach_dataset (res, device_padded_dataset, index);
1588+ return dispatch_update_dataset (res, device_padded_dataset, index);
16651589}
16661590
16671591/* *
0 commit comments