diff src/os/linux/vm/gpu_linux.cpp @ 13828:5c8a3c09397b

Add additional device checks and compute capability checks for CUDA devices found on Linux.
author S.Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>
date Thu, 30 Jan 2014 17:49:56 -0500
parents 49db2c1e3bee
children 51584f76462d
line wrap: on
line diff
--- a/src/os/linux/vm/gpu_linux.cpp	Thu Jan 30 21:11:38 2014 +0100
+++ b/src/os/linux/vm/gpu_linux.cpp	Thu Jan 30 17:49:56 2014 -0500
@@ -34,6 +34,8 @@
 static unsigned int nvidia_vendor_id = 0x10de;
 static unsigned int amd_vendor_id = 0x1002;
 
+#define PCI_DRIVER_NAME_START_POS 255
+
 jobject gpu::probe_gpus(JNIEnv* env) {
   bool hsail = false;
   bool ptx = false;
@@ -52,6 +54,9 @@
   unsigned int bus_num_devfn_ign;
   unsigned int vendor;
   unsigned int device;
+  const char *driver_name_string = "nvidia";
+  const int driver_name_string_len = strlen(driver_name_string);
+
   if (pci_devices == NULL) {
     tty->print_cr("*** Failed to open /proc/bus/pci/devices");
     return NULL;
@@ -59,13 +64,16 @@
 
   while (fgets(contents, sizeof(contents)-1, pci_devices)) {
     sscanf(contents, "%04x%04x%04x", &bus_num_devfn_ign, &vendor, &device);
-    /* Break after finding the first GPU device. */
     if (vendor == nvidia_vendor_id) {
-      if (TraceGPUInteraction) {
-        tty->print_cr("Found supported nVidia GPU: vendor=0x%04x, device=0x%04x", vendor, device);
-      }
-      if (!ptx && gpu::Ptx::register_natives(env)) {
-        ptx = true;
+      /* Check if this device is registered to be using nvidia driver */
+      if (strncmp(&contents[PCI_DRIVER_NAME_START_POS],
+                  driver_name_string, driver_name_string_len) == 0) {
+        if (TraceGPUInteraction) {
+          tty->print_cr("Found supported nVidia device [vendor=0x%04x, device=0x%04x]", vendor, device);
+        }
+        if (!ptx && gpu::Ptx::register_natives(env)) {
+          ptx = true;
+        }
       }
     }
   }