[Mesa-dev] [PATCH 3/4] clover: Align kernel arguments when storing them in the input buffer

Tom Stellard tom at stellard.net
Tue Jun 25 14:45:37 PDT 2013


From: Tom Stellard <thomas.stellard at amd.com>

---
 src/gallium/state_trackers/clover/core/kernel.cpp | 28 +++++++++++++----------
 src/gallium/state_trackers/clover/core/kernel.hpp |  5 ++++
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp
index c95285d..d5b256b 100644
--- a/src/gallium/state_trackers/clover/core/kernel.cpp
+++ b/src/gallium/state_trackers/clover/core/kernel.cpp
@@ -23,6 +23,7 @@
 #include "core/kernel.hpp"
 #include "core/resource.hpp"
 #include "pipe/p_context.h"
+#include "util/u_math.h"
 
 using namespace clover;
 
@@ -190,6 +191,14 @@ _cl_kernel::argument::storage() const {
    return 0;
 }
 
+size_t
+_cl_kernel::argument::allocate_input_space(exec_context &ctx) const {
+   size_t offset = ctx.input.size();
+   size_t aligned_size = align(__size, ctx.q->dev.kernel_arg_alignment());
+   ctx.input.resize(offset + aligned_size);
+   return offset;
+}
+
 _cl_kernel::scalar_argument::scalar_argument(size_t size) :
    argument(size) {
 }
@@ -205,7 +214,8 @@ _cl_kernel::scalar_argument::set(size_t size, const void *value) {
 
 void
 _cl_kernel::scalar_argument::bind(exec_context &ctx) {
-   ctx.input.insert(ctx.input.end(), v.begin(), v.end());
+   size_t offset = allocate_input_space(ctx);
+   memcpy(ctx.input.data() + offset, v.data(), __size);
 }
 
 void
@@ -230,11 +240,9 @@ _cl_kernel::global_argument::set(size_t size, const void *value) {
 
 void
 _cl_kernel::global_argument::bind(exec_context &ctx) {
-   size_t offset = ctx.input.size();
+   size_t offset = allocate_input_space(ctx);
    size_t idx = ctx.g_buffers.size();
 
-   ctx.input.resize(offset + __size);
-
    ctx.g_buffers.resize(idx + 1);
    ctx.g_buffers[idx] = obj->resource(ctx.q).pipe;
 
@@ -266,10 +274,9 @@ _cl_kernel::local_argument::set(size_t size, const void *value) {
 
 void
 _cl_kernel::local_argument::bind(exec_context &ctx) {
-   size_t offset = ctx.input.size();
+   size_t offset = allocate_input_space(ctx);
    size_t ptr = ctx.mem_local;
 
-   ctx.input.resize(offset + __size);
    *(size_t *)&ctx.input[offset] = ptr;
 
    ctx.mem_local += __storage;
@@ -297,10 +304,9 @@ _cl_kernel::constant_argument::set(size_t size, const void *value) {
 
 void
 _cl_kernel::constant_argument::bind(exec_context &ctx) {
-   size_t offset = ctx.input.size();
+   size_t offset = allocate_input_space(ctx);
    size_t idx = ctx.resources.size();
 
-   ctx.input.resize(offset + __size);
    *(uint32_t *)&ctx.input[offset] = idx << 24;
 
    ctx.resources.resize(idx + 1);
@@ -330,10 +336,9 @@ _cl_kernel::image_rd_argument::set(size_t size, const void *value) {
 
 void
 _cl_kernel::image_rd_argument::bind(exec_context &ctx) {
-   size_t offset = ctx.input.size();
+   size_t offset = allocate_input_space(ctx);
    size_t idx = ctx.sviews.size();
 
-   ctx.input.resize(offset + __size);
    *(uint32_t *)&ctx.input[offset] = idx;
 
    ctx.sviews.resize(idx + 1);
@@ -363,10 +368,9 @@ _cl_kernel::image_wr_argument::set(size_t size, const void *value) {
 
 void
 _cl_kernel::image_wr_argument::bind(exec_context &ctx) {
-   size_t offset = ctx.input.size();
+   size_t offset = allocate_input_space(ctx);
    size_t idx = ctx.resources.size();
 
-   ctx.input.resize(offset + __size);
    *(uint32_t *)&ctx.input[offset] = idx;
 
    ctx.resources.resize(idx + 1);
diff --git a/src/gallium/state_trackers/clover/core/kernel.hpp b/src/gallium/state_trackers/clover/core/kernel.hpp
index 6b336d0..5f19657 100644
--- a/src/gallium/state_trackers/clover/core/kernel.hpp
+++ b/src/gallium/state_trackers/clover/core/kernel.hpp
@@ -92,6 +92,11 @@ public:
    protected:
       size_t __size;
       bool __set;
+
+      /// Allocate space for this value in the input buffer
+      /// \returns The offset into the input buffer where the argument can
+      /// be inserted.
+      size_t allocate_input_space(exec_context &ctx) const;
    };
 
    _cl_kernel(clover::program &prog,
-- 
1.7.11.4



More information about the mesa-dev mailing list