Skip to content

Commit 1c2a076

Browse files
authored
[MLIR][CUDA] Update export macros in CudaRuntimeWrappers (#73932)
This fixes a few issues present in the current version: 1) The macro doesn't enforce the default visibility on exported functions, causing compilation to fail when using `-fvisibility=hidden` 2) Not all functions are exported 3) Sometimes the macro ended up weirdly interleaved with `extern "C"` declarations
1 parent 10b44fb commit 1c2a076

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#ifdef _WIN32
3131
#define MLIR_CUDA_WRAPPERS_EXPORT __declspec(dllexport)
3232
#else
33-
#define MLIR_CUDA_WRAPPERS_EXPORT
33+
#define MLIR_CUDA_WRAPPERS_EXPORT __attribute__((visibility("default")))
3434
#endif // _WIN32
3535

3636
#define CUDA_REPORT_IF_ERROR(expr) \
@@ -226,43 +226,44 @@ extern "C" MLIR_CUDA_WRAPPERS_EXPORT void mgpuEventDestroy(CUevent event) {
226226
CUDA_REPORT_IF_ERROR(cuEventDestroy(event));
227227
}
228228

229-
extern MLIR_CUDA_WRAPPERS_EXPORT "C" void mgpuEventSynchronize(CUevent event) {
229+
extern "C" MLIR_CUDA_WRAPPERS_EXPORT void mgpuEventSynchronize(CUevent event) {
230230
CUDA_REPORT_IF_ERROR(cuEventSynchronize(event));
231231
}
232232

233-
extern MLIR_CUDA_WRAPPERS_EXPORT "C" void mgpuEventRecord(CUevent event,
233+
extern "C" MLIR_CUDA_WRAPPERS_EXPORT void mgpuEventRecord(CUevent event,
234234
CUstream stream) {
235235
CUDA_REPORT_IF_ERROR(cuEventRecord(event, stream));
236236
}
237237

238-
extern "C" void *mgpuMemAlloc(uint64_t sizeBytes, CUstream /*stream*/,
239-
bool /*isHostShared*/) {
238+
extern "C" MLIR_CUDA_WRAPPERS_EXPORT void *
239+
mgpuMemAlloc(uint64_t sizeBytes, CUstream /*stream*/, bool /*isHostShared*/) {
240240
ScopedContext scopedContext;
241241
CUdeviceptr ptr = 0;
242242
if (sizeBytes != 0)
243243
CUDA_REPORT_IF_ERROR(cuMemAlloc(&ptr, sizeBytes));
244244
return reinterpret_cast<void *>(ptr);
245245
}
246246

247-
extern "C" void mgpuMemFree(void *ptr, CUstream /*stream*/) {
247+
extern "C" MLIR_CUDA_WRAPPERS_EXPORT void mgpuMemFree(void *ptr,
248+
CUstream /*stream*/) {
248249
CUDA_REPORT_IF_ERROR(cuMemFree(reinterpret_cast<CUdeviceptr>(ptr)));
249250
}
250251

251-
extern "C" void mgpuMemcpy(void *dst, void *src, size_t sizeBytes,
252-
CUstream stream) {
252+
extern "C" MLIR_CUDA_WRAPPERS_EXPORT void
253+
mgpuMemcpy(void *dst, void *src, size_t sizeBytes, CUstream stream) {
253254
CUDA_REPORT_IF_ERROR(cuMemcpyAsync(reinterpret_cast<CUdeviceptr>(dst),
254255
reinterpret_cast<CUdeviceptr>(src),
255256
sizeBytes, stream));
256257
}
257258

258-
extern "C" void mgpuMemset32(void *dst, unsigned int value, size_t count,
259-
CUstream stream) {
259+
extern "C" MLIR_CUDA_WRAPPERS_EXPORT void
260+
mgpuMemset32(void *dst, unsigned int value, size_t count, CUstream stream) {
260261
CUDA_REPORT_IF_ERROR(cuMemsetD32Async(reinterpret_cast<CUdeviceptr>(dst),
261262
value, count, stream));
262263
}
263264

264-
extern "C" void mgpuMemset16(void *dst, unsigned short value, size_t count,
265-
CUstream stream) {
265+
extern "C" MLIR_CUDA_WRAPPERS_EXPORT void
266+
mgpuMemset16(void *dst, unsigned short value, size_t count, CUstream stream) {
266267
CUDA_REPORT_IF_ERROR(cuMemsetD16Async(reinterpret_cast<CUdeviceptr>(dst),
267268
value, count, stream));
268269
}

0 commit comments

Comments
 (0)