[committed] Fix libgomp use_device_* handling (PR libgomp/92028)
diff mbox series

Message ID 20191009073733.GY15914@tucnak
State New
Headers show
  • [committed] Fix libgomp use_device_* handling (PR libgomp/92028)
Related show

Commit Message

Jakub Jelinek Oct. 9, 2019, 7:37 a.m. UTC

The following is what I've intended to do but actually ended up committing
a weird
	  if (!not_found_cnt)
The code used to be at the indentation level of if, so my suspicion is that
I've marked the block in an editor and tried to move that block into the
body, but as it was inside of the block it just removed it instead and I
haven't noticed.
Anyway, the comment which Thomas requested in the PR should hopefully
explain why this needs to be done.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2019-10-09  Jakub Jelinek  <jakub@redhat.com>

	PR libgomp/92028
	* target.c (gomp_map_vars_internal): Readd the previous
	GOMP_MAP_USE_DEVICE_PTR handling code in the first loop,
	though do that just in the !not_found_cnt case.


diff mbox series

--- libgomp/target.c.jj	2019-10-07 13:09:07.038253353 +0200
+++ libgomp/target.c	2019-10-08 15:19:16.249439849 +0200
@@ -593,6 +593,30 @@  gomp_map_vars_internal (struct gomp_devi
 	  tgt->list[i].key = NULL;
 	  if (!not_found_cnt)
+	      /* In OpenMP < 5.0 and OpenACC the mapping has to be done
+		 on a separate construct prior to using use_device_{addr,ptr}.
+		 In OpenMP 5.0, map directives need to be ordered by the
+		 middle-end before the use_device_* clauses.  If
+		 !not_found_cnt, all mappings requested (if any) are already
+		 mapped, so use_device_{addr,ptr} can be resolved right away.
+		 Otherwise, if not_found_cnt, gomp_map_lookup might fail
+		 now but would succeed after performing the mappings in the
+		 following loop.  We can't defer this always to the second
+		 loop, because it is not even invoked when !not_found_cnt
+		 after the first loop.  */
+	      cur_node.host_start = (uintptr_t) hostaddrs[i];
+	      cur_node.host_end = cur_node.host_start;
+	      splay_tree_key n = gomp_map_lookup (mem_map, &cur_node);
+	      if (n == NULL)
+		{
+		  gomp_mutex_unlock (&devicep->lock);
+		  gomp_fatal ("use_device_ptr pointer wasn't mapped");
+		}
+	      cur_node.host_start -= n->host_start;
+	      hostaddrs[i]
+		= (void *) (n->tgt->tgt_start + n->tgt_offset
+			    + cur_node.host_start);
+	      tgt->list[i].offset = ~(uintptr_t) 0;
 	    tgt->list[i].offset = 0;