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 KOKKOSP_INTERFACE_HPP
46 #define KOKKOSP_INTERFACE_HPP
47
48 #include <cinttypes>
49 #include <cstddef>
50
51 #include <cstdlib>
52
53 // NOTE: in this Kokkos::Profiling block, do not define anything that shouldn't
54 // exist should Profiling be disabled
55
56 namespace Kokkos {
57 namespace Tools {
58 namespace Experimental {
59 enum struct DeviceType {
60 Serial,
61 OpenMP,
62 Cuda,
63 HIP,
64 OpenMPTarget,
65 HPX,
66 Threads,
67 SYCL,
68 Unknown
69 };
70
71 template <typename ExecutionSpace>
72 struct DeviceTypeTraits;
73
74 constexpr const size_t device_type_bits = 8;
75 constexpr const size_t instance_bits = 24;
76 template <typename ExecutionSpace>
device_id(ExecutionSpace const & space)77 inline uint32_t device_id(ExecutionSpace const& space) noexcept {
78 auto device_id = static_cast<uint32_t>(DeviceTypeTraits<ExecutionSpace>::id);
79 return (device_id << instance_bits) + space.impl_instance_id();
80 }
81 } // namespace Experimental
82 } // namespace Tools
83 } // end namespace Kokkos
84
85 #if defined(KOKKOS_ENABLE_LIBDL)
86 // We check at configure time that libdl is available.
87 #include <dlfcn.h>
88 #endif
89
90 #include <impl/Kokkos_Profiling_DeviceInfo.hpp>
91 #include <impl/Kokkos_Profiling_C_Interface.h>
92
93 namespace Kokkos {
94 namespace Tools {
95
96 using SpaceHandle = Kokkos_Profiling_SpaceHandle;
97
98 } // namespace Tools
99
100 namespace Tools {
101
102 namespace Experimental {
103 using EventSet = Kokkos_Profiling_EventSet;
104 static_assert(sizeof(EventSet) / sizeof(Kokkos_Tools_functionPointer) == 275,
105 "sizeof EventSet has changed, this is an error on the part of a "
106 "Kokkos developer");
107 static_assert(sizeof(Kokkos_Tools_ToolSettings) / sizeof(bool) == 256,
108 "sizeof EventSet has changed, this is an error on the part of a "
109 "Kokkos developer");
110 static_assert(sizeof(Kokkos_Tools_ToolProgrammingInterface) /
111 sizeof(Kokkos_Tools_functionPointer) ==
112 32,
113 "sizeof EventSet has changed, this is an error on the part of a "
114 "Kokkos developer");
115
116 using toolInvokedFenceFunction = Kokkos_Tools_toolInvokedFenceFunction;
117 using provideToolProgrammingInterfaceFunction =
118 Kokkos_Tools_provideToolProgrammingInterfaceFunction;
119 using requestToolSettingsFunction = Kokkos_Tools_requestToolSettingsFunction;
120 using ToolSettings = Kokkos_Tools_ToolSettings;
121 using ToolProgrammingInterface = Kokkos_Tools_ToolProgrammingInterface;
122 } // namespace Experimental
123 using initFunction = Kokkos_Profiling_initFunction;
124 using finalizeFunction = Kokkos_Profiling_finalizeFunction;
125 using parseArgsFunction = Kokkos_Profiling_parseArgsFunction;
126 using printHelpFunction = Kokkos_Profiling_printHelpFunction;
127 using beginFunction = Kokkos_Profiling_beginFunction;
128 using endFunction = Kokkos_Profiling_endFunction;
129 using pushFunction = Kokkos_Profiling_pushFunction;
130 using popFunction = Kokkos_Profiling_popFunction;
131 using allocateDataFunction = Kokkos_Profiling_allocateDataFunction;
132 using deallocateDataFunction = Kokkos_Profiling_deallocateDataFunction;
133 using createProfileSectionFunction =
134 Kokkos_Profiling_createProfileSectionFunction;
135 using startProfileSectionFunction =
136 Kokkos_Profiling_startProfileSectionFunction;
137 using stopProfileSectionFunction = Kokkos_Profiling_stopProfileSectionFunction;
138 using destroyProfileSectionFunction =
139 Kokkos_Profiling_destroyProfileSectionFunction;
140 using profileEventFunction = Kokkos_Profiling_profileEventFunction;
141 using beginDeepCopyFunction = Kokkos_Profiling_beginDeepCopyFunction;
142 using endDeepCopyFunction = Kokkos_Profiling_endDeepCopyFunction;
143 using beginFenceFunction = Kokkos_Profiling_beginFenceFunction;
144 using endFenceFunction = Kokkos_Profiling_endFenceFunction;
145 using dualViewSyncFunction = Kokkos_Profiling_dualViewSyncFunction;
146 using dualViewModifyFunction = Kokkos_Profiling_dualViewModifyFunction;
147 using declareMetadataFunction = Kokkos_Profiling_declareMetadataFunction;
148
149 } // namespace Tools
150
151 } // namespace Kokkos
152
153 // Profiling
154
155 namespace Kokkos {
156
157 namespace Profiling {
158
159 /** The Profiling namespace is being renamed to Tools.
160 * This is reexposing the contents of what used to be the Profiling
161 * Interface with their original names, to avoid breaking old code
162 */
163
164 namespace Experimental {
165
166 using Kokkos::Tools::Experimental::device_id;
167 using Kokkos::Tools::Experimental::DeviceType;
168 using Kokkos::Tools::Experimental::DeviceTypeTraits;
169
170 } // namespace Experimental
171
172 using Kokkos::Tools::allocateDataFunction;
173 using Kokkos::Tools::beginDeepCopyFunction;
174 using Kokkos::Tools::beginFunction;
175 using Kokkos::Tools::createProfileSectionFunction;
176 using Kokkos::Tools::deallocateDataFunction;
177 using Kokkos::Tools::destroyProfileSectionFunction;
178 using Kokkos::Tools::endDeepCopyFunction;
179 using Kokkos::Tools::endFunction;
180 using Kokkos::Tools::finalizeFunction;
181 using Kokkos::Tools::initFunction;
182 using Kokkos::Tools::parseArgsFunction;
183 using Kokkos::Tools::popFunction;
184 using Kokkos::Tools::printHelpFunction;
185 using Kokkos::Tools::profileEventFunction;
186 using Kokkos::Tools::pushFunction;
187 using Kokkos::Tools::SpaceHandle;
188 using Kokkos::Tools::startProfileSectionFunction;
189 using Kokkos::Tools::stopProfileSectionFunction;
190
191 } // namespace Profiling
192 } // namespace Kokkos
193
194 // Tuning
195
196 namespace Kokkos {
197 namespace Tools {
198 namespace Experimental {
199 using ValueSet = Kokkos_Tools_ValueSet;
200 using ValueRange = Kokkos_Tools_ValueRange;
201 using StatisticalCategory = Kokkos_Tools_VariableInfo_StatisticalCategory;
202 using ValueType = Kokkos_Tools_VariableInfo_ValueType;
203 using CandidateValueType = Kokkos_Tools_VariableInfo_CandidateValueType;
204 using SetOrRange = Kokkos_Tools_VariableInfo_SetOrRange;
205 using VariableInfo = Kokkos_Tools_VariableInfo;
206 using OptimizationGoal = Kokkos_Tools_OptimzationGoal;
207 using TuningString = Kokkos_Tools_Tuning_String;
208 using VariableValue = Kokkos_Tools_VariableValue;
209
210 using outputTypeDeclarationFunction =
211 Kokkos_Tools_outputTypeDeclarationFunction;
212 using inputTypeDeclarationFunction = Kokkos_Tools_inputTypeDeclarationFunction;
213 using requestValueFunction = Kokkos_Tools_requestValueFunction;
214 using contextBeginFunction = Kokkos_Tools_contextBeginFunction;
215 using contextEndFunction = Kokkos_Tools_contextEndFunction;
216 using optimizationGoalDeclarationFunction =
217 Kokkos_Tools_optimizationGoalDeclarationFunction;
218 } // end namespace Experimental
219 } // end namespace Tools
220
221 } // end namespace Kokkos
222
223 #endif
224