Skip to content

Commit 3620ffa

Browse files
authored
Merge pull request #283 from notoraptor/master
Code added to get PCI Bus ID from a CUDA device.
2 parents a0491d1 + 2d6ee2a commit 3620ffa

6 files changed

Lines changed: 53 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Build
12
build
23
Debug
34
Release

pygpu/gpuarray.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ cdef extern from "gpuarray/buffer.h":
8787
int GA_CTX_DISABLE_ALLOCATION_CACHE
8888

8989
int GA_CTX_PROP_DEVNAME
90+
int GA_CTX_PROP_PCIBUSID
9091
int GA_CTX_PROP_MAXLSIZE
9192
int GA_CTX_PROP_LMEMSIZE
9293
int GA_CTX_PROP_NUMPROCS

pygpu/gpuarray.pyx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,19 @@ cdef class GpuContext:
10161016
free(tmp)
10171017
return res
10181018

1019+
property pcibusid:
1020+
"Device PCI Bus ID for this context"
1021+
def __get__(self):
1022+
cdef char *tmp
1023+
cdef unicode res
1024+
1025+
ctx_property(self, GA_CTX_PROP_PCIBUSID, &tmp)
1026+
try:
1027+
res = tmp.decode('ascii')
1028+
finally:
1029+
free(tmp)
1030+
return res
1031+
10191032
property maxlsize:
10201033
"Maximum size of thread block (local size) for this context"
10211034
def __get__(self):

src/gpuarray/buffer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,15 @@ GPUARRAY_PUBLIC gpucontext *gpukernel_context(gpukernel *k);
680680
*/
681681
#define GA_CTX_PROP_COMM_OPS 18
682682

683+
/**
684+
* Get the device PCI Bus ID for the context.
685+
*
686+
* \note The returned string is allocated and must be freed by the caller.
687+
*
688+
* Type: `char *`
689+
*/
690+
#define GA_CTX_PROP_PCIBUSID 19
691+
683692
/* Start at 512 for GA_BUFFER_PROP_ */
684693
#define GA_BUFFER_PROP_START 512
685694

src/gpuarray_buffer_cuda.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,30 @@ static int cuda_property(gpucontext *c, gpudata *buf, gpukernel *k, int prop_id,
15021502
*((char **)res) = s;
15031503
cuda_exit(ctx);
15041504
return GA_NO_ERROR;
1505+
1506+
case GA_CTX_PROP_PCIBUSID:
1507+
cuda_enter(ctx);
1508+
ctx->err = cuCtxGetDevice(&id);
1509+
if (ctx->err != CUDA_SUCCESS) {
1510+
cuda_exit(ctx);
1511+
return GA_IMPL_ERROR;
1512+
}
1513+
s = malloc(13);
1514+
if (s == NULL) {
1515+
cuda_exit(ctx);
1516+
return GA_MEMORY_ERROR;
1517+
}
1518+
ctx->err = cuDeviceGetPCIBusId(s, 13, id);
1519+
if (ctx->err != CUDA_SUCCESS) {
1520+
/* PS: in GA_CTX_PROP_DEVNAME above, s is not freed here.
1521+
* I think it should be freed, isn't it ? */
1522+
free(s);
1523+
cuda_exit(ctx);
1524+
return GA_IMPL_ERROR;
1525+
}
1526+
*((char **)res) = s;
1527+
cuda_exit(ctx);
1528+
return GA_NO_ERROR;
15051529

15061530
case GA_CTX_PROP_MAXLSIZE:
15071531
cuda_enter(ctx);

src/gpuarray_buffer_opencl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,11 @@ static int cl_property(gpucontext *c, gpudata *buf, gpukernel *k, int prop_id,
11721172
*((char **)res) = s;
11731173
return GA_NO_ERROR;
11741174

1175+
case GA_CTX_PROP_PCIBUSID:
1176+
/* For the moment, PCI Bus ID is not supported for OpenCL. */
1177+
*((void **)res) = NULL;
1178+
return GA_DEVSUP_ERROR;
1179+
11751180
case GA_CTX_PROP_MAXLSIZE:
11761181
ctx->err = clGetContextInfo(ctx->ctx, CL_CONTEXT_DEVICES, sizeof(id),
11771182
&id, NULL);

0 commit comments

Comments
 (0)