According to clGetDeviceInfo’s reference page CL_DEVICE_VENDOR_ID could be the PCIe ID, is it guarranteed that this will be the same number that cuDeviceGetAttribute returns with CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID?
If you post some quick sample code, I’ll compile/run it when I get a chance – I have 2 GPUs on my system so I might be able to give you a response if they match up, or test your code on at least a dual-GPU system and see if it matches or not.
After testing the code below the vendor id is 4318, I think it was 0 once… so they’re not the always the same.
#include <stdio.h>
#include <stdlib.h>
#include <CL/cl.h>
#include <cuda.h> /* is not the same path on every system */
/* gcc -Wall -o test test.c -lOpenCL -lcuda */
int main(int argc, char **argv)
{
int i, cl_devcnt = 0;
cl_uint n_platf, n_dev, n_entries=16;
cl_platform_id platf_ids[16];
cl_device_id dev_ids[16];
clGetPlatformIDs(n_entries, platf_ids, &n_platf);
printf("opencl devices:\n");
for(i=0;i<n_platf;i++)
{
if(clGetDeviceIDs(platf_ids[i],CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR,16,dev_ids+cl_devcnt,&n_dev));
cl_devcnt+=n_dev;
}
char name[256];
for(i=0;i<cl_devcnt;i++)
{
clGetDeviceInfo(dev_ids[i], CL_DEVICE_NAME, sizeof(name), name, NULL);
cl_uint vid;
clGetDeviceInfo(dev_ids[i], CL_DEVICE_VENDOR_ID, sizeof(vid), &vid, NULL);
printf("\tname: %s, vendor id: %u\n", name, vid);
}
int cu_devcnt, pci_id;
cuInit(0);
cuDeviceGetCount(&cu_devcnt);
printf("cuda devices:\n");
for(i=0;i<cu_devcnt;i++)
{
cuDeviceGetName(name,sizeof(name),i);
cuDeviceGetAttribute(&pci_id, 34/*pci_device_id*/, i);
printf("\tname: %s, pci device id: %d\n", name, pci_id);
}
return 0;
}
sample output:
opencl devices:
name: GeForce GTX 660 Ti, vendor id: 4318
cuda devices:
name: GeForce GTX 660 Ti, pci device id: 0
Here’s my results in Win 7 x64, CUDA 4.2:
opencl devices:
name: GeForce GTX TITAN, vendor id: 4318
name: GeForce GT 640, vendor id: 4318
cuda devices:
name: GeForce GTX TITAN, pci device id: 0
name: GeForce GT 640, pci device id: 0
I can’t see of a way to correlate OpenCL / CUDA devices because CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID is definitely not the vendor ID, and OpenCL doesn’t seem to have a way of polling for PCI bus ID, which CUDA does… so I’m a bit at a loss as well on that front.
I tried this approach:
http://developer.download.nvidia.com/compute/cuda/4_2/rel/toolkit/docs/online/group__CUDART__DEVICE_g5aa4f47938af8276f08074d09b7d520c.html
but I get the same results as your code. FWIW, I’m posting the code using that approach on the next post.
See also this post, where another person also got a result of 0 for the same call:
https://devtalk.nvidia.com/default/topic/540442/trying-to-get-gpudirect-rdma-working-/
Here’s the modified approach w/ the syntax posted above:
#include <stdio.h>
#include <stdlib.h>
#include <CL\cl.h>
#include <cuda.h> /* is not the same path on every system */
/* gcc -Wall -o test test.c -lOpenCL -lcuda */
int main(int argc, char **argv)
{
int i, cl_devcnt = 0;
cl_uint n_platf, n_dev, n_entries=16;
cl_platform_id platf_ids[16];
cl_device_id dev_ids[16];
clGetPlatformIDs(n_entries, platf_ids, &n_platf);
printf("opencl devices:\n");
for(i=0;i<n_platf;i++)
{
if(clGetDeviceIDs(platf_ids[i],CL_DEVICE_TYPE_GPU|CL_DEVICE_TYPE_ACCELERATOR,16,dev_ids+cl_devcnt,&n_dev));
cl_devcnt+=n_dev;
}
char name[256];
for(i=0;i<n_dev;i++)
{
clGetDeviceInfo(dev_ids[i], CL_DEVICE_NAME, sizeof(name), name, NULL);
cl_uint vid;
clGetDeviceInfo(dev_ids[i], CL_DEVICE_VENDOR_ID, sizeof(vid), &vid, NULL);
printf("\tname: %s, vendor id: %u\n", name, vid);
}
int cu_devcnt; //, pci_id;
cuInit(0);
cuDeviceGetCount(&cu_devcnt);
printf("cuda devices:\n");
cudaDeviceProp prop;
for(i=0;i<cu_devcnt;i++)
{
if (cudaGetDeviceProperties(&prop, i) == cudaSuccess) {
printf("\tname: %s, pci device id: %d\n\n", prop.name, prop.pciDeviceID);
}
// cuDeviceGetName(name,sizeof(name),i);
// cuDeviceGetAttribute(&pci_id, CU_DEVICE_ATTRIBUTE_PCI_DOMAIN_ID/*pci_device_id*/, i);
// printf("\tname: %s, pci device id: %d\n", name, pci_id);
}
return 0;
}
I also tried to use pciDomainID, but that comes out as 0 in my case as well, the only one that reports something different under CUDA is CU_DEVICE_ATTRIBUTE_PCI_BUS_ID (or pciBusID, in the code above)