1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 //                        Kokkos v. 3.0
6 //       Copyright (2020) National Technology & Engineering
7 //               Solutions of Sandia, LLC (NTESS).
8 //
9 // Under the terms of Contract DE-NA0003525 with NTESS,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
40 //
41 // ************************************************************************
42 //@HEADER
43 */
44 
45 #ifndef KOKKOS_PROFILING_C_INTERFACE_HPP
46 #define KOKKOS_PROFILING_C_INTERFACE_HPP
47 
48 #ifdef __cplusplus
49 #include <cstddef>
50 #include <cstdint>
51 #else
52 #include <stddef.h>
53 #include <stdint.h>
54 #include <stdbool.h>
55 #endif
56 
57 #define KOKKOSP_INTERFACE_VERSION 20210225
58 
59 // Profiling
60 
61 struct Kokkos_Profiling_KokkosPDeviceInfo {
62   size_t deviceID;
63 };
64 
65 struct Kokkos_Profiling_SpaceHandle {
66   char name[64];
67 };
68 
69 // NOLINTNEXTLINE(modernize-use-using): C compatibility
70 typedef void (*Kokkos_Profiling_initFunction)(
71     const int, const uint64_t, const uint32_t,
72     struct Kokkos_Profiling_KokkosPDeviceInfo*);
73 // NOLINTNEXTLINE(modernize-use-using): C compatibility
74 typedef void (*Kokkos_Profiling_finalizeFunction)();
75 // NOLINTNEXTLINE(modernize-use-using): C compatibility
76 typedef void (*Kokkos_Profiling_parseArgsFunction)(int, char**);
77 // NOLINTNEXTLINE(modernize-use-using): C compatibility
78 typedef void (*Kokkos_Profiling_printHelpFunction)(char*);
79 // NOLINTNEXTLINE(modernize-use-using): C compatibility
80 typedef void (*Kokkos_Profiling_beginFunction)(const char*, const uint32_t,
81                                                uint64_t*);
82 // NOLINTNEXTLINE(modernize-use-using): C compatibility
83 typedef void (*Kokkos_Profiling_endFunction)(uint64_t);
84 
85 // NOLINTNEXTLINE(modernize-use-using): C compatibility
86 typedef void (*Kokkos_Profiling_pushFunction)(const char*);
87 // NOLINTNEXTLINE(modernize-use-using): C compatibility
88 typedef void (*Kokkos_Profiling_popFunction)();
89 
90 // NOLINTNEXTLINE(modernize-use-using): C compatibility
91 typedef void (*Kokkos_Profiling_allocateDataFunction)(
92     const struct Kokkos_Profiling_SpaceHandle, const char*, const void*,
93     const uint64_t);
94 // NOLINTNEXTLINE(modernize-use-using): C compatibility
95 typedef void (*Kokkos_Profiling_deallocateDataFunction)(
96     const struct Kokkos_Profiling_SpaceHandle, const char*, const void*,
97     const uint64_t);
98 
99 // NOLINTNEXTLINE(modernize-use-using): C compatibility
100 typedef void (*Kokkos_Profiling_createProfileSectionFunction)(const char*,
101                                                               uint32_t*);
102 // NOLINTNEXTLINE(modernize-use-using): C compatibility
103 typedef void (*Kokkos_Profiling_startProfileSectionFunction)(const uint32_t);
104 // NOLINTNEXTLINE(modernize-use-using): C compatibility
105 typedef void (*Kokkos_Profiling_stopProfileSectionFunction)(const uint32_t);
106 // NOLINTNEXTLINE(modernize-use-using): C compatibility
107 typedef void (*Kokkos_Profiling_destroyProfileSectionFunction)(const uint32_t);
108 
109 // NOLINTNEXTLINE(modernize-use-using): C compatibility
110 typedef void (*Kokkos_Profiling_profileEventFunction)(const char*);
111 
112 // NOLINTNEXTLINE(modernize-use-using): C compatibility
113 typedef void (*Kokkos_Profiling_beginDeepCopyFunction)(
114     struct Kokkos_Profiling_SpaceHandle, const char*, const void*,
115     struct Kokkos_Profiling_SpaceHandle, const char*, const void*, uint64_t);
116 // NOLINTNEXTLINE(modernize-use-using): C compatibility
117 typedef void (*Kokkos_Profiling_endDeepCopyFunction)();
118 typedef void (*Kokkos_Profiling_beginFenceFunction)(const char*, const uint32_t,
119                                                     uint64_t*);
120 typedef void (*Kokkos_Profiling_endFenceFunction)(uint64_t);
121 
122 // NOLINTNEXTLINE(modernize-use-using): C compatibility
123 typedef void (*Kokkos_Profiling_dualViewSyncFunction)(const char*,
124                                                       const void* const, bool);
125 // NOLINTNEXTLINE(modernize-use-using): C compatibility
126 typedef void (*Kokkos_Profiling_dualViewModifyFunction)(const char*,
127                                                         const void* const,
128                                                         bool);
129 
130 // NOLINTNEXTLINE(modernize-use-using): C compatibility
131 typedef void (*Kokkos_Profiling_declareMetadataFunction)(const char*,
132                                                          const char*);
133 
134 // NOLINTNEXTLINE(modernize-use-using): C compatibility
135 typedef void (*Kokkos_Tools_toolInvokedFenceFunction)(const uint32_t);
136 
137 // NOLINTNEXTLINE(modernize-use-using): C compatibility
138 typedef void (*Kokkos_Tools_functionPointer)();
139 struct Kokkos_Tools_ToolProgrammingInterface {
140   Kokkos_Tools_toolInvokedFenceFunction fence;
141   // allow addition of more actions
142   Kokkos_Tools_functionPointer padding[31];
143 };
144 
145 struct Kokkos_Tools_ToolSettings {
146   bool requires_global_fencing;
147   bool padding[255];
148 };
149 
150 // NOLINTNEXTLINE(modernize-use-using): C compatibility
151 typedef void (*Kokkos_Tools_provideToolProgrammingInterfaceFunction)(
152     const uint32_t, struct Kokkos_Tools_ToolProgrammingInterface);
153 // NOLINTNEXTLINE(modernize-use-using): C compatibility
154 typedef void (*Kokkos_Tools_requestToolSettingsFunction)(
155     const uint32_t, struct Kokkos_Tools_ToolSettings*);
156 
157 // Tuning
158 
159 #define KOKKOS_TOOLS_TUNING_STRING_LENGTH 64
160 typedef char Kokkos_Tools_Tuning_String[KOKKOS_TOOLS_TUNING_STRING_LENGTH];
161 union Kokkos_Tools_VariableValue_ValueUnion {
162   int64_t int_value;
163   double double_value;
164   Kokkos_Tools_Tuning_String string_value;
165 };
166 
167 union Kokkos_Tools_VariableValue_ValueUnionSet {
168   int64_t* int_value;
169   double* double_value;
170   Kokkos_Tools_Tuning_String* string_value;
171 };
172 
173 struct Kokkos_Tools_ValueSet {
174   size_t size;
175   union Kokkos_Tools_VariableValue_ValueUnionSet values;
176 };
177 
178 enum Kokkos_Tools_OptimizationType {
179   Kokkos_Tools_Minimize,
180   Kokkos_Tools_Maximize
181 };
182 
183 struct Kokkos_Tools_OptimzationGoal {
184   size_t type_id;
185   enum Kokkos_Tools_OptimizationType goal;
186 };
187 
188 struct Kokkos_Tools_ValueRange {
189   union Kokkos_Tools_VariableValue_ValueUnion lower;
190   union Kokkos_Tools_VariableValue_ValueUnion upper;
191   union Kokkos_Tools_VariableValue_ValueUnion step;
192   bool openLower;
193   bool openUpper;
194 };
195 
196 enum Kokkos_Tools_VariableInfo_ValueType {
197   kokkos_value_double,
198   kokkos_value_int64,
199   kokkos_value_string,
200 };
201 
202 enum Kokkos_Tools_VariableInfo_StatisticalCategory {
203   kokkos_value_categorical,  // unordered distinct objects
204   kokkos_value_ordinal,      // ordered distinct objects
205   kokkos_value_interval,  // ordered distinct objects for which distance matters
206   kokkos_value_ratio  // ordered distinct objects for which distance matters,
207                       // division matters, and the concept of zero exists
208 };
209 
210 enum Kokkos_Tools_VariableInfo_CandidateValueType {
211   kokkos_value_set,       // I am one of [2,3,4,5]
212   kokkos_value_range,     // I am somewhere in [2,12)
213   kokkos_value_unbounded  // I am [text/int/float], but we don't know at
214                           // declaration time what values are appropriate. Only
215                           // valid for Context Variables
216 };
217 
218 union Kokkos_Tools_VariableInfo_SetOrRange {
219   struct Kokkos_Tools_ValueSet set;
220   struct Kokkos_Tools_ValueRange range;
221 };
222 
223 struct Kokkos_Tools_VariableInfo {
224   enum Kokkos_Tools_VariableInfo_ValueType type;
225   enum Kokkos_Tools_VariableInfo_StatisticalCategory category;
226   enum Kokkos_Tools_VariableInfo_CandidateValueType valueQuantity;
227   union Kokkos_Tools_VariableInfo_SetOrRange candidates;
228   void* toolProvidedInfo;
229 };
230 
231 struct Kokkos_Tools_VariableValue {
232   size_t type_id;
233   union Kokkos_Tools_VariableValue_ValueUnion value;
234   struct Kokkos_Tools_VariableInfo* metadata;
235 };
236 
237 typedef void (*Kokkos_Tools_outputTypeDeclarationFunction)(
238     const char*, const size_t, struct Kokkos_Tools_VariableInfo* info);
239 typedef void (*Kokkos_Tools_inputTypeDeclarationFunction)(
240     const char*, const size_t, struct Kokkos_Tools_VariableInfo* info);
241 
242 typedef void (*Kokkos_Tools_requestValueFunction)(
243     const size_t, const size_t, const struct Kokkos_Tools_VariableValue*,
244     const size_t count, struct Kokkos_Tools_VariableValue*);
245 typedef void (*Kokkos_Tools_contextBeginFunction)(const size_t);
246 typedef void (*Kokkos_Tools_contextEndFunction)(
247     const size_t, struct Kokkos_Tools_VariableValue);
248 typedef void (*Kokkos_Tools_optimizationGoalDeclarationFunction)(
249     const size_t, const struct Kokkos_Tools_OptimzationGoal goal);
250 
251 struct Kokkos_Profiling_EventSet {
252   Kokkos_Profiling_initFunction init;
253   Kokkos_Profiling_finalizeFunction finalize;
254   Kokkos_Profiling_parseArgsFunction parse_args;
255   Kokkos_Profiling_printHelpFunction print_help;
256   Kokkos_Profiling_beginFunction begin_parallel_for;
257   Kokkos_Profiling_endFunction end_parallel_for;
258   Kokkos_Profiling_beginFunction begin_parallel_reduce;
259   Kokkos_Profiling_endFunction end_parallel_reduce;
260   Kokkos_Profiling_beginFunction begin_parallel_scan;
261   Kokkos_Profiling_endFunction end_parallel_scan;
262   Kokkos_Profiling_pushFunction push_region;
263   Kokkos_Profiling_popFunction pop_region;
264   Kokkos_Profiling_allocateDataFunction allocate_data;
265   Kokkos_Profiling_deallocateDataFunction deallocate_data;
266   Kokkos_Profiling_createProfileSectionFunction create_profile_section;
267   Kokkos_Profiling_startProfileSectionFunction start_profile_section;
268   Kokkos_Profiling_stopProfileSectionFunction stop_profile_section;
269   Kokkos_Profiling_destroyProfileSectionFunction destroy_profile_section;
270   Kokkos_Profiling_profileEventFunction profile_event;
271   Kokkos_Profiling_beginDeepCopyFunction begin_deep_copy;
272   Kokkos_Profiling_endDeepCopyFunction end_deep_copy;
273   Kokkos_Profiling_beginFenceFunction begin_fence;
274   Kokkos_Profiling_endFenceFunction end_fence;
275   Kokkos_Profiling_dualViewSyncFunction sync_dual_view;
276   Kokkos_Profiling_dualViewModifyFunction modify_dual_view;
277   Kokkos_Profiling_declareMetadataFunction declare_metadata;
278   Kokkos_Tools_provideToolProgrammingInterfaceFunction
279       provide_tool_programming_interface;
280   Kokkos_Tools_requestToolSettingsFunction request_tool_settings;
281   char profiling_padding[9 * sizeof(Kokkos_Tools_functionPointer)];
282   Kokkos_Tools_outputTypeDeclarationFunction declare_output_type;
283   Kokkos_Tools_inputTypeDeclarationFunction declare_input_type;
284   Kokkos_Tools_requestValueFunction request_output_values;
285   Kokkos_Tools_contextBeginFunction begin_tuning_context;
286   Kokkos_Tools_contextEndFunction end_tuning_context;
287   Kokkos_Tools_optimizationGoalDeclarationFunction declare_optimization_goal;
288   char padding[232 *
289                sizeof(
290                    Kokkos_Tools_functionPointer)];  // allows us to add another
291                                                     // 256 events to the Tools
292                                                     // interface without
293                                                     // changing struct layout
294 };
295 
296 #endif  // KOKKOS_PROFILING_C_INTERFACE_HPP
297