From 035e882819bcb853fff7a59c638a0ecbf89cb762 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Mon, 21 May 2018 12:19:42 +0200 Subject: [PATCH] clover: implement CL_DEVICE_SVM_CAPABILITIES v2: without supporting userptrs SVM can't be implemented as it's impossible to ensure memory consistency with HOST_PTR buffers v3: fix comment style v4: fixes typo in comment Signed-off-by: Karol Herbst Reviewed-by: Pierre Moreau Reviewed-by: Francisco Jerez Part-of: --- .../state_trackers/clover/api/device.cpp | 4 ++++ .../state_trackers/clover/core/device.cpp | 23 +++++++++++++++++++ .../state_trackers/clover/core/device.hpp | 1 + 3 files changed, 28 insertions(+) diff --git a/src/gallium/state_trackers/clover/api/device.cpp b/src/gallium/state_trackers/clover/api/device.cpp index ca6b90ba271..d1c37b96aeb 100644 --- a/src/gallium/state_trackers/clover/api/device.cpp +++ b/src/gallium/state_trackers/clover/api/device.cpp @@ -405,6 +405,10 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param, buf.as_scalar() = 1; break; + case CL_DEVICE_SVM_CAPABILITIES: + buf.as_scalar() = dev.svm_support(); + break; + default: throw error(CL_INVALID_VALUE); } diff --git a/src/gallium/state_trackers/clover/core/device.cpp b/src/gallium/state_trackers/clover/core/device.cpp index 298cde278b4..e05dc562189 100644 --- a/src/gallium/state_trackers/clover/core/device.cpp +++ b/src/gallium/state_trackers/clover/core/device.cpp @@ -220,6 +220,29 @@ device::mem_base_addr_align() const { return sysconf(_SC_PAGESIZE); } +cl_device_svm_capabilities +device::svm_support() const { + // Without CAP_RESOURCE_FROM_USER_MEMORY SVM and CL_MEM_USE_HOST_PTR + // interactions won't work according to spec as clover manages a GPU side + // copy of the host data. + // + // The biggest problem are memory buffers created with CL_MEM_USE_HOST_PTR, + // but the application and/or the kernel updates the memory via SVM and not + // the cl_mem buffer. + // We can't even do proper tracking on what memory might have been accessed + // as the host ptr to the buffer could be within a SVM region, where through + // the CL API there is no reliable way of knowing if a certain cl_mem buffer + // was accessed by a kernel or not and the runtime can't reliably know from + // which side the GPU buffer content needs to be updated. + // + // Another unsolvable scenario is a cl_mem object passed by cl_mem reference + // and SVM pointer into the same kernel at the same time. + if (pipe->get_param(pipe, PIPE_CAP_RESOURCE_FROM_USER_MEMORY) && + pipe->get_param(pipe, PIPE_CAP_SYSTEM_SVM)) + return CL_DEVICE_SVM_FINE_GRAIN_SYSTEM; + return 0; +} + std::vector device::max_block_size() const { auto v = get_compute_param(pipe, ir_format(), diff --git a/src/gallium/state_trackers/clover/core/device.hpp b/src/gallium/state_trackers/clover/core/device.hpp index 828dfaa65e6..dc9064bb638 100644 --- a/src/gallium/state_trackers/clover/core/device.hpp +++ b/src/gallium/state_trackers/clover/core/device.hpp @@ -71,6 +71,7 @@ namespace clover { bool has_int64_atomics() const; bool has_unified_memory() const; cl_uint mem_base_addr_align() const; + cl_device_svm_capabilities svm_support() const; std::vector max_block_size() const; cl_uint subgroup_size() const; -- 2.30.2