mirror of git://gcc.gnu.org/git/gcc.git
oacc-init.c (resolve_device): Add FAIL_IS_ERROR argument.
* oacc-init.c (resolve_device): Add FAIL_IS_ERROR argument. Update function comment. Only call gomp_fatal if new argument is true. (acc_dev_num_out_of_range): New function. (acc_init_1, acc_shutdown_1): Update call to resolve_device. Call acc_dev_num_out_of_range as appropriate. (acc_get_num_devices, acc_set_device_type, acc_get_device_type) (acc_get_device_num, acc_set_device_num): Update calls to resolve_device. * testsuite/libgomp.oacc-c-c++-common/lib-4.c: Update expected test output. From-SVN: r223803
This commit is contained in:
parent
32eaed9380
commit
9fb5fd444b
|
|
@ -1,3 +1,15 @@
|
||||||
|
2015-05-28 Julian Brown <julian@codesourcery.com>
|
||||||
|
|
||||||
|
* oacc-init.c (resolve_device): Add FAIL_IS_ERROR argument. Update
|
||||||
|
function comment. Only call gomp_fatal if new argument is true.
|
||||||
|
(acc_dev_num_out_of_range): New function.
|
||||||
|
(acc_init_1, acc_shutdown_1): Update call to resolve_device. Call
|
||||||
|
acc_dev_num_out_of_range as appropriate.
|
||||||
|
(acc_get_num_devices, acc_set_device_type, acc_get_device_type)
|
||||||
|
(acc_get_device_num, acc_set_device_num): Update calls to resolve_device.
|
||||||
|
* testsuite/libgomp.oacc-c-c++-common/lib-4.c: Update expected test
|
||||||
|
output.
|
||||||
|
|
||||||
2015-05-28 Julian Brown <julian@codesourcery.com>
|
2015-05-28 Julian Brown <julian@codesourcery.com>
|
||||||
|
|
||||||
PR libgomp/65742
|
PR libgomp/65742
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,12 @@ name_of_acc_device_t (enum acc_device_t type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ACC_DEVICE_LOCK should be held before calling this function. */
|
/* ACC_DEVICE_LOCK must be held before calling this function. If FAIL_IS_ERROR
|
||||||
|
is true, this function raises an error if there are no devices of type D,
|
||||||
|
otherwise it returns NULL in that case. */
|
||||||
|
|
||||||
static struct gomp_device_descr *
|
static struct gomp_device_descr *
|
||||||
resolve_device (acc_device_t d)
|
resolve_device (acc_device_t d, bool fail_is_error)
|
||||||
{
|
{
|
||||||
acc_device_t d_arg = d;
|
acc_device_t d_arg = d;
|
||||||
|
|
||||||
|
|
@ -130,7 +132,13 @@ resolve_device (acc_device_t d)
|
||||||
&& dispatchers[d]->get_num_devices_func () > 0)
|
&& dispatchers[d]->get_num_devices_func () > 0)
|
||||||
goto found;
|
goto found;
|
||||||
|
|
||||||
gomp_fatal ("device type %s not supported", goacc_device_type);
|
if (fail_is_error)
|
||||||
|
{
|
||||||
|
gomp_mutex_unlock (&acc_device_lock);
|
||||||
|
gomp_fatal ("device type %s not supported", goacc_device_type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No default device specified, so start scanning for any non-host
|
/* No default device specified, so start scanning for any non-host
|
||||||
|
|
@ -149,7 +157,13 @@ resolve_device (acc_device_t d)
|
||||||
d = acc_device_host;
|
d = acc_device_host;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
gomp_fatal ("no device found");
|
if (fail_is_error)
|
||||||
|
{
|
||||||
|
gomp_mutex_unlock (&acc_device_lock);
|
||||||
|
gomp_fatal ("no device found");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case acc_device_host:
|
case acc_device_host:
|
||||||
|
|
@ -157,7 +171,12 @@ resolve_device (acc_device_t d)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (d > _ACC_device_hwm)
|
if (d > _ACC_device_hwm)
|
||||||
gomp_fatal ("device %u out of range", (unsigned)d);
|
{
|
||||||
|
if (fail_is_error)
|
||||||
|
goto unsupported_device;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
found:
|
found:
|
||||||
|
|
@ -166,12 +185,30 @@ resolve_device (acc_device_t d)
|
||||||
&& d != acc_device_default
|
&& d != acc_device_default
|
||||||
&& d != acc_device_not_host);
|
&& d != acc_device_not_host);
|
||||||
|
|
||||||
|
if (dispatchers[d] == NULL && fail_is_error)
|
||||||
|
{
|
||||||
|
unsupported_device:
|
||||||
|
gomp_mutex_unlock (&acc_device_lock);
|
||||||
|
gomp_fatal ("device type %s not supported", name_of_acc_device_t (d));
|
||||||
|
}
|
||||||
|
|
||||||
return dispatchers[d];
|
return dispatchers[d];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Emit a suitable error if no device of a particular type is available, or
|
||||||
|
the given device number is out-of-range. */
|
||||||
|
static void
|
||||||
|
acc_dev_num_out_of_range (acc_device_t d, int ord, int ndevs)
|
||||||
|
{
|
||||||
|
if (ndevs == 0)
|
||||||
|
gomp_fatal ("no devices of type %s available", name_of_acc_device_t (d));
|
||||||
|
else
|
||||||
|
gomp_fatal ("device %u out of range", ord);
|
||||||
|
}
|
||||||
|
|
||||||
/* This is called when plugins have been initialized, and serves to call
|
/* This is called when plugins have been initialized, and serves to call
|
||||||
(indirectly) the target's device_init hook. Calling multiple times without
|
(indirectly) the target's device_init hook. Calling multiple times without
|
||||||
an intervening acc_shutdown_1 call is an error. ACC_DEVICE_LOCK should be
|
an intervening acc_shutdown_1 call is an error. ACC_DEVICE_LOCK must be
|
||||||
held before calling this function. */
|
held before calling this function. */
|
||||||
|
|
||||||
static struct gomp_device_descr *
|
static struct gomp_device_descr *
|
||||||
|
|
@ -180,12 +217,12 @@ acc_init_1 (acc_device_t d)
|
||||||
struct gomp_device_descr *base_dev, *acc_dev;
|
struct gomp_device_descr *base_dev, *acc_dev;
|
||||||
int ndevs;
|
int ndevs;
|
||||||
|
|
||||||
base_dev = resolve_device (d);
|
base_dev = resolve_device (d, true);
|
||||||
|
|
||||||
ndevs = base_dev->get_num_devices_func ();
|
ndevs = base_dev->get_num_devices_func ();
|
||||||
|
|
||||||
if (!base_dev || ndevs <= 0 || goacc_device_num >= ndevs)
|
if (ndevs <= 0 || goacc_device_num >= ndevs)
|
||||||
gomp_fatal ("device %s not supported", name_of_acc_device_t (d));
|
acc_dev_num_out_of_range (d, goacc_device_num, ndevs);
|
||||||
|
|
||||||
acc_dev = &base_dev[goacc_device_num];
|
acc_dev = &base_dev[goacc_device_num];
|
||||||
|
|
||||||
|
|
@ -202,7 +239,7 @@ acc_init_1 (acc_device_t d)
|
||||||
return base_dev;
|
return base_dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ACC_DEVICE_LOCK should be held before calling this function. */
|
/* ACC_DEVICE_LOCK must be held before calling this function. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
acc_shutdown_1 (acc_device_t d)
|
acc_shutdown_1 (acc_device_t d)
|
||||||
|
|
@ -213,10 +250,7 @@ acc_shutdown_1 (acc_device_t d)
|
||||||
bool devices_active = false;
|
bool devices_active = false;
|
||||||
|
|
||||||
/* Get the base device for this device type. */
|
/* Get the base device for this device type. */
|
||||||
base_dev = resolve_device (d);
|
base_dev = resolve_device (d, true);
|
||||||
|
|
||||||
if (!base_dev)
|
|
||||||
gomp_fatal ("device %s not supported", name_of_acc_device_t (d));
|
|
||||||
|
|
||||||
gomp_mutex_lock (&goacc_thread_lock);
|
gomp_mutex_lock (&goacc_thread_lock);
|
||||||
|
|
||||||
|
|
@ -366,7 +400,8 @@ goacc_attach_host_thread_to_device (int ord)
|
||||||
|
|
||||||
num_devices = base_dev->get_num_devices_func ();
|
num_devices = base_dev->get_num_devices_func ();
|
||||||
if (num_devices <= 0 || ord >= num_devices)
|
if (num_devices <= 0 || ord >= num_devices)
|
||||||
gomp_fatal ("device %u out of range", ord);
|
acc_dev_num_out_of_range (acc_device_type (base_dev->type), ord,
|
||||||
|
num_devices);
|
||||||
|
|
||||||
if (!thr)
|
if (!thr)
|
||||||
thr = goacc_new_thread ();
|
thr = goacc_new_thread ();
|
||||||
|
|
@ -426,7 +461,7 @@ acc_get_num_devices (acc_device_t d)
|
||||||
gomp_init_targets_once ();
|
gomp_init_targets_once ();
|
||||||
|
|
||||||
gomp_mutex_lock (&acc_device_lock);
|
gomp_mutex_lock (&acc_device_lock);
|
||||||
acc_dev = resolve_device (d);
|
acc_dev = resolve_device (d, false);
|
||||||
gomp_mutex_unlock (&acc_device_lock);
|
gomp_mutex_unlock (&acc_device_lock);
|
||||||
|
|
||||||
if (!acc_dev)
|
if (!acc_dev)
|
||||||
|
|
@ -456,7 +491,7 @@ acc_set_device_type (acc_device_t d)
|
||||||
if (!cached_base_dev)
|
if (!cached_base_dev)
|
||||||
gomp_init_targets_once ();
|
gomp_init_targets_once ();
|
||||||
|
|
||||||
cached_base_dev = base_dev = resolve_device (d);
|
cached_base_dev = base_dev = resolve_device (d, true);
|
||||||
acc_dev = &base_dev[goacc_device_num];
|
acc_dev = &base_dev[goacc_device_num];
|
||||||
|
|
||||||
gomp_mutex_lock (&acc_dev->lock);
|
gomp_mutex_lock (&acc_dev->lock);
|
||||||
|
|
@ -494,7 +529,7 @@ acc_get_device_type (void)
|
||||||
gomp_init_targets_once ();
|
gomp_init_targets_once ();
|
||||||
|
|
||||||
gomp_mutex_lock (&acc_device_lock);
|
gomp_mutex_lock (&acc_device_lock);
|
||||||
dev = resolve_device (acc_device_default);
|
dev = resolve_device (acc_device_default, true);
|
||||||
gomp_mutex_unlock (&acc_device_lock);
|
gomp_mutex_unlock (&acc_device_lock);
|
||||||
res = acc_device_type (dev->type);
|
res = acc_device_type (dev->type);
|
||||||
}
|
}
|
||||||
|
|
@ -514,16 +549,14 @@ acc_get_device_num (acc_device_t d)
|
||||||
struct goacc_thread *thr = goacc_thread ();
|
struct goacc_thread *thr = goacc_thread ();
|
||||||
|
|
||||||
if (d >= _ACC_device_hwm)
|
if (d >= _ACC_device_hwm)
|
||||||
gomp_fatal ("device %u out of range", (unsigned)d);
|
gomp_fatal ("unknown device type %u", (unsigned) d);
|
||||||
|
|
||||||
if (!cached_base_dev)
|
if (!cached_base_dev)
|
||||||
gomp_init_targets_once ();
|
gomp_init_targets_once ();
|
||||||
|
|
||||||
gomp_mutex_lock (&acc_device_lock);
|
gomp_mutex_lock (&acc_device_lock);
|
||||||
dev = resolve_device (d);
|
dev = resolve_device (d, true);
|
||||||
gomp_mutex_unlock (&acc_device_lock);
|
gomp_mutex_unlock (&acc_device_lock);
|
||||||
if (!dev)
|
|
||||||
gomp_fatal ("device %s not supported", name_of_acc_device_t (d));
|
|
||||||
|
|
||||||
if (thr && thr->base_dev == dev && thr->dev)
|
if (thr && thr->base_dev == dev && thr->dev)
|
||||||
return thr->dev->target_id;
|
return thr->dev->target_id;
|
||||||
|
|
@ -554,12 +587,12 @@ acc_set_device_num (int ord, acc_device_t d)
|
||||||
{
|
{
|
||||||
gomp_mutex_lock (&acc_device_lock);
|
gomp_mutex_lock (&acc_device_lock);
|
||||||
|
|
||||||
cached_base_dev = base_dev = resolve_device (d);
|
cached_base_dev = base_dev = resolve_device (d, true);
|
||||||
|
|
||||||
num_devices = base_dev->get_num_devices_func ();
|
num_devices = base_dev->get_num_devices_func ();
|
||||||
|
|
||||||
if (ord >= num_devices)
|
if (num_devices <= 0 || ord >= num_devices)
|
||||||
gomp_fatal ("device %u out of range", ord);
|
acc_dev_num_out_of_range (d, ord, num_devices);
|
||||||
|
|
||||||
acc_dev = &base_dev[ord];
|
acc_dev = &base_dev[ord];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,5 @@ main (int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* { dg-output "device \[0-9\]+ out of range" } */
|
/* { dg-output "unknown device type \[0-9\]+" } */
|
||||||
/* { dg-shouldfail "" } */
|
/* { dg-shouldfail "" } */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue