Avoid using an unsupported agent when offloading to GCN

Message ID 20240126104256.17E003858422@sourceware.org
State Accepted
Headers
Series Avoid using an unsupported agent when offloading to GCN |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Richard Biener Jan. 26, 2024, 10:40 a.m. UTC
  The following avoids selecting an unsupported agent early, avoiding
later asserts when we rely on it being supported.

tested on x86_64-unknown-linux-gnu -> amdhsa-gcn on gfx1060

that's the alternative to the other patch.  I do indeed seem to get
the other (unsupported) agent selected somehow after the other supported
agent finished a kernel run.  Not sure if it's the CPU or the IGPU though.

OK?  Which variant?

libgomp/
	* plugin/plugin-gcn.c (get_agent_info): When the agent isn't supported
	return NULL.
---
 libgomp/plugin/plugin-gcn.c | 7 +++++++
 1 file changed, 7 insertions(+)
  

Patch

diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index d8c3907c108..f453f630e06 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -1036,6 +1036,8 @@  print_kernel_dispatch (struct kernel_dispatch *dispatch, unsigned indent)
 /* }}}  */
 /* {{{ Utility functions  */
 
+static const char* isa_hsa_name (int isa);
+
 /* Cast the thread local storage to gcn_thread.  */
 
 static inline struct gcn_thread *
@@ -1589,6 +1591,11 @@  get_agent_info (int n)
       GOMP_PLUGIN_error ("Attempt to use an uninitialized GCN agent.");
       return NULL;
     }
+  if (!isa_hsa_name (hsa_context.agents[n].device_isa))
+    {
+      GOMP_PLUGIN_error ("Attempt to use an unsupported GCN agent.");
+      return NULL;
+    }
   return &hsa_context.agents[n];
 }