clover: implements clEnqueueFillBuffer
authorSerge Martin <edb@sigluy.net>
Sun, 3 May 2020 11:56:15 +0000 (13:56 +0200)
committerSerge Martin <edb@sigluy.net>
Tue, 14 Jul 2020 07:33:02 +0000 (09:33 +0200)
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5897>

src/gallium/frontends/clover/api/device.cpp
src/gallium/frontends/clover/api/memory.cpp
src/gallium/frontends/clover/api/transfer.cpp
src/gallium/frontends/clover/core/device.cpp
src/gallium/frontends/clover/core/device.hpp
src/gallium/frontends/clover/core/resource.cpp
src/gallium/frontends/clover/core/resource.hpp

index 042f2eda21c8c1f9a48733899e23c46cfb9ebf28..ce9ae75749d795c0e7a607cf265001c772d784d8 100644 (file)
@@ -205,8 +205,7 @@ clGetDeviceInfo(cl_device_id d_dev, cl_device_info param,
       break;
 
    case CL_DEVICE_MEM_BASE_ADDR_ALIGN:
-      buf.as_scalar<cl_uint>() = 8 *
-         std::max(dev.mem_base_addr_align(), (cl_uint) sizeof(cl_long) * 16);
+      buf.as_scalar<cl_uint>() = 8 * dev.mem_base_addr_align();
       break;
 
    case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE:
index 84c1aaf059a0c02fa69803c76cef6f6fa62ab9c1..d069a0977b6a3438f35eae0031d785e8c3e8e774 100644 (file)
@@ -424,17 +424,6 @@ clSetMemObjectDestructorCallback(cl_mem d_mem,
    return e.get();
 }
 
-CLOVER_API cl_int
-clEnqueueFillBuffer(cl_command_queue command_queue, cl_mem buffer,
-                    const void *pattern, size_t pattern_size,
-                    size_t offset, size_t size,
-                    cl_uint num_events_in_wait_list,
-                    const cl_event *event_wait_list,
-                    cl_event *event) {
-   CLOVER_NOT_SUPPORTED_UNTIL("1.2");
-   return CL_INVALID_VALUE;
-}
-
 CLOVER_API cl_int
 clEnqueueFillImage(cl_command_queue command_queue, cl_mem image,
                    const void *fill_color,
index fa8741e02b4eae9db12895e633f51981fcd3c4ab..0e39d976a89edd186460887423a91be1d0e40b64 100644 (file)
@@ -421,6 +421,50 @@ clEnqueueWriteBufferRect(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
    return e.get();
 }
 
+CLOVER_API cl_int
+clEnqueueFillBuffer(cl_command_queue d_queue, cl_mem d_mem,
+                    const void *pattern, size_t pattern_size,
+                    size_t offset, size_t size,
+                    cl_uint num_deps, const cl_event *d_deps,
+                    cl_event *rd_ev) try {
+   auto &q = obj(d_queue);
+   auto &mem = obj<buffer>(d_mem);
+   auto deps = objs<wait_list_tag>(d_deps, num_deps);
+   vector_t region = { size, 1, 1 };
+   vector_t dst_origin = { offset };
+   auto dst_pitch = pitch(region, {{ 1 }});
+
+   validate_common(q, deps);
+   validate_object(q, mem, dst_origin, dst_pitch, region);
+
+   if (!pattern)
+      return CL_INVALID_VALUE;
+
+   if (!util_is_power_of_two_nonzero(pattern_size) ||
+      pattern_size > 128 || size % pattern_size
+      || offset % pattern_size) {
+      return CL_INVALID_VALUE;
+   }
+
+   auto sub = dynamic_cast<sub_buffer *>(&mem);
+   if (sub && sub->offset() % q.device().mem_base_addr_align()) {
+      return CL_MISALIGNED_SUB_BUFFER_OFFSET;
+   }
+
+   std::string data = std::string((char *)pattern, pattern_size);
+   auto hev = create<hard_event>(
+      q, CL_COMMAND_FILL_BUFFER, deps,
+      [=, &q, &mem](event &) {
+         mem.resource(q).clear(q, offset, size, &data[0], data.size());
+      });
+
+   ret_object(rd_ev, hev);
+   return CL_SUCCESS;
+
+} catch (error &e) {
+   return e.get();
+}
+
 CLOVER_API cl_int
 clEnqueueCopyBuffer(cl_command_queue d_q, cl_mem d_src_mem, cl_mem d_dst_mem,
                     size_t src_offset, size_t dst_offset, size_t size,
index 609885c21bcf2463d1d9d5e801c48e26c537a885..ca2d951c76777f4b8c754cf768c845b4767f5c4f 100644 (file)
@@ -20,6 +20,7 @@
 // OTHER DEALINGS IN THE SOFTWARE.
 //
 
+#include <algorithm>
 #include <unistd.h>
 #include "core/device.hpp"
 #include "core/platform.hpp"
@@ -215,9 +216,9 @@ device::has_unified_memory() const {
    return pipe->get_param(pipe, PIPE_CAP_UMA);
 }
 
-cl_uint
+size_t
 device::mem_base_addr_align() const {
-   return sysconf(_SC_PAGESIZE);
+   return std::max((size_t)sysconf(_SC_PAGESIZE), sizeof(cl_long) * 16);
 }
 
 cl_device_svm_capabilities
index 597f9489b2c4618e52cb63334c5c2e6d8a935db4..7c8cf13ccf7955c38ea5f184c2c84da9c1c7d558 100644 (file)
@@ -70,7 +70,7 @@ namespace clover {
       bool has_halves() const;
       bool has_int64_atomics() const;
       bool has_unified_memory() const;
-      cl_uint mem_base_addr_align() const;
+      size_t mem_base_addr_align() const;
       cl_device_svm_capabilities svm_support() const;
 
       std::vector<size_t> max_block_size() const;
index dd207982588c2684336008aba52e6e9129f6d74e..b8e257db6dc1be2c221a0dc10b6aeddc59a47bf1 100644 (file)
@@ -64,6 +64,14 @@ resource::copy(command_queue &q, const vector &origin, const vector &region,
                                 box(src_res.offset + src_origin, region));
 }
 
+void
+resource::clear(command_queue &q, const size_t origin, const size_t size,
+                const void *pattern, const size_t pattern_size) {
+   auto p = offset[0] + origin;
+
+   q.pipe->clear_buffer(q.pipe, pipe, p, size, pattern, pattern_size);
+}
+
 void *
 resource::add_map(command_queue &q, cl_map_flags flags, bool blocking,
                   const vector &origin, const vector &region) {
index 3b994b4008badd43559fb9d447947f3fd82a87f7..208016dd13298226e063f83b327842948203218b 100644 (file)
@@ -50,6 +50,9 @@ namespace clover {
       void copy(command_queue &q, const vector &origin, const vector &region,
                 resource &src_resource, const vector &src_origin);
 
+      void clear(command_queue &q, const size_t origin, const size_t size,
+                 const void *pattern, const size_t pattern_size);
+
       void *add_map(command_queue &q, cl_map_flags flags, bool blocking,
                     const vector &origin, const vector &region);
       void del_map(void *p);