Avoid assert for unknown device ISAs in GCN libgomp plugin

Message ID 20240126103245.8D575385828D@sourceware.org
State Accepted
Headers
Series Avoid assert for unknown device ISAs in GCN libgomp plugin |

Checks

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

Commit Message

Richard Biener Jan. 26, 2024, 10:30 a.m. UTC
  When the agent reports a device ISA we don't support avoid hitting
an assert, instead report the raw integers as error.  I'm not sure
whether -1 is special as I didn't figure where that field is
initialized.  But I guess since agents are not rejected upfront
when registering them I might be able to force execution to an
unsupported one.

An alternative would maybe to change get_agent_info () to return NULL
for unsupported ISAs?

Tested on x86_64-unknown-linux-gnu -> amdgcn-hsa with gfx1060

OK?

Thanks,
Richard.

libgomp/
	* plugin/plugin-gcn.c (isa_matches_agent): Avoid asserting we
	only get supported device ISAs.  Report raw numbers when not.
---
 libgomp/plugin/plugin-gcn.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
  

Patch

diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index db28781dedb..d8c3907c108 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -2459,13 +2459,15 @@  isa_matches_agent (struct agent_info *agent, Elf64_Ehdr *image)
       char msg[120];
       const char *agent_isa_s = isa_hsa_name (agent->device_isa);
       const char *agent_isa_gcc_s = isa_gcc_name (agent->device_isa);
-      assert (agent_isa_s);
-      assert (agent_isa_gcc_s);
-
-      snprintf (msg, sizeof msg,
-		"GCN code object ISA '%s' does not match GPU ISA '%s'.\n"
-		"Try to recompile with '-foffload-options=-march=%s'.\n",
-		isa_s, agent_isa_s, agent_isa_gcc_s);
+      if (agent_isa_s && agent_isa_gcc_s)
+	snprintf (msg, sizeof msg,
+		  "GCN code object ISA '%s' does not match GPU ISA '%s'.\n"
+		  "Try to recompile with '-foffload-options=-march=%s'.\n",
+		  isa_s, agent_isa_s, agent_isa_gcc_s);
+      else
+	snprintf (msg, sizeof msg,
+		  "GCN code object ISA '%s' (%d) does not match GPU ISA %d.\n",
+		  isa_s, isa_field, agent->device_isa);
 
       hsa_error (msg, HSA_STATUS_ERROR);
       return false;