[Mesa-dev] [PATCH 4/7] clover: Let the compiler specify the size of kernel arguments

Tom Stellard tom at stellard.net
Tue Jul 9 21:21:41 PDT 2013


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

---
 src/gallium/state_trackers/clover/core/kernel.cpp | 40 +++++++++++------------
 src/gallium/state_trackers/clover/core/kernel.hpp | 10 +++---
 2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp
index 68e4137..c95285d 100644
--- a/src/gallium/state_trackers/clover/core/kernel.cpp
+++ b/src/gallium/state_trackers/clover/core/kernel.cpp
@@ -36,17 +36,17 @@ _cl_kernel::_cl_kernel(clover::program &prog,
       else if (arg.type == module::argument::global)
          this->args.emplace_back(new global_argument(arg.size));
       else if (arg.type == module::argument::local)
-         this->args.emplace_back(new local_argument());
+         this->args.emplace_back(new local_argument(arg.size));
       else if (arg.type == module::argument::constant)
-         this->args.emplace_back(new constant_argument());
+         this->args.emplace_back(new constant_argument(arg.size));
       else if (arg.type == module::argument::image2d_rd ||
                arg.type == module::argument::image3d_rd)
-         this->args.emplace_back(new image_rd_argument());
+         this->args.emplace_back(new image_rd_argument(arg.size));
       else if (arg.type == module::argument::image2d_wr ||
                arg.type == module::argument::image3d_wr)
-         this->args.emplace_back(new image_wr_argument());
+         this->args.emplace_back(new image_wr_argument(arg.size));
       else if (arg.type == module::argument::sampler)
-         this->args.emplace_back(new sampler_argument());
+         this->args.emplace_back(new sampler_argument(arg.size));
       else
          throw error(CL_INVALID_KERNEL_DEFINITION);
    }
@@ -246,8 +246,8 @@ void
 _cl_kernel::global_argument::unbind(exec_context &ctx) {
 }
 
-_cl_kernel::local_argument::local_argument() :
-   argument(sizeof(uint32_t)) {
+_cl_kernel::local_argument::local_argument(size_t size) :
+   argument(size) {
 }
 
 size_t
@@ -269,8 +269,8 @@ _cl_kernel::local_argument::bind(exec_context &ctx) {
    size_t offset = ctx.input.size();
    size_t ptr = ctx.mem_local;
 
-   ctx.input.resize(offset + sizeof(uint32_t));
-   *(uint32_t *)&ctx.input[offset] = ptr;
+   ctx.input.resize(offset + __size);
+   *(size_t *)&ctx.input[offset] = ptr;
 
    ctx.mem_local += __storage;
 }
@@ -279,8 +279,8 @@ void
 _cl_kernel::local_argument::unbind(exec_context &ctx) {
 }
 
-_cl_kernel::constant_argument::constant_argument() :
-   argument(sizeof(uint32_t)) {
+_cl_kernel::constant_argument::constant_argument(size_t size) :
+   argument(size) {
 }
 
 void
@@ -300,7 +300,7 @@ _cl_kernel::constant_argument::bind(exec_context &ctx) {
    size_t offset = ctx.input.size();
    size_t idx = ctx.resources.size();
 
-   ctx.input.resize(offset + sizeof(uint32_t));
+   ctx.input.resize(offset + __size);
    *(uint32_t *)&ctx.input[offset] = idx << 24;
 
    ctx.resources.resize(idx + 1);
@@ -312,8 +312,8 @@ _cl_kernel::constant_argument::unbind(exec_context &ctx) {
    obj->resource(ctx.q).unbind_surface(*ctx.q, st);
 }
 
-_cl_kernel::image_rd_argument::image_rd_argument() :
-   argument(sizeof(uint32_t)) {
+_cl_kernel::image_rd_argument::image_rd_argument(size_t size) :
+   argument(size) {
 }
 
 void
@@ -333,7 +333,7 @@ _cl_kernel::image_rd_argument::bind(exec_context &ctx) {
    size_t offset = ctx.input.size();
    size_t idx = ctx.sviews.size();
 
-   ctx.input.resize(offset + sizeof(uint32_t));
+   ctx.input.resize(offset + __size);
    *(uint32_t *)&ctx.input[offset] = idx;
 
    ctx.sviews.resize(idx + 1);
@@ -345,8 +345,8 @@ _cl_kernel::image_rd_argument::unbind(exec_context &ctx) {
    obj->resource(ctx.q).unbind_sampler_view(*ctx.q, st);
 }
 
-_cl_kernel::image_wr_argument::image_wr_argument() :
-   argument(sizeof(uint32_t)) {
+_cl_kernel::image_wr_argument::image_wr_argument(size_t size) :
+   argument(size) {
 }
 
 void
@@ -366,7 +366,7 @@ _cl_kernel::image_wr_argument::bind(exec_context &ctx) {
    size_t offset = ctx.input.size();
    size_t idx = ctx.resources.size();
 
-   ctx.input.resize(offset + sizeof(uint32_t));
+   ctx.input.resize(offset + __size);
    *(uint32_t *)&ctx.input[offset] = idx;
 
    ctx.resources.resize(idx + 1);
@@ -378,8 +378,8 @@ _cl_kernel::image_wr_argument::unbind(exec_context &ctx) {
    obj->resource(ctx.q).unbind_surface(*ctx.q, st);
 }
 
-_cl_kernel::sampler_argument::sampler_argument() :
-   argument(0) {
+_cl_kernel::sampler_argument::sampler_argument(size_t size) :
+   argument(size) {
 }
 
 void
diff --git a/src/gallium/state_trackers/clover/core/kernel.hpp b/src/gallium/state_trackers/clover/core/kernel.hpp
index fd64f3e..6b336d0 100644
--- a/src/gallium/state_trackers/clover/core/kernel.hpp
+++ b/src/gallium/state_trackers/clover/core/kernel.hpp
@@ -143,7 +143,7 @@ private:
 
    class local_argument : public argument {
    public:
-      local_argument();
+      local_argument(size_t size);
 
       virtual size_t storage() const;
 
@@ -157,7 +157,7 @@ private:
 
    class constant_argument : public argument {
    public:
-      constant_argument();
+      constant_argument(size_t size);
 
       virtual void set(size_t size, const void *value);
       virtual void bind(exec_context &ctx);
@@ -170,7 +170,7 @@ private:
 
    class image_rd_argument : public argument {
    public:
-      image_rd_argument();
+      image_rd_argument(size_t size);
 
       virtual void set(size_t size, const void *value);
       virtual void bind(exec_context &ctx);
@@ -183,7 +183,7 @@ private:
 
    class image_wr_argument : public argument {
    public:
-      image_wr_argument();
+      image_wr_argument(size_t size);
 
       virtual void set(size_t size, const void *value);
       virtual void bind(exec_context &ctx);
@@ -196,7 +196,7 @@ private:
 
    class sampler_argument : public argument {
    public:
-      sampler_argument();
+      sampler_argument(size_t size);
 
       virtual void set(size_t size, const void *value);
       virtual void bind(exec_context &ctx);
-- 
1.7.11.4



More information about the mesa-dev mailing list