Skip to content

Commit

Permalink
prefix new public api functions w/ cuvs
Browse files Browse the repository at this point in the history
  • Loading branch information
benfred committed Feb 1, 2024
1 parent 106fe15 commit 5708fbd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
36 changes: 18 additions & 18 deletions cpp/include/cuvs/neighbors/cagra_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ struct cagraIndexParams {
size_t nn_descent_niter;
};

typedef struct cagraIndexParams* cagraIndexParams_t;
typedef struct cagraIndexParams* cuvsCagraIndexParams_t;

/**
* @brief Allocate CAGRA Index params, and populate with default values
*
* @param[in] params cagraIndexParams_t to allocate
* @param[in] params cuvsCagraIndexParams_t to allocate
* @return cuvsError_t
*/
cuvsError_t cagraIndexParamsCreate(cagraIndexParams_t* params);
cuvsError_t cuvsCagraIndexParamsCreate(cuvsCagraIndexParams_t* params);

/**
* @brief De-allocate CAGRA Index params
*
* @param[in] params
* @return cuvsError_t
*/
cuvsError_t cagraIndexParamsDestroy(cagraIndexParams_t index);
cuvsError_t cuvsCagraIndexParamsDestroy(cuvsCagraIndexParams_t index);

/**
* @brief Enum to denote algorithm used to search CAGRA Index
Expand Down Expand Up @@ -140,23 +140,23 @@ struct cagraSearchParams {
uint64_t rand_xor_mask;
};

typedef struct cagraSearchParams* cagraSearchParams_t;
typedef struct cagraSearchParams* cuvsCagraSearchParams_t;

/**
* @brief Allocate CAGRA search params, and populate with default values
*
* @param[in] params cagraSearchParams_t to allocate
* @param[in] params cuvsCagraSearchParams_t to allocate
* @return cuvsError_t
*/
cuvsError_t cagraSearchParamsCreate(cagraSearchParams_t* params);
cuvsError_t cuvsCagraSearchParamsCreate(cuvsCagraSearchParams_t* params);

/**
* @brief De-allocate CAGRA search params
*
* @param[in] params
* @return cuvsError_t
*/
cuvsError_t cagraSearchParamsDestroy(cagraSearchParams_t params);
cuvsError_t cuvsCagraSearchParamsDestroy(cuvsCagraSearchParams_t params);

/**
* @brief Struct to hold address of cuvs::neighbors::cagra::index and its active trained dtype
Expand Down Expand Up @@ -205,8 +205,8 @@ cuvsError_t cagraIndexDestroy(cagraIndex_t index);
* DLManagedTensor dataset;
*
* // Create default index params
* cagraIndexParams_t params;
* cuvsError_t params_create_status = cagraIndexParamsCreate(&params);
* cuvsCagraIndexParams_t params;
* cuvsError_t params_create_status = cuvsCagraIndexParamsCreate(&params);
*
* // Create CAGRA index
* cagraIndex_t index;
Expand All @@ -216,19 +216,19 @@ cuvsError_t cagraIndexDestroy(cagraIndex_t index);
* cuvsError_t build_status = cagraBuild(res, params, &dataset, index);
*
* // de-allocate `params`, `index` and `res`
* cuvsError_t params_destroy_status = cagraIndexParamsDestroy(params);
* cuvsError_t params_destroy_status = cuvsCagraIndexParamsDestroy(params);
* cuvsError_t index_destroy_status = cagraIndexDestroy(index);
* cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);
* @endcode
*
* @param[in] res cuvsResources_t opaque C handle
* @param[in] params cagraIndexParams_t used to build CAGRA index
* @param[in] params cuvsCagraIndexParams_t used to build CAGRA index
* @param[in] dataset DLManagedTensor* training dataset
* @param[out] index cagraIndex_t Newly built CAGRA index
* @return cuvsError_t
*/
cuvsError_t cagraBuild(cuvsResources_t res,
cagraIndexParams_t params,
cuvsCagraIndexParams_t params,
DLManagedTensor* dataset,
cagraIndex_t index);

