Skip to content

Commit 42f5ec5

Browse files
authored
Merge pull request #350 from YonatanNachum/cuda_13_fix
Fix use of cuCtxCreate with Cuda 13.0 and newer
2 parents 943db6a + f95933c commit 42f5ec5

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/cuda_loader.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ CUresult (*p_cuDeviceGetCount)(int *) = NULL;
1010
CUresult (*p_cuDeviceGet)(CUdevice *, int) = NULL;
1111
CUresult (*p_cuDeviceGetAttribute)(int *, CUdevice_attribute, CUdevice) = NULL;
1212
CUresult (*p_cuDeviceGetName)(char *, int, CUdevice) = NULL;
13+
#if CUDA_VER >= 13000
14+
CUresult (*p_cuCtxCreate)(CUcontext *, CUctxCreateParams *, unsigned int, CUdevice) = NULL;
15+
#else
1316
CUresult (*p_cuCtxCreate)(CUcontext *, unsigned int, CUdevice) = NULL;
17+
#endif
1418
CUresult (*p_cuDevicePrimaryCtxRetain)(CUcontext *, CUdevice) = NULL;
1519
CUresult (*p_cuCtxSetCurrent)(CUcontext) = NULL;
1620
CUresult (*p_cuCtxDestroy)(CUcontext) = NULL;

src/cuda_loader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ extern CUresult (*p_cuDeviceGetCount)(int *);
3030
extern CUresult (*p_cuDeviceGet)(CUdevice *, int);
3131
extern CUresult (*p_cuDeviceGetAttribute)(int *, CUdevice_attribute, CUdevice);
3232
extern CUresult (*p_cuDeviceGetName)(char *, int, CUdevice);
33+
#if CUDA_VER >= 13000
34+
extern CUresult (*p_cuCtxCreate)(CUcontext *, CUctxCreateParams *, unsigned int, CUdevice);
35+
#else
3336
extern CUresult (*p_cuCtxCreate)(CUcontext *, unsigned int, CUdevice);
37+
#endif
3438
extern CUresult (*p_cuDevicePrimaryCtxRetain)(CUcontext *, CUdevice);
3539
extern CUresult (*p_cuCtxSetCurrent)(CUcontext);
3640
extern CUresult (*p_cuCtxDestroy)(CUcontext);
@@ -61,4 +65,4 @@ void unload_cuda_library(void);
6165
}
6266
#endif
6367

64-
#endif // CUDA_LOADER_H
68+
#endif // CUDA_LOADER_H

src/cuda_memory.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
22
/*
3-
* Copyright 2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2023-2025 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#include <stdio.h>
@@ -96,7 +96,11 @@ static int init_gpu(struct cuda_memory_ctx *ctx)
9696
printf("creating CUDA Ctx\n");
9797

9898
/* Create context */
99+
#if CUDA_VER >= 13000
100+
error = p_cuCtxCreate(&ctx->cuContext, NULL, CU_CTX_MAP_HOST, ctx->cuDevice);
101+
#else
99102
error = p_cuCtxCreate(&ctx->cuContext, CU_CTX_MAP_HOST, ctx->cuDevice);
103+
#endif
100104
if (error != CUDA_SUCCESS) {
101105
printf("cuCtxCreate() error=%d\n", error);
102106
return FAILURE;

0 commit comments

Comments
 (0)