[PR libgomp/65742, PR middle-end/66332] OpenACC acc_on_device fixes

Backport trunk r223801:

    PR libgomp/65742

    gcc/
    * builtins.c (expand_builtin_acc_on_device): Don't use open-coded
    sequence for !ACCEL_COMPILER.

    libgomp/
    * oacc-init.c (plugin/plugin-host.h): Include.
    (acc_on_device): Check whether we're in an offloaded region for
    host_nonshm
    plugin. Don't use __builtin_acc_on_device.
    * plugin/plugin-host.c (GOMP_OFFLOAD_openacc_parallel): Set
    nonshm_exec flag in thread-local data.
    (GOMP_OFFLOAD_openacc_create_thread_data): Allocate thread-local
    data for host_nonshm plugin.
    (GOMP_OFFLOAD_openacc_destroy_thread_data): Free thread-local data
    for host_nonshm plugin.
    * plugin/plugin-host.h: New.

Mark parameters with ATTRIBUTE_UNUSED

Backport trunk r223805:

	* builtins.c (expand_builtin_acc_on_device): Mark parameters
	with ATTRIBUTE_UNUSED.

[PR libgomp/65742, PR middle-end/66332] XFAIL acc_on_device compile-time evaluation

The OpenACC 2.0a specification mandates differently, but we currently do get a
library call in the host code.

Backport trunk r224028:

	PR libgomp/65742
	PR middle-end/66332

	gcc/testsuite/
	* c-c++-common/goacc/acc_on_device-2.c: XFAIL for C, too.

From-SVN: r225822
This commit is contained in:
Thomas Schwinge 2015-07-15 13:55:00 +02:00 committed by Thomas Schwinge
parent 231ff5dde1
commit 02b9e8f24e
8 changed files with 130 additions and 12 deletions

View File

@ -1,3 +1,21 @@
2015-07-15 Thomas Schwinge <thomas@codesourcery.com>
Backport trunk r223805:
2015-05-28 H.J. Lu <hongjiu.lu@intel.com>
* builtins.c (expand_builtin_acc_on_device): Mark parameters
with ATTRIBUTE_UNUSED.
Backport trunk r223801:
2015-05-28 Julian Brown <julian@codesourcery.com>
PR libgomp/65742
* builtins.c (expand_builtin_acc_on_device): Don't use open-coded
sequence for !ACCEL_COMPILER.
2015-07-14 Matthias Klose <doko@ubuntu.com> 2015-07-14 Matthias Klose <doko@ubuntu.com>
PR target/66840 PR target/66840

View File

@ -5915,8 +5915,10 @@ expand_stack_save (void)
acceleration device (ACCEL_COMPILER conditional). */ acceleration device (ACCEL_COMPILER conditional). */
static rtx static rtx
expand_builtin_acc_on_device (tree exp, rtx target) expand_builtin_acc_on_device (tree exp ATTRIBUTE_UNUSED,
rtx target ATTRIBUTE_UNUSED)
{ {
#ifdef ACCEL_COMPILER
if (!validate_arglist (exp, INTEGER_TYPE, VOID_TYPE)) if (!validate_arglist (exp, INTEGER_TYPE, VOID_TYPE))
return NULL_RTX; return NULL_RTX;
@ -5925,13 +5927,8 @@ expand_builtin_acc_on_device (tree exp, rtx target)
/* Return (arg == v1 || arg == v2) ? 1 : 0. */ /* Return (arg == v1 || arg == v2) ? 1 : 0. */
machine_mode v_mode = TYPE_MODE (TREE_TYPE (arg)); machine_mode v_mode = TYPE_MODE (TREE_TYPE (arg));
rtx v = expand_normal (arg), v1, v2; rtx v = expand_normal (arg), v1, v2;
#ifdef ACCEL_COMPILER
v1 = GEN_INT (GOMP_DEVICE_NOT_HOST); v1 = GEN_INT (GOMP_DEVICE_NOT_HOST);
v2 = GEN_INT (ACCEL_COMPILER_acc_device); v2 = GEN_INT (ACCEL_COMPILER_acc_device);
#else
v1 = GEN_INT (GOMP_DEVICE_NONE);
v2 = GEN_INT (GOMP_DEVICE_HOST);
#endif
machine_mode target_mode = TYPE_MODE (integer_type_node); machine_mode target_mode = TYPE_MODE (integer_type_node);
if (!target || !register_operand (target, target_mode)) if (!target || !register_operand (target, target_mode))
target = gen_reg_rtx (target_mode); target = gen_reg_rtx (target_mode);
@ -5945,6 +5942,9 @@ expand_builtin_acc_on_device (tree exp, rtx target)
emit_label (done_label); emit_label (done_label);
return target; return target;
#else
return NULL;
#endif
} }

View File

@ -1,3 +1,13 @@
2015-07-15 Thomas Schwinge <thomas@codesourcery.com>
Backport trunk r224028:
2015-06-02 Thomas Schwinge <thomas@codesourcery.com>
PR libgomp/65742
PR middle-end/66332
* c-c++-common/goacc/acc_on_device-2.c: XFAIL for C, too.
2015-07-10 Jakub Jelinek <jakub@redhat.com> 2015-07-10 Jakub Jelinek <jakub@redhat.com>
PR middle-end/66820 PR middle-end/66820

View File

