changeset 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 8053c3ede984
children 4ca607fc94e0
files src/gpu/ptx/vm/gpu_ptx.cpp src/gpu/ptx/vm/gpu_ptx.hpp src/os/linux/vm/gpu_linux.cpp
diffstat 3 files changed, 49 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/gpu/ptx/vm/gpu_ptx.cpp	Thu Jan 30 21:11:38 2014 +0100
+++ b/src/gpu/ptx/vm/gpu_ptx.cpp	Thu Jan 30 17:49:56 2014 -0500
@@ -183,7 +183,34 @@
   }
 
   /* Get device attributes */
+  int minor, major;
   int unified_addressing;
+  float version = 0.0;
+
+  /* Get the compute capability of the device found */
+  status = _cuda_cu_device_get_attribute(&minor, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, _cu_device);
+  if (status != GRAAL_CUDA_SUCCESS) {
+    tty->print_cr("[CUDA] Failed to get minor attribute of device: %d", _cu_device);
+    return false;
+  }
+  status = _cuda_cu_device_get_attribute(&major, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, _cu_device);
+  if (status != GRAAL_CUDA_SUCCESS) {
+    tty->print_cr("[CUDA] Failed to get major attribute of device: %d", _cu_device);
+    return false;
+  }
+
+  /* Check if the device supports atleast GRAAL_SUPPORTED_COMPUTE_CAPABILITY_VERSION */
+  version = (float) major + ((float) minor)/10;
+
+  if (version < GRAAL_SUPPORTED_COMPUTE_CAPABILITY_VERSION) {
+    tty->print_cr("[CUDA] Only cuda compute capability 3.0 and later supported. Device %d supports %.1f",
+                  _cu_device, version);
+    return false;
+  }
+
+  if (TraceGPUInteraction) {
+    tty->print_cr("[CUDA] Device %d supports cuda compute capability %.1f", _cu_device, version);
+  }
 
   status = _cuda_cu_device_get_attribute(&unified_addressing, GRAAL_CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING, _cu_device);
 
@@ -193,7 +220,8 @@
   }
 
   if (TraceGPUInteraction) {
-    tty->print_cr("[CUDA] Unified addressing support on device %d: %d", _cu_device, unified_addressing);
+    tty->print_cr("[CUDA] Device %d %s unified addressing support", _cu_device,
+                  ((unified_addressing == 0) ? "does not have" : "has"));
   }
 
 
@@ -295,7 +323,6 @@
     }
 
     if (TraceGPUInteraction) {
-        tty->print_cr("[CUDA] Compatibility version of device %d: %d.%d", _cu_device, major, minor);
         tty->print_cr("[CUDA] Number of cores: %d async engines: %d can map host mem: %d concurrent kernels: %d",
                       total, async_engines, can_map_host_memory, concurrent_kernels);
         tty->print_cr("[CUDA] Max threads per block: %d warp size: %d", max_threads_per_block, warp_size);
--- a/src/gpu/ptx/vm/gpu_ptx.hpp	Thu Jan 30 21:11:38 2014 +0100
+++ b/src/gpu/ptx/vm/gpu_ptx.hpp	Thu Jan 30 17:49:56 2014 -0500
@@ -87,6 +87,12 @@
 #define GRAAL_CU_CTX_MAP_HOST            0x08
 #define GRAAL_CU_CTX_SCHED_BLOCKING_SYNC 0x04
 
+/**
+ * Support compute capability 3.0 and later
+ */
+
+#define GRAAL_SUPPORTED_COMPUTE_CAPABILITY_VERSION 3.0
+
 class Ptx {
   friend class PtxCall;
 
--- 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;
+        }
       }
     }
   }