[Beignet] [PATCH V2 4/4] runtime: dynamically get global memory size and max alloc size

Pan Xiuli xiuli.pan at intel.com
Thu Oct 22 22:22:59 PDT 2015


Now device and driver can support bigger memory, we need to abandon
our old 2G hard code. We get global memory by considering device
limitation, drm driver and kernel support and raw, this will ensure
a bigger global memory and a more stable system. We get max mem alloc
size from global memory size and the device limition.

Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
 src/cl_device_id.c       | 19 +++++++++++++++----
 src/intel/intel_driver.c |  5 +++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/cl_device_id.c b/src/cl_device_id.c
index b8abde7..93e24e6 100644
--- a/src/cl_device_id.c
+++ b/src/cl_device_id.c
@@ -548,13 +548,24 @@ skl_gt4_break:
   /* Apply any driver-dependent updates to the device info */
   cl_driver_update_device_info(ret);
 
+  #define toMB(size) (size)&(0xfffffffffffffff<<20)
+  /* Get the global_mem_size and max_mem_alloc size from
+   * driver, system ram and hardware*/
   struct sysinfo info;
   if (sysinfo(&info) == 0) {
-    uint64_t two_gb = 2 * 1024 * 1024 * 1024ul; 
+    uint64_t totalgpumem = ret->global_mem_size;
+	uint64_t maxallocmem = ret->max_mem_alloc_size;
     uint64_t totalram = info.totalram * info.mem_unit;
-    ret->global_mem_size = (totalram > two_gb) ? 
-                            two_gb : info.totalram;
-    ret->max_mem_alloc_size = ret->global_mem_size / 2;
+	/* In case to keep system stable we just use half
+	 * of the raw as global mem */
+    ret->global_mem_size = toMB((totalram / 2 > totalgpumem) ?
+                            totalgpumem: totalram / 2);
+	/* The hardware has some limit about the alloc size
+	 * and the excution of kernel need some global mem
+	 * so we now make sure single mem does not use much
+	 * than 3/4 global mem*/
+    ret->max_mem_alloc_size = toMB((ret->global_mem_size * 3 / 4 > maxallocmem) ?
+                              maxallocmem: ret->global_mem_size * 3 / 4);
   }
 
   return ret;
diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c
index 035a103..782a2de 100644
--- a/src/intel/intel_driver.c
+++ b/src/intel/intel_driver.c
@@ -829,6 +829,11 @@ intel_update_device_info(cl_device_id device)
   if (IS_CHERRYVIEW(device->device_id))
     printf(CHV_CONFIG_WARNING);
 #endif
+  //We should get the device memory dynamically, but the
+  //mapablce mem size usage is unknown. Just ignore it.
+  size_t total_mem,map_mem;
+  if(drm_intel_get_aperture_sizes(driver->fd,&map_mem,&total_mem) == 0)
+    device->global_mem_size = (cl_ulong)total_mem;
 
   intel_driver_context_destroy(driver);
   intel_driver_close(driver);
-- 
2.1.4



More information about the Beignet mailing list