From: Jeff McGee <jeff.mcgee@xxxxxxxxx> We need to update some fields of the device's cl_device_id struct at runtime using driver-specific methods. It is best to group all such updates into a single driver callback to avoid opening/initing and deiniting/closing the device multiple times. Signed-off-by: Jeff McGee <jeff.mcgee@xxxxxxxxx> --- src/cl_device_id.c | 20 ++------------------ src/cl_driver.h | 4 ++++ src/cl_driver_defs.c | 1 + src/intel/intel_driver.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/cl_device_id.c b/src/cl_device_id.c index 4e01c9f..fefcef3 100644 --- a/src/cl_device_id.c +++ b/src/cl_device_id.c @@ -506,24 +506,8 @@ skl_gt4_break: ret->profile_sz = strlen(ret->profile) + 1; } -#ifdef HAS_USERPTR - cl_driver dummy = cl_driver_new(NULL); - cl_buffer_mgr bufmgr = cl_driver_get_bufmgr(dummy); - - const size_t sz = 4096; - void* host_ptr = cl_aligned_malloc(sz, 4096);; - if (host_ptr != NULL) { - cl_buffer bo = cl_buffer_alloc_userptr(bufmgr, "CL memory object", host_ptr, sz, 0); - if (bo == NULL) - ret->host_unified_memory = CL_FALSE; - else - cl_buffer_unreference(bo); - cl_free(host_ptr); - } - else - ret->host_unified_memory = CL_FALSE; - cl_driver_delete(dummy); -#endif + /* Apply any driver-dependent updates to the device info */ + cl_driver_update_device_info(ret); struct sysinfo info; if (sysinfo(&info) == 0) { diff --git a/src/cl_driver.h b/src/cl_driver.h index 16f8bba..3f54a27 100644 --- a/src/cl_driver.h +++ b/src/cl_driver.h @@ -376,6 +376,10 @@ extern cl_buffer_get_tiling_align_cb *cl_buffer_get_tiling_align; typedef int (cl_driver_get_device_id_cb)(void); extern cl_driver_get_device_id_cb *cl_driver_get_device_id; +/* Update the device info */ +typedef void (cl_driver_update_device_info_cb)(cl_device_id device); +extern cl_driver_update_device_info_cb *cl_driver_update_device_info; + /************************************************************************** * cl_khr_gl_sharing. **************************************************************************/ diff --git a/src/cl_driver_defs.c b/src/cl_driver_defs.c index 2b68539..9a47210 100644 --- a/src/cl_driver_defs.c +++ b/src/cl_driver_defs.c @@ -26,6 +26,7 @@ LOCAL cl_driver_delete_cb *cl_driver_delete = NULL; LOCAL cl_driver_get_bufmgr_cb *cl_driver_get_bufmgr = NULL; LOCAL cl_driver_get_ver_cb *cl_driver_get_ver = NULL; LOCAL cl_driver_get_device_id_cb *cl_driver_get_device_id = NULL; +LOCAL cl_driver_update_device_info_cb *cl_driver_update_device_info = NULL; /* Buffer */ LOCAL cl_buffer_alloc_cb *cl_buffer_alloc = NULL; diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c index ff0cf27..d61988c 100644 --- a/src/intel/intel_driver.c +++ b/src/intel/intel_driver.c @@ -754,6 +754,41 @@ static int intel_buffer_set_tiling(cl_buffer bo, return ret; } +static void +intel_update_device_info(cl_device_id device) +{ +#ifdef HAS_USERPTR + intel_driver_t *driver; + const size_t sz = 4096; + void *host_ptr; + + driver = intel_driver_new(); + assert(driver != NULL); + if (intel_driver_open(driver, NULL) != CL_SUCCESS) { + intel_driver_delete(driver); + return; + } + + host_ptr = cl_aligned_malloc(sz, 4096); + if (host_ptr != NULL) { + cl_buffer bo = intel_buffer_alloc_userptr((cl_buffer_mgr)driver->bufmgr, + "CL memory object", host_ptr, sz, 0); + if (bo == NULL) + device->host_unified_memory = CL_FALSE; + else + drm_intel_bo_unreference((drm_intel_bo*)bo); + cl_free(host_ptr); + } + else + device->host_unified_memory = CL_FALSE; + + intel_driver_context_destroy(driver); + intel_driver_close(driver); + intel_driver_terminate(driver); + intel_driver_delete(driver); +#endif +} + LOCAL void intel_setup_callbacks(void) { @@ -762,6 +797,7 @@ intel_setup_callbacks(void) cl_driver_get_ver = (cl_driver_get_ver_cb *) intel_driver_get_ver; cl_driver_get_bufmgr = (cl_driver_get_bufmgr_cb *) intel_driver_get_bufmgr; cl_driver_get_device_id = (cl_driver_get_device_id_cb *) intel_get_device_id; + cl_driver_update_device_info = (cl_driver_update_device_info_cb *) intel_update_device_info; cl_buffer_alloc = (cl_buffer_alloc_cb *) drm_intel_bo_alloc; cl_buffer_alloc_userptr = (cl_buffer_alloc_userptr_cb*) intel_buffer_alloc_userptr; cl_buffer_set_tiling = (cl_buffer_set_tiling_cb *) intel_buffer_set_tiling; -- 2.3.0 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/dri-devel