Hi,
This patch removes the goacc_parse_device_num function in libgomp's
env.c since it is redundant with parse_int. I also added some bounds
checking for the device number in oacc-init.c (the behaviour is left as
"implementation defined" in the OpenACC 2.0 spec, so I chose to raise
an error for an out-of-range device number).
OK for gomp4 branch?
Thanks,
Julian
ChangeLog
libgomp/
* env.c (goacc_parse_device_num): Remove.
(initialize_env): Use parse_int instead of goacc_parse_device_num.
* oacc-init.c (lazy_open): Add bounds check for device number.
commit 1dacb833b33d179553723faecf4b32e89efc69a9
Author: Julian Brown <jul...@codesourcery.com>
Date: Tue Oct 28 06:03:47 2014 -0700
ACC_DEVICE_NUM tweaks
diff --git a/libgomp/env.c b/libgomp/env.c
index 8b22e6f..02bce0c 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -1016,27 +1016,6 @@ parse_affinity (bool ignore)
return false;
}
-
-static void
-goacc_parse_device_num (void)
-{
- const char *env = getenv ("ACC_DEVICE_NUM");
- int default_num = -1;
-
- if (env && *env != '\0')
- {
- char *end;
- default_num = strtol (env, &end, 0);
-
- if (*end || default_num < 0)
- default_num = 0;
- }
- else
- default_num = 0;
-
- goacc_device_num = default_num;
-}
-
static void
goacc_parse_device_type (void)
{
@@ -1310,7 +1289,9 @@ initialize_env (void)
handle_omp_display_env (stacksize, wait_policy);
/* Look for OpenACC-specific environment variables. */
- goacc_parse_device_num ();
+ if (!parse_int ("ACC_DEVICE_NUM", &goacc_device_num, true))
+ goacc_device_num = 0;
+
goacc_parse_device_type ();
/* Initialize OpenACC-specific internal state. */
diff --git a/libgomp/oacc-init.c b/libgomp/oacc-init.c
index 489ac14..24e911b 100644
--- a/libgomp/oacc-init.c
+++ b/libgomp/oacc-init.c
@@ -249,6 +249,9 @@ lazy_open (int ord)
if (ord < 0)
ord = goacc_device_num;
+ if (ord >= base_dev->get_num_devices_func ())
+ gomp_fatal ("device %u does not exist", ord);
+
if (!thr)
thr = goacc_new_thread ();