This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [libgomp, nvptx] Disable OMP_{DISPLAY_AFFINITY,AFFINITY_FORMAT} support


On 12-12-18 11:48, Tom de Vries wrote:
> On 12-12-18 10:36, Jakub Jelinek wrote:
>> On Wed, Dec 12, 2018 at 09:29:36AM +0100, Tom de Vries wrote:
>>>> This is the libgomp/ except libgomp/testsuite/ part of the gomp-5_0-branch
>>>> merge to trunk I've just committed.
>>>>
>>>> 2018-11-08  Jakub Jelinek  <jakub@redhat.com>
>>>>
>>>> 	* affinity.c (gomp_display_affinity_place): New function.
>>>> 	* affinity-fmt.c: New file.
>>>
>>>> 	* fortran.c: Include stdio.h and string.h.
>>>> 	(omp_pause_resource, omp_pause_resource_all): Add ialias_redirect.
>>>> 	(omp_get_schedule_, omp_get_schedule_8_): Mask off GFS_MONOTONIC bit.
>>>> 	(omp_set_affinity_format_, omp_get_affinity_format_,
>>>> 	omp_display_affinity_, omp_capture_affinity_, omp_pause_resource_,
>>>> 	omp_pause_resource_all_): New functions.
>>>
>>> OK for trunk?
>>>
>>> Thanks,
>>> - Tom
>>
>>> [libgomp, nvptx] Disable OMP_{DISPLAY_AFFINITY,AFFINITY_FORMAT} support
>>>
>>> Disable compilation of support for OMP_DISPLAY_AFFINITY and OMP_AFFINITY_FORMAT
>>> for nvptx.
>>>
>>> This fixes some libgomp testsuite failures for x86_64 with nvptx accelerator.
>>>
>>> Build on x86_64 with nvptx accelerator, tested libgomp.
>>>
>>> 2018-12-12  Tom de Vries  <tdevries@suse.de>
>>>
>>> 	* affinity.c (gomp_display_affinity_place): Guard with
>>> 	#ifndef LIBGOMP_OFFLOADED_ONLY.
>>> 	* fortran.c (omp_set_affinity_format_, omp_get_affinity_format_)
>>> 	(omp_display_affinity_, omp_capture_affinity_): Same.
>>> 	* libgomp/config/nvptx/affinity-fmt.c: New, empty file overriding
>>> 	libgomp/affinity-fmt.c.
>>
>> The runtime APIs should still be available inside of OpenMP regions, your
>> patch makes them unavailable.
> 
> Ah, I see.
> 
>> What exactly doesn't work?
>> hostname handling, getpid, thread_id, affinity places?
> 
> The concrete error I'm getting is unresolved symbol getpid.  This is
> caused by the AC_COMPILE_IFELSE configure test for HAVE_GETPID passing
> for nvptx, while the master newlib for nvptx does not contain getpid.
> 
>> I'd prefer for now to just stub what doesn't work in the LIBGOMP_OFFLOADED_ONLY
>> case (print "node", 0 as pid, 0 as thread id, something for affinity
>> (0 or 0-N where N is the number of warps it can support or whatever).
>>
> 
> OK, I'll give that a try.
> 

This RFC patch implements that approach for getpid and gethostname (I
wonder though whether it's not possible to turn the corresponding
configure tests into link tests, which could also fix this for nvptx).

Another problem we're running into is missing istty, pulled in by
fwrite. The nvptx newlib port does support write, but I'm unsure in what
form I should handle this.  Add configure tests for fwrite and write? Or
special case the files in the config/nvptx dir? Any advice here?

Thanks,
- Tom
[RFC][libgomp, nvptx] Fix target-5.c compilation

Libgomp test-case libgomp.c/target-5.c is failing to compile with nvptx
accelerator due to missing:
- getpid
- gethostname
- isatty (pulled in by fwrite)
in the nvptx newlib.

This demonstrator patch fixes that by minimally guarding all related locations
with ifndef LIBGOMP_OFFLOADED_ONLY, which allows the test-case (and others) to
pass.

---
 libgomp/affinity-fmt.c | 12 +++++++++++-
 libgomp/fortran.c      |  4 ++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/libgomp/affinity-fmt.c b/libgomp/affinity-fmt.c
index 9e5c5f754eb..72b511eec73 100644
--- a/libgomp/affinity-fmt.c
+++ b/libgomp/affinity-fmt.c
@@ -184,6 +184,7 @@ static void
 gomp_display_hostname (char *buffer, size_t size, size_t *ret,
 		       bool right, size_t sz)
 {
+#ifndef LIBGOMP_OFFLOADED_ONLY
 #ifdef HAVE_GETHOSTNAME
   {
     char buf[256];
@@ -227,6 +228,7 @@ gomp_display_hostname (char *buffer, size_t size, size_t *ret,
 	return;
       }
   }
+#endif
 #endif
   gomp_display_string_len (buffer, size, ret, right, sz, "node", 4);
 }
@@ -351,7 +353,7 @@ gomp_display_affinity (char *buffer, size_t size,
 	  gomp_display_hostname (buffer, size, &ret, right, sz);
 	  break;
 	case 'P':
-#ifdef HAVE_GETPID
+#if defined(HAVE_GETPID) && !defined(LIBGOMP_OFFLOADED_ONLY)
 	  val = getpid ();
 #else
 	  val = 0;
@@ -456,13 +458,17 @@ omp_display_affinity (const char *format)
   if (ret < sizeof buf)
     {
       buf[ret] = '\n';
+#ifndef LIBGOMP_OFFLOADED_ONLY
       fwrite (buf, 1, ret + 1, stderr);
+#endif
       return;
     }
   b = gomp_malloc (ret + 1);
   ialias_call (omp_capture_affinity) (b, ret + 1, format);
   b[ret] = '\n';
+#ifndef LIBGOMP_OFFLOADED_ONLY
   fwrite (b, 1, ret + 1, stderr);
+#endif
   free (b);
 }
 
@@ -477,13 +483,17 @@ gomp_display_affinity_thread (gomp_thread_handle handle,
   if (ret < sizeof buf)
     {
       buf[ret] = '\n';
+#ifndef LIBGOMP_OFFLOADED_ONLY
       fwrite (buf, 1, ret + 1, stderr);
+#endif
       return;
     }
   b = gomp_malloc (ret + 1);
   gomp_display_affinity (b, ret + 1, gomp_affinity_format_var,
   			 handle, ts, place);
   b[ret] = '\n';
+#ifndef LIBGOMP_OFFLOADED_ONLY
   fwrite (b, 1, ret + 1, stderr);
+#endif
   free (b);
 }
diff --git a/libgomp/fortran.c b/libgomp/fortran.c
index 0157baec648..21ea9482e09 100644
--- a/libgomp/fortran.c
+++ b/libgomp/fortran.c
@@ -626,7 +626,9 @@ omp_display_affinity_ (const char *format, size_t format_len)
   if (ret < sizeof buf)
     {
       buf[ret] = '\n';
+#ifndef LIBGOMP_OFFLOADED_ONLY
       fwrite (buf, 1, ret + 1, stderr);
+#endif
     }
   else
     {
@@ -635,7 +637,9 @@ omp_display_affinity_ (const char *format, size_t format_len)
 			     format_len ? fmt : gomp_affinity_format_var,
 			     gomp_thread_self (), &thr->ts, thr->place);
       b[ret] = '\n';
+#ifndef LIBGOMP_OFFLOADED_ONLY
       fwrite (b, 1, ret + 1, stderr);
+#endif
       free (b);
     }
   if (fmt && fmt != fmt_buf)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]