Expand Down Expand Up @@ -256,26 +256,26 @@ cuvsError_t cagraBuild(cuvsResources_t res,
* DLManagedTensor neighbors;
*
* // Create default search params
* cagraSearchParams_t params;
* cuvsError_t params_create_status = cagraSearchParamsCreate(&params);
* cuvsCagraSearchParams_t params;
* cuvsError_t params_create_status = cuvsCagraSearchParamsCreate(&params);
*
* // Search the `index` built using `cagraBuild`
* cuvsError_t search_status = cagraSearch(res, params, index, queries, neighbors, distances);
*
* // de-allocate `params` and `res`
* cuvsError_t params_destroy_status = cagraSearchParamsDestroy(params);
* cuvsError_t params_destroy_status = cuvsCagraSearchParamsDestroy(params);
* cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);
* @endcode
*
* @param[in] res cuvsResources_t opaque C handle
* @param[in] params cagraSearchParams_t used to search CAGRA index
* @param[in] params cuvsCagraSearchParams_t used to search CAGRA index
* @param[in] index cagraIndex which has been returned by `cagraBuild`
* @param[in] queries DLManagedTensor* queries dataset to search
* @param[out] neighbors DLManagedTensor* output `k` neighbors for queries
* @param[out] distances DLManagedTensor* output `k` distances for queries
*/
cuvsError_t cagraSearch(cuvsResources_t res,
cagraSearchParams_t params,
cuvsCagraSearchParams_t params,
cagraIndex_t index,
DLManagedTensor* queries,
DLManagedTensor* neighbors,
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/neighbors/cagra_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extern "C" cuvsError_t cagraIndexDestroy(cagraIndex_t index_c_ptr)
}

extern "C" cuvsError_t cagraBuild(cuvsResources_t res,
cagraIndexParams_t params,
cuvsCagraIndexParams_t params,
DLManagedTensor* dataset_tensor,
cagraIndex_t index)
{
Expand Down Expand Up @@ -159,7 +159,7 @@ extern "C" cuvsError_t cagraBuild(cuvsResources_t res,
}

extern "C" cuvsError_t cagraSearch(cuvsResources_t res,
cagraSearchParams_t params,
cuvsCagraSearchParams_t params,
cagraIndex_t index_c_ptr,
DLManagedTensor* queries_tensor,
DLManagedTensor* neighbors_tensor,
Expand Down Expand Up @@ -202,7 +202,7 @@ extern "C" cuvsError_t cagraSearch(cuvsResources_t res,
}
}

extern "C" cuvsError_t cagraIndexParamsCreate(cagraIndexParams_t* params)
extern "C" cuvsError_t cuvsCagraIndexParamsCreate(cuvsCagraIndexParams_t* params)
{
try {
*params = new cagraIndexParams{.intermediate_graph_degree = 128,
Expand All @@ -215,7 +215,7 @@ extern "C" cuvsError_t cagraIndexParamsCreate(cagraIndexParams_t* params)
}
}

extern "C" cuvsError_t cagraIndexParamsDestroy(cagraIndexParams_t params)
extern "C" cuvsError_t cuvsCagraIndexParamsDestroy(cuvsCagraIndexParams_t params)
{
try {
delete params;
Expand All @@ -225,7 +225,7 @@ extern "C" cuvsError_t cagraIndexParamsDestroy(cagraIndexParams_t params)
}
}

extern "C" cuvsError_t cagraSearchParamsCreate(cagraSearchParams_t* params)
extern "C" cuvsError_t cuvsCagraSearchParamsCreate(cuvsCagraSearchParams_t* params)
{
try {
*params = new cagraSearchParams{.itopk_size = 64,
Expand All @@ -239,7 +239,7 @@ extern "C" cuvsError_t cagraSearchParamsCreate(cagraSearchParams_t* params)
}
}

extern "C" cuvsError_t cagraSearchParamsDestroy(cagraSearchParams_t params)
extern "C" cuvsError_t cuvsCagraSearchParamsDestroy(cuvsCagraSearchParams_t params)
{
try {
delete params;
Expand Down
12 changes: 6 additions & 6 deletions cpp/test/neighbors/ann_cagra_c.cu
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ TEST(CagraC, BuildSearch)
cagraIndexCreate(&index);

// build index
cagraIndexParams_t build_params;
cagraIndexParamsCreate(&build_params);
cuvsCagraIndexParams_t build_params;
cuvsCagraIndexParamsCreate(&build_params);
cagraBuild(res, build_params, &dataset_tensor, index);

// create queries DLTensor
Expand Down Expand Up @@ -111,8 +111,8 @@ TEST(CagraC, BuildSearch)
distances_tensor.dl_tensor.strides = nullptr;

// search index
cagraSearchParams_t search_params;
cagraSearchParamsCreate(&search_params);
cuvsCagraSearchParams_t search_params;
cuvsCagraSearchParamsCreate(&search_params);
cagraSearch(res, search_params, index, &queries_tensor, &neighbors_tensor, &distances_tensor);

// verify output
Expand All @@ -126,8 +126,8 @@ TEST(CagraC, BuildSearch)
cudaFree(distances_d);

// de-allocate index and res
cagraSearchParamsDestroy(search_params);
cagraIndexParamsDestroy(build_params);
cuvsCagraSearchParamsDestroy(search_params);
cuvsCagraIndexParamsDestroy(build_params);
cagraIndexDestroy(index);
cuvsResourcesDestroy(res);
}

0 comments on commit 5708fbd

Please sign in to comment.