Mesa (main): clover: Local memory needs to be aligned.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 3 17:25:25 UTC 2021


Module: Mesa
Branch: main
Commit: 5ffe059fd2c373734c91e85bc809a6cc32ba8f3d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5ffe059fd2c373734c91e85bc809a6cc32ba8f3d

Author: Karol Herbst <kherbst at redhat.com>
Date:   Sun Aug 16 01:51:49 2020 +0200

clover: Local memory needs to be aligned.

Fixes a couple of OpenCL CTS tests.

v3:
* Add a comment in module.hpp explaining that target_align means
  something different for arguments of type local (Francisco Jerez)
* Squash in the fix for the LLVM backend.

Reviewed-by: Francisco Jerez <currojerez at riseup.net>
Signed-off-by: Pierre Moreau <dev at pmoreau.org>
Signed-off-by: Karol Herbst <kherbst at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10256>

---

 src/gallium/frontends/clover/core/kernel.cpp         | 3 ++-
 src/gallium/frontends/clover/core/module.hpp         | 4 +++-
 src/gallium/frontends/clover/llvm/codegen/common.cpp | 5 ++++-
 src/gallium/frontends/clover/spirv/invocation.cpp    | 8 +++++++-
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/gallium/frontends/clover/core/kernel.cpp b/src/gallium/frontends/clover/core/kernel.cpp
index 36a81ee04e1..16be95e5906 100644
--- a/src/gallium/frontends/clover/core/kernel.cpp
+++ b/src/gallium/frontends/clover/core/kernel.cpp
@@ -523,11 +523,12 @@ kernel::local_argument::set(size_t size, const void *value) {
 void
 kernel::local_argument::bind(exec_context &ctx,
                              const module::argument &marg) {
+   ctx.mem_local = ::align(ctx.mem_local, marg.target_align);
    auto v = bytes(ctx.mem_local);
 
    extend(v, module::argument::zero_ext, marg.target_size);
    byteswap(v, ctx.q->device().endianness());
-   align(ctx.input, marg.target_align);
+   align(ctx.input, ctx.q->device().address_bits() / 8);
    insert(ctx.input, v);
 
    ctx.mem_local += _storage;
diff --git a/src/gallium/frontends/clover/core/module.hpp b/src/gallium/frontends/clover/core/module.hpp
index 9825ea259b9..d7c669d1b7b 100644
--- a/src/gallium/frontends/clover/core/module.hpp
+++ b/src/gallium/frontends/clover/core/module.hpp
@@ -125,7 +125,9 @@ namespace clover {
          type type;
          size_t size;
          size_t target_size;
-         size_t target_align;
+         size_t target_align; // For arguments of type local, this represents
+                              // the alignment requirement for the pointed
+                              // type and for the pointer itself.
          ext_type ext_type;
          semantic semantic;
          arg_info info;
diff --git a/src/gallium/frontends/clover/llvm/codegen/common.cpp b/src/gallium/frontends/clover/llvm/codegen/common.cpp
index 1c3e822aac8..2ed46794def 100644
--- a/src/gallium/frontends/clover/llvm/codegen/common.cpp
+++ b/src/gallium/frontends/clover/llvm/codegen/common.cpp
@@ -213,8 +213,11 @@ namespace {
                const auto offset =
                            static_cast<unsigned>(clang::LangAS::opencl_local);
                if (address_space == map[offset]) {
+                  const auto pointee_type = cast<
+                     ::llvm::PointerType>(actual_type)->getElementType();
                   args.emplace_back(module::argument::local, arg_api_size,
-                                    target_size, target_align,
+                                    target_size,
+                                    dl.getABITypeAlignment(pointee_type),
                                     module::argument::zero_ext);
                } else {
                   // XXX: Correctly handle constant address space.  There is no
diff --git a/src/gallium/frontends/clover/spirv/invocation.cpp b/src/gallium/frontends/clover/spirv/invocation.cpp
index ec425e2c7d6..cec265d87ed 100644
--- a/src/gallium/frontends/clover/spirv/invocation.cpp
+++ b/src/gallium/frontends/clover/spirv/invocation.cpp
@@ -350,10 +350,16 @@ namespace {
             if (opcode == SpvOpTypePointer)
                pointer_types[id] = get<SpvId>(inst, 3);
 
+            module::size_t alignment;
+            if (storage_class == SpvStorageClassWorkgroup)
+               alignment = opcode == SpvOpTypePointer ? types[pointer_types[id]].target_align : 0;
+            else
+               alignment = pointer_byte_size;
+
             types[id] = { convert_storage_class(storage_class, err),
                           sizeof(cl_mem),
                           static_cast<module::size_t>(pointer_byte_size),
-                          static_cast<module::size_t>(pointer_byte_size),
+                          alignment,
                           module::argument::zero_ext };
             types[id].info.address_qualifier = convert_storage_class_to_cl(storage_class);
             break;



More information about the mesa-commit mailing list