[Mesa-dev] [PATCH 5/7] gallium: Add PIPE_COMPUTE_CAP_KERNEL_ARG_ALIGNMENT v2

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


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

This value for this CAP is the alignment to use when storing kernel
arguments in the input buffer.

v2:
  - Allow per-type alignments
---
 src/gallium/docs/source/screen.rst                | 17 +++++++++++++++++
 src/gallium/drivers/r600/r600_pipe.c              | 11 ++++++++++-
 src/gallium/drivers/radeonsi/radeonsi_pipe.c      | 10 ++++++++++
 src/gallium/include/pipe/p_defines.h              |  3 ++-
 src/gallium/state_trackers/clover/core/device.cpp |  8 ++++++++
 src/gallium/state_trackers/clover/core/device.hpp |  1 +
 6 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst
index f062bea..4176421 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -281,6 +281,23 @@ pipe_screen::get_compute_param.
   resource.  Value type: ``uint64_t``.
 * ``PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE``: Maximum size of a memory object
   allocation in bytes.  Value type: ``uint64_t``.
+* ``PIPE_COMPUTE_CAP_KERNEL_ARG_ALIGNMENT``: Alignment to use when uploading
+  arguments to a kernel.  Input is the size in bytes of the value type,
+  output is the size in bytes of the alignment for that type.  Both input
+  and output Must be a power of two.  Value type: ``size_t``.
+
+EXAMPLE:
+char, short, and int all have the same alignemnt.
+
+kernel void align(char a, short b, int c);
+
+ALIGNMENT
+   1     a b b c c c c
+   2     a   b b c c c c
+   4     a       b b     c c c c
+   8     a               b b             c c c c
+
+Byte     0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3
 
 .. _pipe_bind:
 
diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
index 5fe9d39..76717b5 100644
--- a/src/gallium/drivers/r600/r600_pipe.c
+++ b/src/gallium/drivers/r600/r600_pipe.c
@@ -953,7 +953,16 @@ static int r600_get_compute_param(const struct pipe_screen *screen,
 			*max_mem_alloc_size = max_global_size / 4;
 		}
 		return sizeof(uint64_t);
-
+	case PIPE_COMPUTE_CAP_KERNEL_ARG_ALIGNMENT:
+		if (ret) {
+			size_t *alignment = ret;
+#if HAVE_LLVM < 0x0303
+			*alignment = 1;
+#else
+			*alignment = 4;
+#endif
+		}
+		return sizeof(size_t);
 	default:
 		fprintf(stderr, "unknown PIPE_COMPUTE_CAP %d\n", param);
 		return 0;
diff --git a/src/gallium/drivers/radeonsi/radeonsi_pipe.c b/src/gallium/drivers/radeonsi/radeonsi_pipe.c
index d2724b9..c9634a2 100644
--- a/src/gallium/drivers/radeonsi/radeonsi_pipe.c
+++ b/src/gallium/drivers/radeonsi/radeonsi_pipe.c
@@ -611,6 +611,16 @@ static int r600_get_compute_param(const struct pipe_screen *screen,
 			*max_mem_alloc_size = max_global_size / 4;
 		}
 		return sizeof(uint64_t);
+	case PIPE_COMPUTE_CAP_KERNEL_ARG_ALIGNMENT:
+		if (ret) {
+			size_t *alignment = ret;
+#if HAVE_LLVM < 0x0303
+			*alignment = 1;
+#else
+			*alignment = 4;
+#endif
+		}
+		return sizeof(size_t);
 	default:
 		fprintf(stderr, "unknown PIPE_COMPUTE_CAP %d\n", param);
 		return 0;
diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 4828a3e..62d973d 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -588,7 +588,8 @@ enum pipe_compute_cap
    PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE,
    PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE,
    PIPE_COMPUTE_CAP_MAX_INPUT_SIZE,
-   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE
+   PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,
+   PIPE_COMPUTE_CAP_KERNEL_ARG_ALIGNMENT
 };
 
 /**
diff --git a/src/gallium/state_trackers/clover/core/device.cpp b/src/gallium/state_trackers/clover/core/device.cpp
index 94faeee..e8ed975 100644
--- a/src/gallium/state_trackers/clover/core/device.cpp
+++ b/src/gallium/state_trackers/clover/core/device.cpp
@@ -163,6 +163,14 @@ _cl_device_id::max_mem_alloc_size() const {
                                       PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE)[0];
 }
 
+size_t
+_cl_device_id::kernel_arg_alignment(size_t type_size) const {
+   size_t size = type_size;
+   pipe->get_compute_param(pipe, PIPE_COMPUTE_CAP_KERNEL_ARG_ALIGNMENT,
+                                  &size);
+   return size;
+}
+
 std::vector<size_t>
 _cl_device_id::max_block_size() const {
    auto v = get_compute_param<uint64_t>(pipe, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
diff --git a/src/gallium/state_trackers/clover/core/device.hpp b/src/gallium/state_trackers/clover/core/device.hpp
index 61b690b..bfe84b0 100644
--- a/src/gallium/state_trackers/clover/core/device.hpp
+++ b/src/gallium/state_trackers/clover/core/device.hpp
@@ -60,6 +60,7 @@ public:
    cl_uint max_const_buffers() const;
    size_t max_threads_per_block() const;
    cl_ulong max_mem_alloc_size() const;
+   size_t kernel_arg_alignment(size_t type_size) const;
 
    std::vector<size_t> max_block_size() const;
    std::string device_name() const;
-- 
1.7.11.4



More information about the mesa-dev mailing list