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