gpu-compute: Fix LDS out-of-bounds behavior
authorTony Gutierrez <anthony.gutierrez@amd.com>
Thu, 14 Jun 2018 19:22:03 +0000 (15:22 -0400)
committerAnthony Gutierrez <anthony.gutierrez@amd.com>
Thu, 16 Jul 2020 20:37:22 +0000 (20:37 +0000)
The LDS is capable of handling out-of-bounds accesses,
that is, accesses that are outside the bounds of the
chunk allocated to a WG. Currently, the simulator asserts
on these accesses. This patch changes the behavior of the
LDS to return 0 for reads and dropping writes that are
out-of-bounds.

Change-Id: I5f467d0f52113e8565e1a3029e82fb89cc6f07ea
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/29940
Maintainer: Anthony Gutierrez <anthony.gutierrez@amd.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Matt Sinclair <mattdsinclair@gmail.com>
src/gpu-compute/lds_state.hh

index 58171e30cb095c5f00192d7c6aae2775d2375c25..d793f0f9e5865cb3cc19f01b18ad8b801ac1656b 100644 (file)
@@ -69,9 +69,14 @@ class LdsChunk
     T
     read(const uint32_t index)
     {
-        fatal_if(!chunk.size(), "cannot read from an LDS chunk of size 0");
-        fatal_if(index >= chunk.size(), "out-of-bounds access to an LDS "
-            "chunk");
+        /**
+         * For reads that are outside the bounds of the LDS
+         * chunk allocated to this WG we return 0.
+         */
+        if (index >= chunk.size()) {
+            return (T)0;
+        }
+
         T *p0 = (T *) (&(chunk.at(index)));
         return *p0;
     }
@@ -83,9 +88,14 @@ class LdsChunk
     void
     write(const uint32_t index, const T value)
     {
-        fatal_if(!chunk.size(), "cannot write to an LDS chunk of size 0");
-        fatal_if(index >= chunk.size(), "out-of-bounds access to an LDS "
-            "chunk");
+        /**
+         * Writes that are outside the bounds of the LDS
+         * chunk allocated to this WG are dropped.
+         */
+        if (index >= chunk.size()) {
+            return;
+        }
+
         T *p0 = (T *) (&(chunk.at(index)));
         *p0 = value;
     }