summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPan Xiuli <xiuli.pan@intel.com>2015-10-23 13:22:59 +0800
committerYang Rong <rong.r.yang@intel.com>2015-11-03 12:48:32 +0800
commit5e87359ff0b381dedbbd1ccc2e78a5adb8fae476 (patch)
tree8feca307beb37e2519ec3b227703c179295c7047
parent98ea7beb0a4f6934fa724ccf7db6bc68b164758b (diff)
runtime: dynamically get global memory size and max alloc size
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@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@intel.com>
-rw-r--r--src/cl_device_id.c19
-rw-r--r--src/intel/intel_driver.c5
2 files changed, 20 insertions, 4 deletions
diff --git a/src/cl_device_id.c b/src/cl_device_id.c
index 8a051684..deb2fad8 100644
--- a/src/cl_device_id.c
+++ b/src/cl_device_id.c
@@ -559,13 +559,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 035a1039..782a2deb 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);