Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / include / interop.h
blobed3aa0d83a8637b3e25abfa6f191ff50c8653964
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _INTEROP_H_
10 #define _INTEROP_H_
12 #include "omptarget.h"
13 #include <assert.h>
15 #if defined(_WIN32)
16 #define __KAI_KMPC_CONVENTION __cdecl
17 #ifndef __KMP_IMP
18 #define __KMP_IMP __declspec(dllimport)
19 #endif
20 #else
21 #define __KAI_KMPC_CONVENTION
22 #ifndef __KMP_IMP
23 #define __KMP_IMP
24 #endif
25 #endif
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
31 /// TODO: Include the `omp.h` of the current build
32 /* OpenMP 5.1 interop */
33 typedef intptr_t omp_intptr_t;
35 /* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined
36 * properties */
37 typedef enum omp_interop_property {
38 omp_ipr_fr_id = -1,
39 omp_ipr_fr_name = -2,
40 omp_ipr_vendor = -3,
41 omp_ipr_vendor_name = -4,
42 omp_ipr_device_num = -5,
43 omp_ipr_platform = -6,
44 omp_ipr_device = -7,
45 omp_ipr_device_context = -8,
46 omp_ipr_targetsync = -9,
47 omp_ipr_first = -9
48 } omp_interop_property_t;
50 #define omp_interop_none 0
52 typedef enum omp_interop_rc {
53 omp_irc_no_value = 1,
54 omp_irc_success = 0,
55 omp_irc_empty = -1,
56 omp_irc_out_of_range = -2,
57 omp_irc_type_int = -3,
58 omp_irc_type_ptr = -4,
59 omp_irc_type_str = -5,
60 omp_irc_other = -6
61 } omp_interop_rc_t;
63 typedef enum omp_interop_fr {
64 omp_ifr_cuda = 1,
65 omp_ifr_cuda_driver = 2,
66 omp_ifr_opencl = 3,
67 omp_ifr_sycl = 4,
68 omp_ifr_hip = 5,
69 omp_ifr_level_zero = 6,
70 omp_ifr_last = 7
71 } omp_interop_fr_t;
73 typedef void *omp_interop_t;
75 /*!
76 * The `omp_get_num_interop_properties` routine retrieves the number of
77 * implementation-defined properties available for an `omp_interop_t` object.
79 int __KAI_KMPC_CONVENTION omp_get_num_interop_properties(const omp_interop_t);
80 /*!
81 * The `omp_get_interop_int` routine retrieves an integer property from an
82 * `omp_interop_t` object.
84 omp_intptr_t __KAI_KMPC_CONVENTION omp_get_interop_int(const omp_interop_t,
85 omp_interop_property_t,
86 int *);
87 /*!
88 * The `omp_get_interop_ptr` routine retrieves a pointer property from an
89 * `omp_interop_t` object.
91 void *__KAI_KMPC_CONVENTION omp_get_interop_ptr(const omp_interop_t,
92 omp_interop_property_t, int *);
93 /*!
94 * The `omp_get_interop_str` routine retrieves a string property from an
95 * `omp_interop_t` object.
97 const char *__KAI_KMPC_CONVENTION omp_get_interop_str(const omp_interop_t,
98 omp_interop_property_t,
99 int *);
101 * The `omp_get_interop_name` routine retrieves a property name from an
102 * `omp_interop_t` object.
104 const char *__KAI_KMPC_CONVENTION omp_get_interop_name(const omp_interop_t,
105 omp_interop_property_t);
107 * The `omp_get_interop_type_desc` routine retrieves a description of the type
108 * of a property associated with an `omp_interop_t` object.
110 const char *__KAI_KMPC_CONVENTION
111 omp_get_interop_type_desc(const omp_interop_t, omp_interop_property_t);
113 * The `omp_get_interop_rc_desc` routine retrieves a description of the return
114 * code associated with an `omp_interop_t` object.
116 extern const char *__KAI_KMPC_CONVENTION
117 omp_get_interop_rc_desc(const omp_interop_t, omp_interop_rc_t);
119 typedef enum omp_interop_backend_type_t {
120 // reserve 0
121 omp_interop_backend_type_cuda_1 = 1,
122 } omp_interop_backend_type_t;
124 typedef enum kmp_interop_type_t {
125 kmp_interop_type_unknown = -1,
126 kmp_interop_type_platform,
127 kmp_interop_type_device,
128 kmp_interop_type_tasksync,
129 } kmp_interop_type_t;
131 typedef enum omp_foreign_runtime_ids {
132 cuda = 1,
133 cuda_driver = 2,
134 opencl = 3,
135 sycl = 4,
136 hip = 5,
137 level_zero = 6,
138 } omp_foreign_runtime_ids_t;
140 /// The interop value type, aka. the interop object.
141 typedef struct omp_interop_val_t {
142 /// Device and interop-type are determined at construction time and fix.
143 omp_interop_val_t(intptr_t device_id, kmp_interop_type_t interop_type)
144 : interop_type(interop_type), device_id(device_id) {}
145 const char *err_str = nullptr;
146 __tgt_async_info *async_info = nullptr;
147 __tgt_device_info device_info;
148 const kmp_interop_type_t interop_type;
149 const intptr_t device_id;
150 const omp_foreign_runtime_ids_t vendor_id = cuda;
151 const intptr_t backend_type_id = omp_interop_backend_type_cuda_1;
152 } omp_interop_val_t;
154 #ifdef __cplusplus
156 #endif
157 #endif