summaryrefslogtreecommitdiff
path: root/libgomp
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@codesourcery.com>2020-01-10 23:24:36 +0100
committerThomas Schwinge <tschwinge@gcc.gnu.org>2020-01-10 23:24:36 +0100
commit6fc0385c0ce39470e137eab27dee8955b3f98258 (patch)
tree0a95a071bafad5393c048a74bec3cdb005499f3d /libgomp
parentb3b75e664a619dae98571a0b3ac8034f5fa7c2be (diff)
OpenACC 'acc_get_property' cleanup
include/ * gomp-constants.h (enum gomp_device_property): Remove. libgomp/ * libgomp-plugin.h (enum goacc_property): New. Adjust all users to use this instead of 'enum gomp_device_property'. (GOMP_OFFLOAD_get_property): Rename to... (GOMP_OFFLOAD_openacc_get_property): ... this. Adjust all users. * libgomp.h (struct gomp_device_descr): Move 'GOMP_OFFLOAD_openacc_get_property'... (struct acc_dispatch_t): ... here. Adjust all users. * plugin/plugin-hsa.c (GOMP_OFFLOAD_get_property): Remove. liboffloadmic/ * plugin/libgomp-plugin-intelmic.cpp (GOMP_OFFLOAD_get_property): Remove. From-SVN: r280150
Diffstat (limited to 'libgomp')
-rw-r--r--libgomp/ChangeLog9
-rw-r--r--libgomp/libgomp-plugin.h36
-rw-r--r--libgomp/libgomp.h3
-rw-r--r--libgomp/oacc-host.c47
-rw-r--r--libgomp/oacc-init.c10
-rw-r--r--libgomp/openacc.f902
-rw-r--r--libgomp/openacc.h3
-rw-r--r--libgomp/plugin/plugin-gcn.c22
-rw-r--r--libgomp/plugin/plugin-hsa.c26
-rw-r--r--libgomp/plugin/plugin-nvptx.c138
-rw-r--r--libgomp/target.c4
11 files changed, 154 insertions, 146 deletions
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 81d0c164a3a..de286ddac7c 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,5 +1,14 @@
2020-01-10 Thomas Schwinge <thomas@codesourcery.com>
+ * libgomp-plugin.h (enum goacc_property): New. Adjust all users
+ to use this instead of 'enum gomp_device_property'.
+ (GOMP_OFFLOAD_get_property): Rename to...
+ (GOMP_OFFLOAD_openacc_get_property): ... this. Adjust all users.
+ * libgomp.h (struct gomp_device_descr): Move
+ 'GOMP_OFFLOAD_openacc_get_property'...
+ (struct acc_dispatch_t): ... here. Adjust all users.
+ * plugin/plugin-hsa.c (GOMP_OFFLOAD_get_property): Remove.
+
* target.c (gomp_map_vars_internal)
<GOMP_MAP_USE_DEVICE_PTR_IF_PRESENT>: Clean up/elaborate code
paths.
diff --git a/libgomp/libgomp-plugin.h b/libgomp/libgomp-plugin.h
index 2559ce0ea3a..64f138d3821 100644
--- a/libgomp/libgomp-plugin.h
+++ b/libgomp/libgomp-plugin.h
@@ -54,13 +54,6 @@ enum offload_target_type
OFFLOAD_TARGET_TYPE_GCN = 8
};
-/* Container type for passing device properties. */
-union gomp_device_property_value
-{
- const char *ptr;
- size_t val;
-};
-
/* Opaque type to represent plugin-dependent implementation of an
OpenACC asynchronous queue. */
struct goacc_asyncqueue;
@@ -75,6 +68,32 @@ struct goacc_asyncqueue_list
typedef struct goacc_asyncqueue *goacc_aq;
typedef struct goacc_asyncqueue_list *goacc_aq_list;
+
+/* OpenACC 'acc_get_property' support. */
+
+/* Device property values. Keep in sync with
+ 'libgomp/{openacc.h,openacc.f90}:acc_device_property_t'. */
+enum goacc_property
+ {
+ /* Mask to tell numeric and string values apart. */
+#define GOACC_PROPERTY_STRING_MASK 0x10000
+
+ /* Start from 1 to catch uninitialized use. */
+ GOACC_PROPERTY_MEMORY = 1,
+ GOACC_PROPERTY_FREE_MEMORY = 2,
+ GOACC_PROPERTY_NAME = GOACC_PROPERTY_STRING_MASK | 1,
+ GOACC_PROPERTY_VENDOR = GOACC_PROPERTY_STRING_MASK | 2,
+ GOACC_PROPERTY_DRIVER = GOACC_PROPERTY_STRING_MASK | 3
+ };
+
+/* Container type for passing device properties. */
+union goacc_property_value
+{
+ const char *ptr;
+ size_t val;
+};
+
+
/* Auxiliary struct, used for transferring pairs of addresses from plugin
to libgomp. */
struct addr_pair
@@ -101,7 +120,6 @@ extern const char *GOMP_OFFLOAD_get_name (void);
extern unsigned int GOMP_OFFLOAD_get_caps (void);
extern int GOMP_OFFLOAD_get_type (void);
extern int GOMP_OFFLOAD_get_num_devices (void);
-extern union gomp_device_property_value GOMP_OFFLOAD_get_property (int, int);
extern bool GOMP_OFFLOAD_init_device (int);
extern bool GOMP_OFFLOAD_fini_device (int);
extern unsigned GOMP_OFFLOAD_version (void);
@@ -141,6 +159,8 @@ extern void *GOMP_OFFLOAD_openacc_cuda_get_current_context (void);
extern void *GOMP_OFFLOAD_openacc_cuda_get_stream (struct goacc_asyncqueue *);
extern int GOMP_OFFLOAD_openacc_cuda_set_stream (struct goacc_asyncqueue *,
void *);
+extern union goacc_property_value
+ GOMP_OFFLOAD_openacc_get_property (int, enum goacc_property);
#ifdef __cplusplus
}
diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index 44703aaae6a..f5415bb156c 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -1068,6 +1068,8 @@ typedef struct acc_dispatch_t
__typeof (GOMP_OFFLOAD_openacc_async_host2dev) *host2dev_func;
} async;
+ __typeof (GOMP_OFFLOAD_openacc_get_property) *get_property_func;
+
/* NVIDIA target specific routines. */
struct {
__typeof (GOMP_OFFLOAD_openacc_cuda_get_current_device)
@@ -1113,7 +1115,6 @@ struct gomp_device_descr
__typeof (GOMP_OFFLOAD_get_caps) *get_caps_func;
__typeof (GOMP_OFFLOAD_get_type) *get_type_func;
__typeof (GOMP_OFFLOAD_get_num_devices) *get_num_devices_func;
- __typeof (GOMP_OFFLOAD_get_property) *get_property_func;
__typeof (GOMP_OFFLOAD_init_device) *init_device_func;
__typeof (GOMP_OFFLOAD_fini_device) *fini_device_func;
__typeof (GOMP_OFFLOAD_version) *version_func;
diff --git a/libgomp/oacc-host.c b/libgomp/oacc-host.c
index 22c18942752..46387897b13 100644
--- a/libgomp/oacc-host.c
+++ b/libgomp/oacc-host.c
@@ -59,27 +59,6 @@ host_get_num_devices (void)
return 1;
}
-static union gomp_device_property_value
-host_get_property (int n, int prop)
-{
- union gomp_device_property_value nullval = { .val = 0 };
-
- if (n >= host_get_num_devices ())
- return nullval;
-
- switch (prop)
- {
- case GOMP_DEVICE_PROPERTY_NAME:
- return (union gomp_device_property_value) { .ptr = "GOMP" };
- case GOMP_DEVICE_PROPERTY_VENDOR:
- return (union gomp_device_property_value) { .ptr = "GNU" };
- case GOMP_DEVICE_PROPERTY_DRIVER:
- return (union gomp_device_property_value) { .ptr = VERSION };
- default:
- return nullval;
- }
-}
-
static bool
host_init_device (int n __attribute__ ((unused)))
{
@@ -245,6 +224,29 @@ host_openacc_async_destruct (struct goacc_asyncqueue *aq
return true;
}
+static union goacc_property_value
+host_openacc_get_property (int n, enum goacc_property prop)
+{
+ union goacc_property_value nullval = { .val = 0 };
+
+ if (n >= host_get_num_devices ())
+ return nullval;
+
+ switch (prop)
+ {
+ case GOACC_PROPERTY_NAME:
+ return (union goacc_property_value) { .ptr = "GOMP" };
+ case GOACC_PROPERTY_VENDOR:
+ return (union goacc_property_value) { .ptr = "GNU" };
+ case GOACC_PROPERTY_DRIVER:
+ return (union goacc_property_value) { .ptr = VERSION };
+ case GOACC_PROPERTY_MEMORY:
+ case GOACC_PROPERTY_FREE_MEMORY:
+ default:
+ return nullval;
+ }
+}
+
static void *
host_openacc_create_thread_data (int ord __attribute__ ((unused)))
{
@@ -269,7 +271,6 @@ static struct gomp_device_descr host_dispatch =
.get_caps_func = host_get_caps,
.get_type_func = host_get_type,
.get_num_devices_func = host_get_num_devices,
- .get_property_func = host_get_property,
.init_device_func = host_init_device,
.fini_device_func = host_fini_device,
.version_func = host_version,
@@ -303,6 +304,8 @@ static struct gomp_device_descr host_dispatch =
.host2dev_func = host_openacc_async_host2dev,
},
+ .get_property_func = host_openacc_get_property,
+
.cuda = {
.get_current_device_func = NULL,
.get_current_context_func = NULL,
diff --git a/libgomp/oacc-init.c b/libgomp/oacc-init.c
index d15f08f7e18..89a30b3e716 100644
--- a/libgomp/oacc-init.c
+++ b/libgomp/oacc-init.c
@@ -760,14 +760,14 @@ acc_set_device_num (int ord, acc_device_t d)
ialias (acc_set_device_num)
-static union gomp_device_property_value
+static union goacc_property_value
get_property_any (int ord, acc_device_t d, acc_device_property_t prop)
{
goacc_lazy_initialize ();
struct goacc_thread *thr = goacc_thread ();
if (d == acc_device_current && thr && thr->dev)
- return thr->dev->get_property_func (thr->dev->target_id, prop);
+ return thr->dev->openacc.get_property_func (thr->dev->target_id, prop);
gomp_mutex_lock (&acc_device_lock);
@@ -789,7 +789,7 @@ get_property_any (int ord, acc_device_t d, acc_device_property_t prop)
assert (dev);
- return dev->get_property_func (dev->target_id, prop);
+ return dev->openacc.get_property_func (dev->target_id, prop);
}
size_t
@@ -798,7 +798,7 @@ acc_get_property (int ord, acc_device_t d, acc_device_property_t prop)
if (!known_device_type_p (d))
unknown_device_type_error(d);
- if (prop & GOMP_DEVICE_PROPERTY_STRING_MASK)
+ if (prop & GOACC_PROPERTY_STRING_MASK)
return 0;
else
return get_property_any (ord, d, prop).val;
@@ -812,7 +812,7 @@ acc_get_property_string (int ord, acc_device_t d, acc_device_property_t prop)
if (!known_device_type_p (d))
unknown_device_type_error(d);
- if (prop & GOMP_DEVICE_PROPERTY_STRING_MASK)
+ if (prop & GOACC_PROPERTY_STRING_MASK)
return get_property_any (ord, d, prop).ptr;
else
return NULL;
diff --git a/libgomp/openacc.f90 b/libgomp/openacc.f90
index a3083168a3a..6c92c7c12c9 100644
--- a/libgomp/openacc.f90
+++ b/libgomp/openacc.f90
@@ -53,7 +53,7 @@ module openacc_kinds
integer, parameter :: acc_device_property = c_size_t
- ! Keep in sync with include/gomp-constants.h.
+ ! Keep in sync with 'libgomp/libgomp-plugin.h:goacc_property'.
integer (acc_device_property), parameter :: acc_property_memory = 1
integer (acc_device_property), parameter :: acc_property_free_memory = 2
integer (acc_device_property), parameter :: acc_property_name = int(Z'10001')
diff --git a/libgomp/openacc.h b/libgomp/openacc.h
index 66786d7521f..62b2b0ea559 100644
--- a/libgomp/openacc.h
+++ b/libgomp/openacc.h
@@ -64,8 +64,7 @@ typedef enum acc_device_t {
} acc_device_t;
typedef enum acc_device_property_t {
- /* Keep in sync with include/gomp-constants.h. */
- /* Start from 1 to catch uninitialized use. */
+ /* Keep in sync with 'libgomp/libgomp-plugin.h:goacc_property'. */
acc_property_memory = 1,
acc_property_free_memory = 2,
acc_property_name = 0x10001,
diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index b5ca7c1b4bd..16ce251f3a5 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -3236,17 +3236,6 @@ GOMP_OFFLOAD_get_num_devices (void)
return hsa_context.agent_count;
}
-union gomp_device_property_value
-GOMP_OFFLOAD_get_property (int device, int prop)
-{
- /* Stub. Check device and return default value for unsupported properties. */
- /* TODO: Implement this function. */
- get_agent_info (device);
-
- union gomp_device_property_value nullval = { .val = 0 };
- return nullval;
-}
-
/* Initialize device (agent) number N so that it can be used for computation.
Return TRUE on success. */
@@ -3999,6 +3988,17 @@ GOMP_OFFLOAD_openacc_async_dev2host (int device, void *dst, const void *src,
return true;
}
+union goacc_property_value
+GOMP_OFFLOAD_openacc_get_property (int device, enum goacc_property prop)
+{
+ /* Stub. Check device and return default value for unsupported properties. */
+ /* TODO: Implement this function. */
+ get_agent_info (device);
+
+ union goacc_property_value nullval = { .val = 0 };
+ return nullval;
+}
+
/* Set up plugin-specific thread-local-data (host-side). */
void *
diff --git a/libgomp/plugin/plugin-hsa.c b/libgomp/plugin/plugin-hsa.c
index b04923b1920..abd3bc64163 100644
--- a/libgomp/plugin/plugin-hsa.c
+++ b/libgomp/plugin/plugin-hsa.c
@@ -699,32 +699,6 @@ GOMP_OFFLOAD_get_num_devices (void)
return hsa_context.agent_count;
}
-/* Part of the libgomp plugin interface. Return the value of property
- PROP of agent number N. */
-
-union gomp_device_property_value
-GOMP_OFFLOAD_get_property (int n, int prop)
-{
- union gomp_device_property_value nullval = { .val = 0 };
-
- if (!init_hsa_context ())
- return nullval;
- if (n >= hsa_context.agent_count)
- {
- GOMP_PLUGIN_error
- ("Request for a property of a non-existing HSA device %i", n);
- return nullval;
- }
-
- switch (prop)
- {
- case GOMP_DEVICE_PROPERTY_VENDOR:
- return (union gomp_device_property_value) { .ptr = "HSA" };
- default:
- return nullval;
- }
-}
-
/* Part of the libgomp plugin interface. Initialize agent number N so that it
can be used for computation. Return TRUE on success. */
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index e867b4cdedb..6033c71a9db 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -1121,74 +1121,6 @@ GOMP_OFFLOAD_get_num_devices (void)
return nvptx_get_num_devices ();
}
-union gomp_device_property_value
-GOMP_OFFLOAD_get_property (int n, int prop)
-{
- union gomp_device_property_value propval = { .val = 0 };
-
- pthread_mutex_lock (&ptx_dev_lock);
-
- if (n >= nvptx_get_num_devices () || n < 0 || ptx_devices[n] == NULL)
- {
- pthread_mutex_unlock (&ptx_dev_lock);
- return propval;
- }
-
- struct ptx_device *ptx_dev = ptx_devices[n];
- switch (prop)
- {
- case GOMP_DEVICE_PROPERTY_MEMORY:
- {
- size_t total_mem;
-
- CUDA_CALL_ERET (propval, cuDeviceTotalMem, &total_mem, ptx_dev->dev);
- propval.val = total_mem;
- }
- break;
- case GOMP_DEVICE_PROPERTY_FREE_MEMORY:
- {
- size_t total_mem;
- size_t free_mem;
- CUdevice ctxdev;
-
- CUDA_CALL_ERET (propval, cuCtxGetDevice, &ctxdev);
- if (ptx_dev->dev == ctxdev)
- CUDA_CALL_ERET (propval, cuMemGetInfo, &free_mem, &total_mem);
- else if (ptx_dev->ctx)
- {
- CUcontext old_ctx;
-
- CUDA_CALL_ERET (propval, cuCtxPushCurrent, ptx_dev->ctx);
- CUDA_CALL_ERET (propval, cuMemGetInfo, &free_mem, &total_mem);
- CUDA_CALL_ASSERT (cuCtxPopCurrent, &old_ctx);
- }
- else
- {
- CUcontext new_ctx;
-
- CUDA_CALL_ERET (propval, cuCtxCreate, &new_ctx, CU_CTX_SCHED_AUTO,
- ptx_dev->dev);
- CUDA_CALL_ERET (propval, cuMemGetInfo, &free_mem, &total_mem);
- CUDA_CALL_ASSERT (cuCtxDestroy, new_ctx);
- }
- propval.val = free_mem;
- }
- break;
- case GOMP_DEVICE_PROPERTY_NAME:
- propval.ptr = ptx_dev->name;
- break;
- case GOMP_DEVICE_PROPERTY_VENDOR:
- propval.ptr = "Nvidia";
- break;
- case GOMP_DEVICE_PROPERTY_DRIVER:
- propval.ptr = cuda_driver_version_s;
- break;
- }
-
- pthread_mutex_unlock (&ptx_dev_lock);
- return propval;
-}
-
bool
GOMP_OFFLOAD_init_device (int n)
{
@@ -1818,6 +1750,76 @@ GOMP_OFFLOAD_openacc_async_dev2host (int ord, void *dst, const void *src,
return true;
}
+union goacc_property_value
+GOMP_OFFLOAD_openacc_get_property (int n, enum goacc_property prop)
+{
+ union goacc_property_value propval = { .val = 0 };
+
+ pthread_mutex_lock (&ptx_dev_lock);
+
+ if (n >= nvptx_get_num_devices () || n < 0 || ptx_devices[n] == NULL)
+ {
+ pthread_mutex_unlock (&ptx_dev_lock);
+ return propval;
+ }
+
+ struct ptx_device *ptx_dev = ptx_devices[n];
+ switch (prop)
+ {
+ case GOACC_PROPERTY_MEMORY:
+ {
+ size_t total_mem;
+
+ CUDA_CALL_ERET (propval, cuDeviceTotalMem, &total_mem, ptx_dev->dev);
+ propval.val = total_mem;
+ }
+ break;
+ case GOACC_PROPERTY_FREE_MEMORY:
+ {
+ size_t total_mem;
+ size_t free_mem;
+ CUdevice ctxdev;
+
+ CUDA_CALL_ERET (propval, cuCtxGetDevice, &ctxdev);
+ if (ptx_dev->dev == ctxdev)
+ CUDA_CALL_ERET (propval, cuMemGetInfo, &free_mem, &total_mem);
+ else if (ptx_dev->ctx)
+ {
+ CUcontext old_ctx;
+
+ CUDA_CALL_ERET (propval, cuCtxPushCurrent, ptx_dev->ctx);
+ CUDA_CALL_ERET (propval, cuMemGetInfo, &free_mem, &total_mem);
+ CUDA_CALL_ASSERT (cuCtxPopCurrent, &old_ctx);
+ }
+ else
+ {
+ CUcontext new_ctx;
+
+ CUDA_CALL_ERET (propval, cuCtxCreate, &new_ctx, CU_CTX_SCHED_AUTO,
+ ptx_dev->dev);
+ CUDA_CALL_ERET (propval, cuMemGetInfo, &free_mem, &total_mem);
+ CUDA_CALL_ASSERT (cuCtxDestroy, new_ctx);
+ }
+ propval.val = free_mem;
+ }
+ break;
+ case GOACC_PROPERTY_NAME:
+ propval.ptr = ptx_dev->name;
+ break;
+ case GOACC_PROPERTY_VENDOR:
+ propval.ptr = "Nvidia";
+ break;
+ case GOACC_PROPERTY_DRIVER:
+ propval.ptr = cuda_driver_version_s;
+ break;
+ default:
+ break;
+ }
+
+ pthread_mutex_unlock (&ptx_dev_lock);
+ return propval;
+}
+
/* Adjust launch dimensions: pick good values for number of blocks and warps
and ensure that number of warps does not exceed CUDA limits as well as GCC's
own limits. */
diff --git a/libgomp/target.c b/libgomp/target.c
index 38de1c0cf92..3df007283f4 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -3028,7 +3028,6 @@ gomp_load_plugin_for_device (struct gomp_device_descr *device,
DLSYM (get_caps);
DLSYM (get_type);
DLSYM (get_num_devices);
- DLSYM (get_property);
DLSYM (init_device);
DLSYM (fini_device);
DLSYM (load_image);
@@ -3061,7 +3060,8 @@ gomp_load_plugin_for_device (struct gomp_device_descr *device,
openacc_async_queue_callback)
|| !DLSYM_OPT (openacc.async.exec, openacc_async_exec)
|| !DLSYM_OPT (openacc.async.dev2host, openacc_async_dev2host)
- || !DLSYM_OPT (openacc.async.host2dev, openacc_async_host2dev))
+ || !DLSYM_OPT (openacc.async.host2dev, openacc_async_host2dev)
+ || !DLSYM_OPT (openacc.get_property, openacc_get_property))
{
/* Require all the OpenACC handlers if we have
GOMP_OFFLOAD_CAP_OPENACC_200. */