@ -20,10 +20,18 @@ f (void)
} }
/* With -fopenacc, we're expecting the builtin to be expanded, so no calls. /* With -fopenacc, we're expecting the builtin to be expanded, so no calls.
TODO: in C++, even under extern "C", the use of enum for acc_device_t TODO: in C++, even under extern "C", the use of enum for acc_device_t
perturbs expansion as a builtin, which expects an int parameter. It's fine perturbs expansion as a builtin, which expects an int parameter. It's fine
when changing acc_device_t to plain int, but that's not what we're doing in when changing acc_device_t to plain int, but that's not what we're doing in
<openacc.h>. <openacc.h>.
{ dg-final { scan-rtl-dump-times "\\\(call \[^\\n\]* acc_on_device" 0 "expand" { xfail c++ } } } */
TODO: given that we can't expand acc_on_device in
gcc/builtins.c:expand_builtin_acc_on_device for in the !ACCEL_COMPILER case
(because at that point we don't know whether we're acc_device_host or
acc_device_host_nonshm), we'll (erroneously) get a library call in the host
code.
{ dg-final { scan-rtl-dump-times "\\\(call \[^\\n\]* acc_on_device" 0 "expand" { xfail { c || c++ } } } } */
/* { dg-final { cleanup-rtl-dump "expand" } } */ /* { dg-final { cleanup-rtl-dump "expand" } } */

View File

@ -1,3 +1,23 @@
2015-07-15 Thomas Schwinge <thomas@codesourcery.com>
Backport trunk r223801:
2015-05-28 Julian Brown <julian@codesourcery.com>
PR libgomp/65742
* oacc-init.c (plugin/plugin-host.h): Include.
(acc_on_device): Check whether we're in an offloaded region for
host_nonshm
plugin. Don't use __builtin_acc_on_device.
* plugin/plugin-host.c (GOMP_OFFLOAD_openacc_parallel): Set
nonshm_exec flag in thread-local data.
(GOMP_OFFLOAD_openacc_create_thread_data): Allocate thread-local
data for host_nonshm plugin.
(GOMP_OFFLOAD_openacc_destroy_thread_data): Free thread-local data
for host_nonshm plugin.
* plugin/plugin-host.h: New.
2015-06-30 Jakub Jelinek <jakub@redhat.com> 2015-06-30 Jakub Jelinek <jakub@redhat.com>
PR middle-end/66702 PR middle-end/66702

View File

@ -29,6 +29,7 @@
#include "libgomp.h" #include "libgomp.h"
#include "oacc-int.h" #include "oacc-int.h"
#include "openacc.h" #include "openacc.h"
#include "plugin/plugin-host.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <strings.h> #include <strings.h>
@ -548,11 +549,18 @@ ialias (acc_set_device_num)
int int
acc_on_device (acc_device_t dev) acc_on_device (acc_device_t dev)
{ {
if (acc_get_device_type () == acc_device_host_nonshm) struct goacc_thread *thr = goacc_thread ();
/* We only want to appear to be the "host_nonshm" plugin from "offloaded"
code -- i.e. within a parallel region. Test a flag set by the
openacc_parallel hook of the host_nonshm plugin to determine that. */
if (acc_get_device_type () == acc_device_host_nonshm
&& thr && thr->target_tls
&& ((struct nonshm_thread *)thr->target_tls)->nonshm_exec)
return dev == acc_device_host_nonshm || dev == acc_device_not_host; return dev == acc_device_host_nonshm || dev == acc_device_not_host;
/* Just rely on the compiler builtin. */ /* For OpenACC, libgomp is only built for the host, so this is sufficient. */
return __builtin_acc_on_device (dev); return dev == acc_device_host || dev == acc_device_none;
} }
ialias (acc_on_device) ialias (acc_on_device)

View File

@ -44,6 +44,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#ifdef HOST_NONSHM_PLUGIN #ifdef HOST_NONSHM_PLUGIN
#define STATIC #define STATIC
@ -55,6 +56,10 @@
#define SELF "host: " #define SELF "host: "
#endif #endif
#ifdef HOST_NONSHM_PLUGIN
#include "plugin-host.h"
#endif
STATIC const char * STATIC const char *
GOMP_OFFLOAD_get_name (void) GOMP_OFFLOAD_get_name (void)
{ {
@ -174,7 +179,10 @@ GOMP_OFFLOAD_openacc_parallel (void (*fn) (void *),
void *targ_mem_desc __attribute__ ((unused))) void *targ_mem_desc __attribute__ ((unused)))
{ {
#ifdef HOST_NONSHM_PLUGIN #ifdef HOST_NONSHM_PLUGIN
struct nonshm_thread *thd = GOMP_PLUGIN_acc_thread ();
thd->nonshm_exec = true;
fn (devaddrs); fn (devaddrs);
thd->nonshm_exec = false;
#else #else
fn (hostaddrs); fn (hostaddrs);
#endif #endif
@ -232,11 +240,20 @@ STATIC void *
GOMP_OFFLOAD_openacc_create_thread_data (int ord GOMP_OFFLOAD_openacc_create_thread_data (int ord
__attribute__ ((unused))) __attribute__ ((unused)))
{ {
#ifdef HOST_NONSHM_PLUGIN
struct nonshm_thread *thd
= GOMP_PLUGIN_malloc (sizeof (struct nonshm_thread));
thd->nonshm_exec = false;
return thd;
#else
return NULL; return NULL;
#endif
} }
STATIC void STATIC void
GOMP_OFFLOAD_openacc_destroy_thread_data (void *tls_data GOMP_OFFLOAD_openacc_destroy_thread_data (void *tls_data)
__attribute__ ((unused)))
{ {
#ifdef HOST_NONSHM_PLUGIN
free (tls_data);
#endif
} }

View File

@ -0,0 +1,37 @@
/* OpenACC Runtime Library: acc_device_host, acc_device_host_nonshm.
Copyright (C) 2015 Free Software Foundation, Inc.
Contributed by Mentor Embedded.
This file is part of the GNU Offloading and Multi Processing Library
(libgomp).
Libgomp is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef PLUGIN_HOST_H
#define PLUGIN_HOST_H
struct nonshm_thread
{
bool nonshm_exec;
};
#endif