clover/device: Calculate CL_DEVICE_MEM_BASE_ADDR_ALIGN in device
authorAaron Watry <awatry@gmail.com>
Thu, 17 Aug 2017 01:44:41 +0000 (20:44 -0500)
committerAaron Watry <awatry@gmail.com>
Tue, 22 Aug 2017 01:21:52 +0000 (20:21 -0500)
The CL CTS queries CL_DEVICE_MEM_BASE_ADDR_ALIGN for a device and
then allocates user pointers aligned to that value for its tests.

The minimum value is defined as:
  the size (in bits) of the largest OpenCL built-in data type supported
  by the device (long16 in FULL profile, long16 or int16 in EMBEDDED
  profile) for devices that are not of type CL_DEVICE_TYPE_CUSTOM.

At the moment, all known devices that support user pointers require
CPU page alignment for buffers created from user pointers, so just
query that from sysconf.

v3: Use std::max instead of MAX2 (Francisco)
    Add missing unistd include
v2: Use system page size instead of a new pipe cap

Signed-off-by: Aaron Watry <awatry@gmail.com>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Reviewed-by (v2): Jan Vesely <jan.vesely@rutgers.edu>

src/gallium/state_trackers/clover/api/device.cpp
src/gallium/state_trackers/clover/core/device.cpp
src/gallium/state_trackers/clover/core/device.hpp

index b1b7917e4ece3a4339fca833eea72fd971d536c4..b202102389fc75de4c7ec4d7b8145741804e8a44 100644 (file)
@@ -205,7 +205,8 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
       break;
 
    case CL_DEVICE_MEM_BASE_ADDR_ALIGN:
-      buf.as_scalar<cl_uint>() = 128 * 8;
+      buf.as_scalar<cl_uint>() = 8 *
+         std::max(dev.mem_base_addr_align(), (cl_uint) sizeof(cl_long) * 16);
       break;
 
    case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE:
index f6bbc38a9806ad287f56170bd48b633957b3a8d6..fc74bd51a9eafde0a2e2b9282adbf664e404f466 100644 (file)
@@ -20,6 +20,7 @@
 // OTHER DEALINGS IN THE SOFTWARE.
 //
 
+#include <unistd.h>
 #include "core/device.hpp"
 #include "core/platform.hpp"
 #include "pipe/p_screen.h"
@@ -194,6 +195,11 @@ device::has_unified_memory() const {
    return pipe->get_param(pipe, PIPE_CAP_UMA);
 }
 
+cl_uint
+device::mem_base_addr_align() const {
+   return sysconf(_SC_PAGESIZE);
+}
+
 std::vector<size_t>
 device::max_block_size() const {
    auto v = get_compute_param<uint64_t>(pipe, ir_format(),
index efc217aedb074f5fbde8916ab5a02fdac05d8a56..4e11519421a9ca23149161a0eaab04a96a836321 100644 (file)
@@ -68,6 +68,7 @@ namespace clover {
       bool image_support() const;
       bool has_doubles() const;
       bool has_unified_memory() const;
+      cl_uint mem_base_addr_align() const;
 
       std::vector<size_t> max_block_size() const;
       cl_uint subgroup_size() const;