Home | History | Annotate | Line # | Download | only in libgomp
      1  1.3  mrg /* The libgomp plugin API.
      2  1.3  mrg 
      3  1.7  mrg    Copyright (C) 2014-2022 Free Software Foundation, Inc.
      4  1.1  mrg 
      5  1.1  mrg    Contributed by Mentor Embedded.
      6  1.1  mrg 
      7  1.1  mrg    This file is part of the GNU Offloading and Multi Processing Library
      8  1.1  mrg    (libgomp).
      9  1.1  mrg 
     10  1.1  mrg    Libgomp is free software; you can redistribute it and/or modify it
     11  1.1  mrg    under the terms of the GNU General Public License as published by
     12  1.1  mrg    the Free Software Foundation; either version 3, or (at your option)
     13  1.1  mrg    any later version.
     14  1.1  mrg 
     15  1.1  mrg    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
     16  1.1  mrg    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     17  1.1  mrg    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
     18  1.1  mrg    more details.
     19  1.1  mrg 
     20  1.1  mrg    Under Section 7 of GPL version 3, you are granted additional
     21  1.1  mrg    permissions described in the GCC Runtime Library Exception, version
     22  1.1  mrg    3.1, as published by the Free Software Foundation.
     23  1.1  mrg 
     24  1.1  mrg    You should have received a copy of the GNU General Public License and
     25  1.1  mrg    a copy of the GCC Runtime Library Exception along with this program;
     26  1.1  mrg    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     27  1.1  mrg    <http://www.gnu.org/licenses/>.  */
     28  1.1  mrg 
     29  1.1  mrg #ifndef LIBGOMP_PLUGIN_H
     30  1.1  mrg #define LIBGOMP_PLUGIN_H 1
     31  1.1  mrg 
     32  1.3  mrg #include <stdbool.h>
     33  1.1  mrg #include <stddef.h>
     34  1.1  mrg #include <stdint.h>
     35  1.1  mrg 
     36  1.1  mrg #ifdef __cplusplus
     37  1.1  mrg extern "C" {
     38  1.1  mrg #endif
     39  1.1  mrg 
     40  1.1  mrg /* Capabilities of offloading devices.  */
     41  1.1  mrg #define GOMP_OFFLOAD_CAP_SHARED_MEM	(1 << 0)
     42  1.1  mrg #define GOMP_OFFLOAD_CAP_NATIVE_EXEC	(1 << 1)
     43  1.1  mrg #define GOMP_OFFLOAD_CAP_OPENMP_400	(1 << 2)
     44  1.1  mrg #define GOMP_OFFLOAD_CAP_OPENACC_200	(1 << 3)
     45  1.1  mrg 
     46  1.1  mrg /* Type of offload target device.  Keep in sync with include/gomp-constants.h.  */
     47  1.1  mrg enum offload_target_type
     48  1.1  mrg {
     49  1.1  mrg   OFFLOAD_TARGET_TYPE_HOST = 2,
     50  1.3  mrg   /* OFFLOAD_TARGET_TYPE_HOST_NONSHM = 3 removed.  */
     51  1.1  mrg   OFFLOAD_TARGET_TYPE_NVIDIA_PTX = 5,
     52  1.3  mrg   OFFLOAD_TARGET_TYPE_INTEL_MIC = 6,
     53  1.6  mrg   OFFLOAD_TARGET_TYPE_HSA = 7,
     54  1.6  mrg   OFFLOAD_TARGET_TYPE_GCN = 8
     55  1.1  mrg };
     56  1.1  mrg 
     57  1.6  mrg /* Opaque type to represent plugin-dependent implementation of an
     58  1.6  mrg    OpenACC asynchronous queue.  */
     59  1.6  mrg struct goacc_asyncqueue;
     60  1.6  mrg 
     61  1.6  mrg /* Used to keep a list of active asynchronous queues.  */
     62  1.6  mrg struct goacc_asyncqueue_list
     63  1.6  mrg {
     64  1.6  mrg   struct goacc_asyncqueue *aq;
     65  1.6  mrg   struct goacc_asyncqueue_list *next;
     66  1.6  mrg };
     67  1.6  mrg 
     68  1.6  mrg typedef struct goacc_asyncqueue *goacc_aq;
     69  1.6  mrg typedef struct goacc_asyncqueue_list *goacc_aq_list;
     70  1.6  mrg 
     71  1.6  mrg 
     72  1.6  mrg /* OpenACC 'acc_get_property' support.  */
     73  1.6  mrg 
     74  1.6  mrg /* Device property values.  Keep in sync with
     75  1.6  mrg    'libgomp/{openacc.h,openacc.f90}:acc_device_property_t'.  */
     76  1.6  mrg enum goacc_property
     77  1.6  mrg   {
     78  1.6  mrg    /* Mask to tell numeric and string values apart.  */
     79  1.6  mrg #define GOACC_PROPERTY_STRING_MASK 0x10000
     80  1.6  mrg 
     81  1.6  mrg    /* Start from 1 to catch uninitialized use.  */
     82  1.6  mrg    GOACC_PROPERTY_MEMORY =		1,
     83  1.6  mrg    GOACC_PROPERTY_FREE_MEMORY =		2,
     84  1.6  mrg    GOACC_PROPERTY_NAME =		GOACC_PROPERTY_STRING_MASK | 1,
     85  1.6  mrg    GOACC_PROPERTY_VENDOR =		GOACC_PROPERTY_STRING_MASK | 2,
     86  1.6  mrg    GOACC_PROPERTY_DRIVER =		GOACC_PROPERTY_STRING_MASK | 3
     87  1.6  mrg   };
     88  1.6  mrg 
     89  1.6  mrg /* Container type for passing device properties.  */
     90  1.6  mrg union goacc_property_value
     91  1.6  mrg {
     92  1.6  mrg   const char *ptr;
     93  1.6  mrg   size_t val;
     94  1.6  mrg };
     95  1.6  mrg 
     96  1.6  mrg 
     97  1.1  mrg /* Auxiliary struct, used for transferring pairs of addresses from plugin
     98  1.1  mrg    to libgomp.  */
     99  1.1  mrg struct addr_pair
    100  1.1  mrg {
    101  1.1  mrg   uintptr_t start;
    102  1.1  mrg   uintptr_t end;
    103  1.1  mrg };
    104  1.1  mrg 
    105  1.7  mrg /* This symbol is to name a target side variable that holds the designated
    106  1.7  mrg    'device number' of the target device. The symbol needs to be available to
    107  1.7  mrg    libgomp code and the offload plugin (which in the latter case must be
    108  1.7  mrg    stringified).  */
    109  1.7  mrg #define GOMP_DEVICE_NUM_VAR __gomp_device_num
    110  1.7  mrg 
    111  1.1  mrg /* Miscellaneous functions.  */
    112  1.1  mrg extern void *GOMP_PLUGIN_malloc (size_t) __attribute__ ((malloc));
    113  1.1  mrg extern void *GOMP_PLUGIN_malloc_cleared (size_t) __attribute__ ((malloc));
    114  1.1  mrg extern void *GOMP_PLUGIN_realloc (void *, size_t);
    115  1.3  mrg void GOMP_PLUGIN_target_task_completion (void *);
    116  1.1  mrg 
    117  1.1  mrg extern void GOMP_PLUGIN_debug (int, const char *, ...)
    118  1.1  mrg 	__attribute__ ((format (printf, 2, 3)));
    119  1.1  mrg extern void GOMP_PLUGIN_error (const char *, ...)
    120  1.1  mrg 	__attribute__ ((format (printf, 1, 2)));
    121  1.1  mrg extern void GOMP_PLUGIN_fatal (const char *, ...)
    122  1.1  mrg 	__attribute__ ((noreturn, format (printf, 1, 2)));
    123  1.1  mrg 
    124  1.3  mrg /* Prototypes for functions implemented by libgomp plugins.  */
    125  1.3  mrg extern const char *GOMP_OFFLOAD_get_name (void);
    126  1.3  mrg extern unsigned int GOMP_OFFLOAD_get_caps (void);
    127  1.3  mrg extern int GOMP_OFFLOAD_get_type (void);
    128  1.3  mrg extern int GOMP_OFFLOAD_get_num_devices (void);
    129  1.3  mrg extern bool GOMP_OFFLOAD_init_device (int);
    130  1.3  mrg extern bool GOMP_OFFLOAD_fini_device (int);
    131  1.3  mrg extern unsigned GOMP_OFFLOAD_version (void);
    132  1.3  mrg extern int GOMP_OFFLOAD_load_image (int, unsigned, const void *,
    133  1.3  mrg 				    struct addr_pair **);
    134  1.3  mrg extern bool GOMP_OFFLOAD_unload_image (int, unsigned, const void *);
    135  1.3  mrg extern void *GOMP_OFFLOAD_alloc (int, size_t);
    136  1.3  mrg extern bool GOMP_OFFLOAD_free (int, void *);
    137  1.3  mrg extern bool GOMP_OFFLOAD_dev2host (int, void *, const void *, size_t);
    138  1.3  mrg extern bool GOMP_OFFLOAD_host2dev (int, void *, const void *, size_t);
    139  1.3  mrg extern bool GOMP_OFFLOAD_dev2dev (int, void *, const void *, size_t);
    140  1.3  mrg extern bool GOMP_OFFLOAD_can_run (void *);
    141  1.3  mrg extern void GOMP_OFFLOAD_run (int, void *, void *, void **);
    142  1.3  mrg extern void GOMP_OFFLOAD_async_run (int, void *, void *, void **, void *);
    143  1.6  mrg 
    144  1.3  mrg extern void GOMP_OFFLOAD_openacc_exec (void (*) (void *), size_t, void **,
    145  1.6  mrg 				       void **, unsigned *, void *);
    146  1.3  mrg extern void *GOMP_OFFLOAD_openacc_create_thread_data (int);
    147  1.3  mrg extern void GOMP_OFFLOAD_openacc_destroy_thread_data (void *);
    148  1.6  mrg extern struct goacc_asyncqueue *GOMP_OFFLOAD_openacc_async_construct (int);
    149  1.6  mrg extern bool GOMP_OFFLOAD_openacc_async_destruct (struct goacc_asyncqueue *);
    150  1.6  mrg extern int GOMP_OFFLOAD_openacc_async_test (struct goacc_asyncqueue *);
    151  1.6  mrg extern bool GOMP_OFFLOAD_openacc_async_synchronize (struct goacc_asyncqueue *);
    152  1.6  mrg extern bool GOMP_OFFLOAD_openacc_async_serialize (struct goacc_asyncqueue *,
    153  1.6  mrg 						  struct goacc_asyncqueue *);
    154  1.6  mrg extern void GOMP_OFFLOAD_openacc_async_queue_callback (struct goacc_asyncqueue *,
    155  1.6  mrg 						       void (*)(void *), void *);
    156  1.6  mrg extern void GOMP_OFFLOAD_openacc_async_exec (void (*) (void *), size_t, void **,
    157  1.6  mrg 					     void **, unsigned *, void *,
    158  1.6  mrg 					     struct goacc_asyncqueue *);
    159  1.6  mrg extern bool GOMP_OFFLOAD_openacc_async_dev2host (int, void *, const void *, size_t,
    160  1.6  mrg 						 struct goacc_asyncqueue *);
    161  1.6  mrg extern bool GOMP_OFFLOAD_openacc_async_host2dev (int, void *, const void *, size_t,
    162  1.6  mrg 						 struct goacc_asyncqueue *);
    163  1.3  mrg extern void *GOMP_OFFLOAD_openacc_cuda_get_current_device (void);
    164  1.3  mrg extern void *GOMP_OFFLOAD_openacc_cuda_get_current_context (void);
    165  1.6  mrg extern void *GOMP_OFFLOAD_openacc_cuda_get_stream (struct goacc_asyncqueue *);
    166  1.6  mrg extern int GOMP_OFFLOAD_openacc_cuda_set_stream (struct goacc_asyncqueue *,
    167  1.6  mrg 						 void *);
    168  1.6  mrg extern union goacc_property_value
    169  1.6  mrg   GOMP_OFFLOAD_openacc_get_property (int, enum goacc_property);
    170  1.3  mrg 
    171  1.1  mrg #ifdef __cplusplus
    172  1.1  mrg }
    173  1.1  mrg #endif
    174  1.1  mrg 
    175  1.1  mrg #endif
    176