1 /*
2  * Copyright (c) 2017-2019, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 /** \file
19  * \brief Various definitions for the libomptarget runtime
20  */
21 
22 #ifndef TGT_RUNTIME_H__
23 #define TGT_RUNTIME_H__
24 
25 #include "ompaccel.h"
26 #include "gbldefs.h"
27 
28 #define OMPACCEL_DEFAULT_DEVICEID -1
29 
30 /* TGT API macros and structs */
31 enum {
32   TGT_API_BAD,
33   TGT_API_REGISTER_LIB,
34   TGT_API_UNREGISTER_LIB,
35   TGT_API_TARGET,
36   TGT_API_TARGET_NOWAIT,
37   TGT_API_TARGET_TEAMS,
38   TGT_API_TARGET_TEAMS_NOWAIT,
39   TGT_API_TARGET_TEAMS_PARALLEL,
40   TGT_API_TARGET_TEAMS_PARALLEL_NOWAIT,
41   TGT_API_TARGET_DATA_BEGIN,
42   TGT_API_TARGET_DATA_BEGIN_DEPEND,
43   TGT_API_TARGET_DATA_BEGIN_NOWAIT,
44   TGT_API_TARGET_DATA_BEGIN_NOWAIT_DEPEND,
45   TGT_API_TARGET_DATA_END,
46   TGT_API_TARGET_DATA_END_DEPEND,
47   TGT_API_TARGET_DATA_END_NOWAIT,
48   TGT_API_TARGET_DATA_END_NOWAIT_DEPEND,
49   TGT_API_TARGETUPDATE,
50   TGT_API_N_ENTRIES /* <-- Always last */
51 };
52 
53 typedef struct any_tgt_struct {
54   char *name;
55   DTYPE dtype;
56   int byval;
57   int psptr;
58 } TGT_ST_TYPE;
59 
60 struct tgt_api_entry_t {
61   const char *name;     /* TGT API function name                    */
62   const int ret_iliopc; /* TGT API function return value ili opcode */
63   const DTYPE ret_dtype;  /* TGT API function return value type       */
64 };
65 
66 /**
67    \brief Register the file and load cubin file
68  */
69 int ll_make_tgt_register_lib(void);
70 
71 /**
72    \brief Register the file and load cubin file
73  */
74 int ll_make_tgt_register_lib2(void);
75 /**
76    \brief Unregister the file
77  */
78 int ll_make_tgt_unregister_lib(void);
79 
80 /**
81    \brief Start offload for target region
82  */
83 int ll_make_tgt_target(SPTR, int64_t, SPTR);
84 
85 /**
86    \brief Start offload for target teams region
87  */
88 int ll_make_tgt_target_teams(SPTR, int64_t, SPTR, int32_t, int32_t);
89 
90 /**
91    \brief Start offload for target teams region
92  */
93 int ll_make_tgt_target_teams_parallel(SPTR, int64_t, SPTR, int32_t, int32_t, int32_t, int32_t);
94 
95 /**
96    \brief Start target data begin.
97  */
98 int ll_make_tgt_target_data_begin(int, OMPACCEL_TINFO *);
99 
100 /**
101    \brief Finish target data begin.
102  */
103 int ll_make_tgt_target_data_end(int, OMPACCEL_TINFO *);
104 
105 /**
106    \brief Finish target update begin.
107  */
108 int ll_make_tgt_targetupdate_end(int, OMPACCEL_TINFO *);
109 /**
110    \brief create tgt_offload_entry dtype
111  */
112 DTYPE ll_make_tgt_offload_entry(char *);
113 
114 void init_tgtutil();
115 
116 #endif /* __TGT_RUNTIME_H__ */
117