Add driver callback for updating device info
PATCH 1/2 Add driver callback for updating device info
From: Jeff McGee <[email protected]>
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.
--- 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(-)
src/cl_device_id.c +2 -18
@@ -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 ) {
src/cl_driver.h +4 -0
@@ -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. **************************************************************************/
src/cl_driver_defs.c +1 -0
@@ -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;
src/intel/intel_driver.c +36 -0
@@ -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 voidintel_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;
Signature · 6 lines
2.3.0 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 Query the driver directly for compute units and subslice
From: Jeff McGee <[email protected]>
Values of device max compute units and max subslice obtained directly from the driver should be more accurate than our own ID-based lookup values. This is particularly important when a single device ID may encompass more than one configuration. If the driver cannot provide a valid value for the given device, we fallback on the ID-based lookup value.
--- src/intel/intel_driver.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
src/intel/intel_driver.c +12 -4
@@ -757,10 +757,8 @@ static int intel_buffer_set_tiling(cl_buffer bo,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; +unsigned int eu_total, subslice_total; driver =intel_driver_new ();assert (driver !=NULL );
@@ -769,6 +767,10 @@ intel_update_device_info(cl_device_id device)return ; } +#ifdef HAS_USERPTR +const size_t sz =4096 ; +void *host_ptr; + host_ptr =cl_aligned_malloc (sz,4096 );if (host_ptr !=NULL ) { cl_buffer bo = intel_buffer_alloc_userptr((cl_buffer_mgr)driver->bufmgr,
@@ -781,12 +783,18 @@ intel_update_device_info(cl_device_id device) }else device->host_unified_memory =CL_FALSE ; +#endif + +/* Prefer driver-queried value if supported */ +if (!drm_intel_get_eu_total (driver->fd, &eu_total)) + device->max_compute_unit = eu_total; +if (!drm_intel_get_subslice_total (driver->fd, &subslice_total)) + device->sub_slice_count = subslice_total;intel_driver_context_destroy (driver);intel_driver_close (driver);intel_driver_terminate (driver);intel_driver_delete (driver); -#endif }LOCAL void
Signature · 6 lines
2.3.0 _______________________________________________ Beignet mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/beignet
PATCH v2 2/2 Query the driver directly for compute units and subslice
From: Jeff McGee <[email protected]>
Values of device max compute units and max subslice obtained directly from the driver should be more accurate than our own ID-based lookup values. This is particularly important when a single device ID may encompass more than one configuration. If the driver cannot provide a valid value for the given device, we fallback on the ID-based lookup value.
This query requires libdrm 2.4.60. For now we will consider the use of this query to be optional and exclude it from compilation when building against older libdrm. Later we may want to consider requiring the query or at least warning more strongly when it is not supported.
v2: Make feature use conditional on libdrm version (Zhigang).
--- CMakeLists.txt | 9 +++++++++ src/CMakeLists.txt | 10 ++++++++++ src/intel/intel_driver.c | 25 +++++++++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-)
CMakeLists.txt +9 -0
@@ -131,6 +131,15 @@ IF(DRM_INTEL_FOUND) ELSE(DRM_INTEL_VERSION VERSION_GREATER 2.4.57) MESSAGE(STATUS "Disable userptr support") ENDIF(DRM_INTEL_VERSION VERSION_GREATER 2.4.57) + IF(DRM_INTEL_VERSION VERSION_GREATER 2.4.59) + MESSAGE(STATUS "Enable EU total query support") + SET(DRM_INTEL_EU_TOTAL "enable") + MESSAGE(STATUS "Enable subslice total query support") + SET(DRM_INTEL_SUBSLICE_TOTAL "enable") + ELSE(DRM_INTEL_VERSION VERSION_GREATER 2.4.59) + MESSAGE(STATUS "Disable EU total query support") + MESSAGE(STATUS "Disable subslice total query support") + ENDIF(DRM_INTEL_VERSION VERSION_GREATER 2.4.59) ELSE(DRM_INTEL_FOUND) MESSAGE(FATAL_ERROR "Looking for DRM Intel (>= 2.4.52) - not found") ENDIF(DRM_INTEL_FOUND)
src/CMakeLists.txt +10 -0
@@ -118,6 +118,16 @@ SET(CMAKE_CXX_FLAGS "-DHAS_USERPTR ${CMAKE_CXX_FLAGS}") SET(CMAKE_C_FLAGS "-DHAS_USERPTR ${CMAKE_C_FLAGS}") endif (DRM_INTEL_USERPTR) +if (DRM_INTEL_EU_TOTAL) +SET(CMAKE_CXX_FLAGS "-DHAS_EU_TOTAL ${CMAKE_CXX_FLAGS}") +SET(CMAKE_C_FLAGS "-DHAS_EU_TOTAL ${CMAKE_C_FLAGS}") +endif (DRM_INTEL_EU_TOTAL) + +if (DRM_INTEL_SUBSLICE_TOTAL) +SET(CMAKE_CXX_FLAGS "-DHAS_SUBSLICE_TOTAL ${CMAKE_CXX_FLAGS}") +SET(CMAKE_C_FLAGS "-DHAS_SUBSLICE_TOTAL ${CMAKE_C_FLAGS}") +endif (DRM_INTEL_SUBSLICE_TOTAL) + set(GIT_SHA1 "git_sha1.h") add_custom_target(${GIT_SHA1} ALL COMMAND chmod +x ${CMAKE_CURRENT_SOURCE_DIR}/git_sha1.sh
src/intel/intel_driver.c +21 -4
@@ -757,10 +757,7 @@ static int intel_buffer_set_tiling(cl_buffer bo,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 );
@@ -769,6 +766,10 @@ intel_update_device_info(cl_device_id device)return ; } +#ifdef HAS_USERPTR +const size_t sz =4096 ; +void *host_ptr; + host_ptr =cl_aligned_malloc (sz,4096 );if (host_ptr !=NULL ) { cl_buffer bo = intel_buffer_alloc_userptr((cl_buffer_mgr)driver->bufmgr,
@@ -781,12 +782,28 @@ intel_update_device_info(cl_device_id device) }else device->host_unified_memory =CL_FALSE ; +#endif + +#ifdef HAS_EU_TOTAL +unsigned int eu_total; + +/* Prefer driver-queried max compute units if supported */ +if (!drm_intel_get_eu_total (driver->fd, &eu_total)) + device->max_compute_unit = eu_total; +#endif + +#ifdef HAS_SUBSLICE_TOTAL +unsigned int subslice_total; + +/* Prefer driver-queried subslice count if supported */ +if (!drm_intel_get_subslice_total (driver->fd, &subslice_total)) + device->sub_slice_count = subslice_total; +#endif intel_driver_context_destroy (driver);intel_driver_close (driver);intel_driver_terminate (driver);intel_driver_delete (driver); -#endif }LOCAL void
Signature · 6 lines
2.3.0 _______________________________________________ Beignet mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/beignet
Re: [Beignet] [PATCH 2/2 v2] Query the driver directly for compute units and subslice
LGTM,
Thanks.
Quoted 126 lines
-----Original Message-----
From: Beignet [mailto:[email protected]] On Behalf Of [email protected]
Sent: Tuesday, March 10, 2015 7:36 AM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [Beignet] [PATCH 2/2 v2] Query the driver directly for compute units and subsliceFrom: Jeff McGee <[email protected]>
Values of device max compute units and max subslice obtained directly from the driver should be more accurate than our own ID-based lookup values. This is particularly important when a single device ID may encompass more than one configuration. If the driver cannot provide a valid value for the given device, we fallback on the ID-based lookup value.
This query requires libdrm 2.4.60. For now we will consider the use of this query to be optional and exclude it from compilation when building against older libdrm. Later we may want to consider requiring the query or at least warning more strongly when it is not supported.
v2: Make feature use conditional on libdrm version (Zhigang).
Signed-off-by Jeff McGee <[email protected]>--- CMakeLists.txt | 9 +++++++++ src/CMakeLists.txt | 10 ++++++++++ src/intel/intel_driver.c | 25 +++++++++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-)CMakeLists.txt +5
-0@@ -131,6 +131,15 @@ IF(DRM_INTEL_FOUND) ELSE(DRM_INTEL_VERSION VERSION_GREATER 2.4.57) MESSAGE(STATUS "Disable userptr support") ENDIF(DRM_INTEL_VERSION VERSION_GREATER 2.4.57) + IF(DRM_INTEL_VERSION VERSION_GREATER 2.4.59) + MESSAGE(STATUS "Enable EU total query support") + SET(DRM_INTEL_EU_TOTAL "enable") + MESSAGE(STATUS "Enable subslice total query support") + SET(DRM_INTEL_SUBSLICE_TOTAL "enable")ELSE(DRM_INTEL_VERSION
+VERSION_GREATER2.4.59)CMakeLists.txt +3
-0+ MESSAGE(STATUS "Disable EU total query support") + MESSAGE(STATUS "Disable subslice total query support") + ENDIF(DRM_INTEL_VERSION VERSION_GREATER 2.4.59) ELSE(DRM_INTEL_FOUND) MESSAGE(FATAL_ERROR "Looking for DRM Intel (>= 2.4.52) - not found") ENDIF(DRM_INTEL_FOUND)src/CMakeLists.txt index d4181d8..464765f renamed from src/CMakeLists.txt +0
-0100644
src/CMakeLists.txt +0
-0@@ -118,6 +118,16 @@ SET(CMAKE_CXX_FLAGS "-DHAS_USERPTR${CMAKE_CXX_FLAGS}")
SET(CMAKE_C_FLAGS "-DHAS_USERPTR ${CMAKE_C_FLAGS}")endif (DRM_INTEL_USERPTR)src/CMakeLists.txt +10
-0+if (DRM_INTEL_EU_TOTAL) +SET(CMAKE_CXX_FLAGS "-DHAS_EU_TOTAL ${CMAKE_CXX_FLAGS}") +SET(CMAKE_C_FLAGS "-DHAS_EU_TOTAL ${CMAKE_C_FLAGS}") endif +(DRM_INTEL_EU_TOTAL) + +if (DRM_INTEL_SUBSLICE_TOTAL) +SET(CMAKE_CXX_FLAGS "-DHAS_SUBSLICE_TOTAL ${CMAKE_CXX_FLAGS}") +SET(CMAKE_C_FLAGS "-DHAS_SUBSLICE_TOTAL ${CMAKE_C_FLAGS}") endif +(DRM_INTEL_SUBSLICE_TOTAL) + set(GIT_SHA1 "git_sha1.h") add_custom_target(${GIT_SHA1} ALL COMMAND chmod +x ${CMAKE_CURRENT_SOURCE_DIR}/git_sha1.shsrc/intel/intel_driver.c index renamed from src/intel/intel_driver.c +0
-0d61988c..755ab6b 100644
src/intel/intel_driver.c +0
-0@@ -757,10 +757,7 @@ static int intel_buffer_set_tiling(cl_buffer bo, staticvoid
intel_update_device_info(cl_device_id device){ -#ifdefHAS_USERPTR
intel_driver_t*driver;src/intel/intel_driver.c +19
-4-const size_t sz =4096 ; -void *host_ptr; driver =intel_driver_new ();assert (driver !=NULL );@@ -769,6 +766,10 @@ intel_update_device_info(cl_device_id device)return ; } +#ifdef HAS_USERPTR +const size_t sz =4096 ; +void *host_ptr; + host_ptr =cl_aligned_malloc (sz,4096 );if (host_ptr !=NULL ) { cl_buffer bo = intel_buffer_alloc_userptr((cl_buffer_mgr)driver->bufmgr,@@ -781,12 +782,28 @@ intel_update_device_info(cl_device_id device) }else device->host_unified_memory =CL_FALSE ; +#endif + +#ifdef HAS_EU_TOTAL +unsigned int eu_total; + +/* Prefer driver-queried max compute units if supported */ +if (!drm_intel_get_eu_total (driver->fd, &eu_total)) + device->max_compute_unit = eu_total;#endif + +#ifdef HAS_SUBSLICE_TOTAL +unsigned int subslice_total; + +/* Prefer driver-queried subslice count if supported */ +if (!drm_intel_get_subslice_total (driver->fd, &subslice_total)) + device->sub_slice_count = subslice_total;#endif intel_driver_context_destroy (driver);intel_driver_close (driver);intel_driver_terminate (driver);intel_driver_delete (driver); -#endif }LOCAL void --2.3.0
Quoted 4 lines
_______________________________________________
Beignet mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/beignet
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Beignet] [PATCH 2/2 v2] Query the driver directly for compute units and subslice
Quoted 6 lines · Zhigang Gong
LGTM,
Reviewed-by Zhigang Gong <[email protected]>Thanks.
Thanks for the review, Zhigang.
With beignet portion reviewed, review should be able to proceed for the i915, libdrm, and igt parts. These are all quite simple. Can someone(s) please review?
-Jeff
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
This patchset is a must for beignet to support CHV. One comment is that we should put the usage of these new libdrm APIs to conditional block thus we don't break the build on old system.
For the other parts of the patchset:
Thanks,
Zhigang Gong.
Quoted 140 lines
-----Original Message-----
From: Beignet [mailto:[email protected]] On Behalf Of [email protected]
Sent: Tuesday, March 3, 2015 7:43 AM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: [Beignet] [PATCH 1/2] Add driver callback for updating device infoFrom: Jeff McGee <[email protected]>
We need to update some fields of the device's
cl_device_idstruct 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 <[email protected]>--- 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(-)src/cl_device_id.c +2
-18@@ -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) {src/cl_driver.h +4
-0@@ -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.****************************************************************
**********/src/cl_driver_defs.c index 2b68539..9a47210 renamed from src/cl_driver_defs.c +0
-0100644
src/cl_driver_defs.c +0
-0@@ -26,6 +26,7 @@ LOCAL cl_driver_delete_cb *cl_driver_delete = NULL;LOCAL
cl_driver_get_bufmgr_cb*cl_driver_get_bufmgr= NULL; LOCALcl_driver_get_ver_cb*cl_driver_get_ver= NULL; LOCALcl_driver_get_device_id_cb*cl_driver_get_device_id= NULL;src/cl_driver_defs.c +2
-0+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.cb/src/intel/intel_driver.cindex ff0cf27..d61988c 100644src/intel/intel_driver.c +34
-0@@ -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 voidintel_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;
Quoted 7 lines
--
2.3.0_______________________________________________
Beignet mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/beignet
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx