userptr is firstly checked at compile time with libdrm version, but it does not ensure the system has such capability (for exmaple, with old linux kernel), so also take a check at run time for the device info.
V2: add runtime check to see if userptr is really supported Signed-off-by: Guo Yejun <[email protected]> --- src/cl_device_id.c | 18 ++++++++++++++++++ src/cl_gt_device.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/src/cl_device_id.c b/src/cl_device_id.c index c911c23..8ab1651 100644 --- a/src/cl_device_id.c +++ b/src/cl_device_id.c @@ -36,6 +36,8 @@ #define CL_DEVICE_BUILT_IN_KERNELS 0x103F #endif +void *aligned_alloc(size_t alignment, size_t size); + static struct _cl_device_id intel_ivb_gt2_device = { INIT_ICD(dispatch) .max_compute_unit = 16, @@ -401,6 +403,22 @@ brw_gt3_break: } } +#ifdef HAS_USERPTR + cl_driver dummy = cl_driver_new(NULL); + cl_buffer_mgr bufmgr = cl_driver_get_bufmgr(dummy); + + const size_t sz = 4096; + char* host_ptr = (char*)aligned_alloc(4096, sz); + 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); + + free(host_ptr); + cl_driver_delete(dummy); +#endif + return ret; } diff --git a/src/cl_gt_device.h b/src/cl_gt_device.h index 3cd54eb..c9caa1d 100644 --- a/src/cl_gt_device.h +++ b/src/cl_gt_device.h @@ -60,7 +60,11 @@ .max_constant_buffer_size = 512 << 10, .max_constant_args = 8, .error_correction_support = CL_FALSE, +#ifdef HAS_USERPTR +.host_unified_memory = CL_TRUE, +#else .host_unified_memory = CL_FALSE, +#endif .profiling_timer_resolution = 80, /* ns */ .endian_little = CL_TRUE, .available = CL_TRUE, -- 2.1.0 _______________________________________________ Beignet mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/beignet
