Skip to content

Commit ea5359b

Browse files
authored
Fix symbol export (#2052)
This PR adds symbol visibility controls to cuvs to avoid exporting weak symbols that it shouldn't. Contributes to rapidsai/build-infra#53 Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Robert Maynard (https://github.com/robertmaynard) - Divye Gala (https://github.com/divyegala) URL: #2052
1 parent ab35848 commit ea5359b

69 files changed

Lines changed: 639 additions & 350 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

c/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ set_target_properties(
115115
POSITION_INDEPENDENT_CODE ON
116116
INTERFACE_POSITION_INDEPENDENT_CODE ON
117117
EXPORT_NAME c_api
118+
CXX_VISIBILITY_PRESET hidden
119+
VISIBILITY_INLINES_HIDDEN ON
118120
)
119121

120122
# Setup the VERSION and SOVERSION of our library

c/include/cuvs/cluster/kmeans.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <dlpack/dlpack.h>
1111
#include <stdint.h>
1212

13+
#include <cuvs/core/export.h>
14+
1315
#ifdef __cplusplus
1416
extern "C" {
1517
#endif
@@ -211,7 +213,7 @@ typedef struct cuvsKMeansParams_v2* cuvsKMeansParams_v2_t;
211213
* @param[in] params cuvsKMeansParams_t to allocate
212214
* @return cuvsError_t
213215
*/
214-
cuvsError_t cuvsKMeansParamsCreate(cuvsKMeansParams_t* params);
216+
CUVS_EXPORT cuvsError_t cuvsKMeansParamsCreate(cuvsKMeansParams_t* params);
215217

216218
/**
217219
* @brief De-allocate KMeans params
@@ -222,7 +224,7 @@ cuvsError_t cuvsKMeansParamsCreate(cuvsKMeansParams_t* params);
222224
* @param[in] params
223225
* @return cuvsError_t
224226
*/
225-
cuvsError_t cuvsKMeansParamsDestroy(cuvsKMeansParams_t params);
227+
CUVS_EXPORT cuvsError_t cuvsKMeansParamsDestroy(cuvsKMeansParams_t params);
226228

227229
/**
228230
* @brief Allocate KMeans params
@@ -290,7 +292,7 @@ typedef enum { CUVS_KMEANS_TYPE_KMEANS = 0, CUVS_KMEANS_TYPE_KMEANS_BALANCED = 1
290292
* closest cluster center.
291293
* @param[out] n_iter Number of iterations run.
292294
*/
293-
cuvsError_t cuvsKMeansFit(cuvsResources_t res,
295+
CUVS_EXPORT cuvsError_t cuvsKMeansFit(cuvsResources_t res,
294296
cuvsKMeansParams_t params,
295297
DLManagedTensor* X,
296298
DLManagedTensor* sample_weight,
@@ -353,7 +355,7 @@ cuvsError_t cuvsKMeansFit_v2(cuvsResources_t res,
353355
* @param[out] inertia Sum of squared distances of samples to
354356
* their closest cluster center.
355357
*/
356-
cuvsError_t cuvsKMeansPredict(cuvsResources_t res,
358+
CUVS_EXPORT cuvsError_t cuvsKMeansPredict(cuvsResources_t res,
357359
cuvsKMeansParams_t params,
358360
DLManagedTensor* X,
359361
DLManagedTensor* sample_weight,
@@ -406,7 +408,7 @@ cuvsError_t cuvsKMeansPredict_v2(cuvsResources_t res,
406408
* @param[out] cost Resulting cluster cost
407409
*
408410
*/
409-
cuvsError_t cuvsKMeansClusterCost(cuvsResources_t res,
411+
CUVS_EXPORT cuvsError_t cuvsKMeansClusterCost(cuvsResources_t res,
410412
DLManagedTensor* X,
411413
DLManagedTensor* centroids,
412414
double* cost);

c/include/cuvs/core/all.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

1111
#include <cuvs/core/c_config.h>
12+
#include <cuvs/core/export.h>
1213
#include <cuvs/core/c_api.h>
1314

1415
#include <cuvs/cluster/kmeans.h>

c/include/cuvs/core/c_api.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -10,6 +10,8 @@
1010
#include <stdbool.h>
1111
#include <stdint.h>
1212

13+
#include <cuvs/core/export.h>
14+
1315
#ifdef __cplusplus
1416
extern "C" {
1517
#endif
@@ -27,13 +29,13 @@ typedef enum { CUVS_ERROR = 0, CUVS_SUCCESS = 1 } cuvsError_t;
2729
/** @brief Returns a string describing the last seen error on this thread, or
2830
* NULL if the last function succeeded.
2931
*/
30-
const char* cuvsGetLastErrorText();
32+
CUVS_EXPORT const char* cuvsGetLastErrorText();
3133

3234
/**
3335
* @brief Sets a string describing an error seen on the thread. Passing NULL
3436
* clears any previously seen error message.
3537
*/
36-
void cuvsSetLastErrorText(const char* error);
38+
CUVS_EXPORT void cuvsSetLastErrorText(const char* error);
3739

3840
/** @} */
3941

@@ -58,11 +60,11 @@ typedef enum {
5860

5961
/** @brief Returns the current log level
6062
*/
61-
cuvsLogLevel_t cuvsGetLogLevel();
63+
CUVS_EXPORT cuvsLogLevel_t cuvsGetLogLevel();
6264

6365
/** @brief Sets the log level
6466
*/
65-
void cuvsSetLogLevel(cuvsLogLevel_t);
67+
CUVS_EXPORT void cuvsSetLogLevel(cuvsLogLevel_t);
6668

6769
/** @} */
6870

@@ -83,15 +85,15 @@ typedef uintptr_t cuvsResources_t;
8385
* @param[in] res cuvsResources_t opaque C handle
8486
* @return cuvsError_t
8587
*/
86-
cuvsError_t cuvsResourcesCreate(cuvsResources_t* res);
88+
CUVS_EXPORT cuvsError_t cuvsResourcesCreate(cuvsResources_t* res);
8789

8890
/**
8991
* @brief Destroy and de-allocate opaque C handle for C++ type `raft::resources`
9092
*
9193
* @param[in] res cuvsResources_t opaque C handle
9294
* @return cuvsError_t
9395
*/
94-
cuvsError_t cuvsResourcesDestroy(cuvsResources_t res);
96+
CUVS_EXPORT cuvsError_t cuvsResourcesDestroy(cuvsResources_t res);
9597

9698
/**
9799
* @brief Set cudaStream_t on cuvsResources_t to queue CUDA kernels on APIs
@@ -101,7 +103,7 @@ cuvsError_t cuvsResourcesDestroy(cuvsResources_t res);
101103
* @param[in] stream cudaStream_t stream to queue CUDA kernels
102104
* @return cuvsError_t
103105
*/
104-
cuvsError_t cuvsStreamSet(cuvsResources_t res, cudaStream_t stream);
106+
CUVS_EXPORT cuvsError_t cuvsStreamSet(cuvsResources_t res, cudaStream_t stream);
105107

106108
/**
107109
* @brief Get the cudaStream_t from a cuvsResources_t
@@ -110,15 +112,15 @@ cuvsError_t cuvsStreamSet(cuvsResources_t res, cudaStream_t stream);
110112
* @param[out] stream cudaStream_t stream to queue CUDA kernels
111113
* @return cuvsError_t
112114
*/
113-
cuvsError_t cuvsStreamGet(cuvsResources_t res, cudaStream_t* stream);
115+
CUVS_EXPORT cuvsError_t cuvsStreamGet(cuvsResources_t res, cudaStream_t* stream);
114116

115117
/**
116118
* @brief Syncs the current CUDA stream on the resources object
117119
*
118120
* @param[in] res cuvsResources_t opaque C handle
119121
* @return cuvsError_t
120122
*/
121-
cuvsError_t cuvsStreamSync(cuvsResources_t res);
123+
CUVS_EXPORT cuvsError_t cuvsStreamSync(cuvsResources_t res);
122124

123125
/**
124126
* @brief Get the id of the device associated with this cuvsResources_t
@@ -127,7 +129,7 @@ cuvsError_t cuvsStreamSync(cuvsResources_t res);
127129
* @param[out] device_id int the id of the device associated with res
128130
* @return cuvsError_t
129131
*/
130-
cuvsError_t cuvsDeviceIdGet(cuvsResources_t res, int* device_id);
132+
CUVS_EXPORT cuvsError_t cuvsDeviceIdGet(cuvsResources_t res, int* device_id);
131133

132134
/**
133135
* @brief Create an Initialized opaque C handle for C++ type `raft::device_resources_snmg`
@@ -136,7 +138,7 @@ cuvsError_t cuvsDeviceIdGet(cuvsResources_t res, int* device_id);
136138
* @param[in] res cuvsResources_t opaque C handle
137139
* @return cuvsError_t
138140
*/
139-
cuvsError_t cuvsMultiGpuResourcesCreate(cuvsResources_t* res);
141+
CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesCreate(cuvsResources_t* res);
140142

141143
/**
142144
* @brief Create an Initialized opaque C handle for C++ type `raft::device_resources_snmg`
@@ -146,7 +148,7 @@ cuvsError_t cuvsMultiGpuResourcesCreate(cuvsResources_t* res);
146148
* @param[in] device_ids DLManagedTensor* containing device IDs to use
147149
* @return cuvsError_t
148150
*/
149-
cuvsError_t cuvsMultiGpuResourcesCreateWithDeviceIds(cuvsResources_t* res,
151+
CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesCreateWithDeviceIds(cuvsResources_t* res,
150152
DLManagedTensor* device_ids);
151153

152154
/**
@@ -155,7 +157,7 @@ cuvsError_t cuvsMultiGpuResourcesCreateWithDeviceIds(cuvsResources_t* res,
155157
* @param[in] res cuvsResources_t opaque C handle
156158
* @return cuvsError_t
157159
*/
158-
cuvsError_t cuvsMultiGpuResourcesDestroy(cuvsResources_t res);
160+
CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesDestroy(cuvsResources_t res);
159161

160162
/**
161163
* @brief Set a memory pool on all devices managed by the multi-GPU resources
@@ -164,7 +166,7 @@ cuvsError_t cuvsMultiGpuResourcesDestroy(cuvsResources_t res);
164166
* @param[in] percent_of_free_memory Percent of free memory to allocate for the pool
165167
* @return cuvsError_t
166168
*/
167-
cuvsError_t cuvsMultiGpuResourcesSetMemoryPool(cuvsResources_t res, int percent_of_free_memory);
169+
CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesSetMemoryPool(cuvsResources_t res, int percent_of_free_memory);
168170
/** @} */
169171

170172
/**
@@ -181,7 +183,7 @@ cuvsError_t cuvsMultiGpuResourcesSetMemoryPool(cuvsResources_t res, int percent_
181183
* @param[in] bytes Size in bytes to allocate
182184
* @return cuvsError_t
183185
*/
184-
cuvsError_t cuvsRMMAlloc(cuvsResources_t res, void** ptr, size_t bytes);
186+
CUVS_EXPORT cuvsError_t cuvsRMMAlloc(cuvsResources_t res, void** ptr, size_t bytes);
185187

186188
/**
187189
* @brief Deallocates device memory using RMM
@@ -191,7 +193,7 @@ cuvsError_t cuvsRMMAlloc(cuvsResources_t res, void** ptr, size_t bytes);
191193
* @param[in] bytes Size in bytes to allocate
192194
* @return cuvsError_t
193195
*/
194-
cuvsError_t cuvsRMMFree(cuvsResources_t res, void* ptr, size_t bytes);
196+
CUVS_EXPORT cuvsError_t cuvsRMMFree(cuvsResources_t res, void* ptr, size_t bytes);
195197

196198
/**
197199
* @brief Switches the working memory resource to use the RMM pool memory resource, which will
@@ -207,30 +209,30 @@ cuvsError_t cuvsRMMFree(cuvsResources_t res, void* ptr, size_t bytes);
207209
* @param[in] managed Whether to use a managed memory resource as upstream resource or not
208210
* @return cuvsError_t
209211
*/
210-
cuvsError_t cuvsRMMPoolMemoryResourceEnable(int initial_pool_size_percent,
212+
CUVS_EXPORT cuvsError_t cuvsRMMPoolMemoryResourceEnable(int initial_pool_size_percent,
211213
int max_pool_size_percent,
212214
bool managed);
213215
/**
214216
* @brief Resets the memory resource to use the default memory resource (cuda_memory_resource)
215217
* @return cuvsError_t
216218
*/
217-
cuvsError_t cuvsRMMMemoryResourceReset();
219+
CUVS_EXPORT cuvsError_t cuvsRMMMemoryResourceReset();
218220

219221
/**
220222
* @brief Allocates pinned memory on the host using RMM
221223
* @param[out] ptr Pointer to allocated host memory
222224
* @param[in] bytes Size in bytes to allocate
223225
* @return cuvsError_t
224226
*/
225-
cuvsError_t cuvsRMMHostAlloc(void** ptr, size_t bytes);
227+
CUVS_EXPORT cuvsError_t cuvsRMMHostAlloc(void** ptr, size_t bytes);
226228

227229
/**
228230
* @brief Deallocates pinned memory on the host using RMM
229231
* @param[in] ptr Pointer to allocated host memory to free
230232
* @param[in] bytes Size in bytes to deallocate
231233
* @return cuvsError_t
232234
*/
233-
cuvsError_t cuvsRMMHostFree(void* ptr, size_t bytes);
235+
CUVS_EXPORT cuvsError_t cuvsRMMHostFree(void* ptr, size_t bytes);
234236

235237
/**
236238
* @brief Get the version of the cuVS library
@@ -239,7 +241,7 @@ cuvsError_t cuvsRMMHostFree(void* ptr, size_t bytes);
239241
* @param[out] patch Patch version
240242
* @return cuvsError_t
241243
*/
242-
cuvsError_t cuvsVersionGet(uint16_t* major, uint16_t* minor, uint16_t* patch);
244+
CUVS_EXPORT cuvsError_t cuvsVersionGet(uint16_t* major, uint16_t* minor, uint16_t* patch);
243245

244246
/**
245247
* @brief Copy a matrix
@@ -256,7 +258,7 @@ cuvsError_t cuvsVersionGet(uint16_t* major, uint16_t* minor, uint16_t* patch);
256258
* @param[in] src Pointer to DLManagedTensor to copy
257259
* @param[out] dst Pointer to DLManagedTensor to receive copy of data
258260
*/
259-
cuvsError_t cuvsMatrixCopy(cuvsResources_t res, DLManagedTensor* src, DLManagedTensor* dst);
261+
CUVS_EXPORT cuvsError_t cuvsMatrixCopy(cuvsResources_t res, DLManagedTensor* src, DLManagedTensor* dst);
260262

261263
/**
262264
* @brief Slices rows from a matrix
@@ -267,7 +269,7 @@ cuvsError_t cuvsMatrixCopy(cuvsResources_t res, DLManagedTensor* src, DLManagedT
267269
* @param[in] end Last row index to include in the output
268270
* @param[out] dst Pointer to DLManagedTensor to receive slice from matrix
269271
*/
270-
cuvsError_t cuvsMatrixSliceRows(
272+
CUVS_EXPORT cuvsError_t cuvsMatrixSliceRows(
271273
cuvsResources_t res, DLManagedTensor* src, int64_t start, int64_t end, DLManagedTensor* dst);
272274
/** @} */
273275

c/include/cuvs/core/export.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#pragma once
7+
8+
// Symbol visibility macros for cuVS shared libraries.
9+
// When CXX_VISIBILITY_PRESET is set to hidden, only symbols explicitly
10+
// marked with CUVS_EXPORT will be visible in the shared library.
11+
// CUVS_HIDDEN can be used to explicitly mark symbols as hidden.
12+
#if (defined(__GNUC__) && !defined(__MINGW32__) && !defined(__MINGW64__))
13+
#define CUVS_EXPORT __attribute__((visibility("default")))
14+
#define CUVS_HIDDEN __attribute__((visibility("hidden")))
15+
#else
16+
#define CUVS_EXPORT
17+
#define CUVS_HIDDEN
18+
#endif

c/include/cuvs/distance/distance.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/*
2-
* SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION.
2+
* SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
#pragma once
66

7+
#include <cuvs/core/export.h>
8+
79
#ifdef __cplusplus
810
extern "C" {
911
#endif

c/include/cuvs/distance/pairwise_distance.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <cuvs/core/c_api.h>
99
#include <cuvs/distance/distance.h>
1010

11+
#include <cuvs/core/export.h>
12+
1113
#ifdef __cplusplus
1214
extern "C" {
1315
#endif
@@ -45,7 +47,7 @@ extern "C" {
4547
* @param[in] metric distance to evaluate
4648
* @param[in] metric_arg metric argument (used for Minkowski distance)
4749
*/
48-
cuvsError_t cuvsPairwiseDistance(cuvsResources_t res,
50+
CUVS_EXPORT cuvsError_t cuvsPairwiseDistance(cuvsResources_t res,
4951
DLManagedTensor* x,
5052
DLManagedTensor* y,
5153
DLManagedTensor* dist,

c/include/cuvs/neighbors/all_neighbors.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <dlpack/dlpack.h>
1313
#include <stdint.h>
1414

15+
#include <cuvs/core/export.h>
16+
1517
#ifdef __cplusplus
1618
extern "C" {
1719
#endif
@@ -67,7 +69,7 @@ typedef struct cuvsAllNeighborsIndexParams* cuvsAllNeighborsIndexParams_t;
6769
*
6870
* @return cuvsError_t
6971
*/
70-
cuvsError_t cuvsAllNeighborsIndexParamsCreate(cuvsAllNeighborsIndexParams_t* index_params);
72+
CUVS_EXPORT cuvsError_t cuvsAllNeighborsIndexParamsCreate(cuvsAllNeighborsIndexParams_t* index_params);
7173

7274
/**
7375
* @brief Destroy an all-neighbors index parameters struct.
@@ -76,7 +78,7 @@ cuvsError_t cuvsAllNeighborsIndexParamsCreate(cuvsAllNeighborsIndexParams_t* ind
7678
*
7779
* @return cuvsError_t
7880
*/
79-
cuvsError_t cuvsAllNeighborsIndexParamsDestroy(cuvsAllNeighborsIndexParams_t index_params);
81+
CUVS_EXPORT cuvsError_t cuvsAllNeighborsIndexParamsDestroy(cuvsAllNeighborsIndexParams_t index_params);
8082

8183
/** @} */
8284

@@ -103,7 +105,7 @@ cuvsError_t cuvsAllNeighborsIndexParamsDestroy(cuvsAllNeighborsIndexParams_t ind
103105
* datasets, `n_clusters` must be 1 (no batching); `overlap_factor` is ignored.
104106
* Outputs always reside in device memory.
105107
*/
106-
cuvsError_t cuvsAllNeighborsBuild(cuvsResources_t res,
108+
CUVS_EXPORT cuvsError_t cuvsAllNeighborsBuild(cuvsResources_t res,
107109
cuvsAllNeighborsIndexParams_t params,
108110
DLManagedTensor* dataset,
109111
DLManagedTensor* indices,

0 commit comments

Comments
 (0)