[Mesa-dev] [PATCH] clover: Compute aligned size for scalar argument

Vedran Miletić vedran at miletic.net
Fri May 27 15:01:57 UTC 2016


Scalar arguments are aligned to the next power of two per OpenCL 1.2
specification, Ch. 6.1.5: "A built-in data type that is not a power of
two bytes in size must be aligned to the next larger power of two." We
already compute size aligned to the next power of two in
get_kernel_args() and store it in scalar_argument object. This patch
adds same computation in kernel::scalar_argument::set().

Since the code might now silently fail where it previously failed with
CL_INVALID_ARG_SIZE, this patch also adds assert checking that Clang
compiled a struct argument into LLVM IR that we can handle.
---
 src/gallium/state_trackers/clover/core/kernel.cpp     | 7 +++++--
 src/gallium/state_trackers/clover/llvm/invocation.cpp | 4 ++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp
index 9231462..b2dc7f9 100644
--- a/src/gallium/state_trackers/clover/core/kernel.cpp
+++ b/src/gallium/state_trackers/clover/core/kernel.cpp
@@ -376,10 +376,13 @@ kernel::scalar_argument::set(size_t size, const void *value) {
    if (!value)
       throw error(CL_INVALID_ARG_VALUE);
 
-   if (size != this->size)
+   // OpenCL 1.2 specification, Ch. 6.1.5: "A built-in data
+   // type that is not a power of two bytes in size must be
+   // aligned to the next larger power of two."
+   if (util_next_power_of_two(size) != this->size)
       throw error(CL_INVALID_ARG_SIZE);
 
-   v = { (uint8_t *)value, (uint8_t *)value + size };
+   v = { (uint8_t *)value, (uint8_t *)value + util_next_power_of_two(size) };
    _set = true;
 }
 
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index e2cadda..b4b8e74 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -463,6 +463,10 @@ namespace {
          llvm::Type *arg_type = arg.getType();
          const unsigned arg_store_size = TD.getTypeStoreSize(arg_type);
 
+         assert(!(arg_type->isPointerTy() && arg.hasByValAttr() &&
+                arg_type->getPointerElementType()->isStructTy()) &&
+                "Unable to handle struct compiled as pointer with byval.");
+
          // OpenCL 1.2 specification, Ch. 6.1.5: "A built-in data
          // type that is not a power of two bytes in size must be
          // aligned to the next larger power of two".  We need this
-- 
2.7.4



More information about the mesa-dev mailing list