HIP: Heterogenous-computing Interface for Portability
hip_ext.h
1 /*
2 Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 
23 #ifndef HIP_INCLUDE_HIP_HIP_EXT_H
24 #define HIP_INCLUDE_HIP_HIP_EXT_H
25 #include "hip/hip_runtime.h"
26 #if defined(__cplusplus)
27 #include <tuple>
28 #include <type_traits>
29 #endif
30 #ifdef __HCC__
31 
32 // Forward declarations:
33 namespace hc {
34 class accelerator;
35 class accelerator_view;
36 }; // namespace hc
37 
38 
53 HIP_PUBLIC_API
54 hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator* acc);
55 
62 HIP_PUBLIC_API
63 hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view** av);
64 
65 #endif // #ifdef __HCC__
66 
96 HIP_PUBLIC_API
97 hipError_t hipExtModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
98  uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ,
99  uint32_t localWorkSizeX, uint32_t localWorkSizeY,
100  uint32_t localWorkSizeZ, size_t sharedMemBytes,
101  hipStream_t hStream, void** kernelParams, void** extra,
102  hipEvent_t startEvent = nullptr,
103  hipEvent_t stopEvent = nullptr,
104  uint32_t flags = 0);
105 
106 HIP_PUBLIC_API
107 hipError_t hipHccModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
108  uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ,
109  uint32_t localWorkSizeX, uint32_t localWorkSizeY,
110  uint32_t localWorkSizeZ, size_t sharedMemBytes,
111  hipStream_t hStream, void** kernelParams, void** extra,
112  hipEvent_t startEvent = nullptr,
113  hipEvent_t stopEvent = nullptr)
114  __attribute__((deprecated("use hipExtModuleLaunchKernel instead")));
115 
116 #if defined(__HIP_ROCclr__) && defined(__cplusplus)
117 
118 extern "C" hipError_t hipExtLaunchKernel(const void* function_address, dim3 numBlocks,
119  dim3 dimBlocks, void** args, size_t sharedMemBytes,
120  hipStream_t stream, hipEvent_t startEvent,
121  hipEvent_t stopEvent, int flags);
122 
123 template <typename... Args, typename F = void (*)(Args...)>
124 inline void hipExtLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
125  std::uint32_t sharedMemBytes, hipStream_t stream,
126  hipEvent_t startEvent, hipEvent_t stopEvent, std::uint32_t flags,
127  Args... args) {
128  constexpr size_t count = sizeof...(Args);
129  auto tup_ = std::tuple<Args...>{args...};
130  auto tup = validateArgsCountType(kernel, tup_);
131  void* _Args[count];
132  pArgs<0>(tup, _Args);
133 
134  auto k = reinterpret_cast<void*>(kernel);
135  hipExtLaunchKernel(k, numBlocks, dimBlocks, _Args, sharedMemBytes, stream, startEvent,
136  stopEvent, (int)flags);
137 }
138 #elif defined(__HIP_PLATFORM_HCC__) && GENERIC_GRID_LAUNCH == 1 && defined(__HCC__)
139 //kernel_descriptor and hip_impl::make_kernarg are in "grid_launch_GGL.hpp"
140 
141 namespace hip_impl {
142 inline
143 __attribute__((visibility("hidden")))
144 void hipExtLaunchKernelGGLImpl(
145  std::uintptr_t function_address,
146  const dim3& numBlocks,
147  const dim3& dimBlocks,
148  std::uint32_t sharedMemBytes,
149  hipStream_t stream,
150  hipEvent_t startEvent,
151  hipEvent_t stopEvent,
152  std::uint32_t flags,
153  void** kernarg) {
154 
155  const auto& kd = hip_impl::get_program_state()
156  .kernel_descriptor(function_address, target_agent(stream));
157 
158  hipExtModuleLaunchKernel(kd, numBlocks.x * dimBlocks.x,
159  numBlocks.y * dimBlocks.y,
160  numBlocks.z * dimBlocks.z,
161  dimBlocks.x, dimBlocks.y, dimBlocks.z,
162  sharedMemBytes, stream, nullptr, kernarg,
163  startEvent, stopEvent, flags);
164 }
165 } // namespace hip_impl
166 
167 template <typename... Args, typename F = void (*)(Args...)>
168 inline
169 void hipExtLaunchKernelGGL(F kernel, const dim3& numBlocks,
170  const dim3& dimBlocks, std::uint32_t sharedMemBytes,
171  hipStream_t stream, hipEvent_t startEvent,
172  hipEvent_t stopEvent, std::uint32_t flags,
173  Args... args) {
174  hip_impl::hip_init();
175  auto kernarg =
176  hip_impl::make_kernarg(kernel, std::tuple<Args...>{std::move(args)...});
177  std::size_t kernarg_size = kernarg.size();
178 
179  void* config[]{
180  HIP_LAUNCH_PARAM_BUFFER_POINTER,
181  kernarg.data(),
182  HIP_LAUNCH_PARAM_BUFFER_SIZE,
183  &kernarg_size,
184  HIP_LAUNCH_PARAM_END};
185 
186  hip_impl::hipExtLaunchKernelGGLImpl(reinterpret_cast<std::uintptr_t>(kernel),
187  numBlocks, dimBlocks, sharedMemBytes,
188  stream, startEvent, stopEvent, flags,
189  &config[0]);
190 }
191 #endif // !__HIP_ROCclr__ && defined(__cplusplus)
192 
193 // doxygen end AMD-specific features
197 #endif // #iidef HIP_INCLUDE_HIP_HIP_EXT_H
hipHccGetAccelerator
HIP_PUBLIC_API hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc)
Return hc::accelerator associated with the specified deviceId.
Definition: hip_hcc.cpp:2512
hipHccGetAcceleratorView
HIP_PUBLIC_API hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view **av)
Return hc::accelerator_view associated with the specified stream.
Definition: hip_hcc.cpp:2528
ihipEvent_t
Definition: hip_hcc_internal.h:759
ihipStream_t
Definition: hip_hcc_internal.h:580
dim3
Definition: hip_runtime_api.h:313
ihipModuleSymbol_t
Definition: hip_module.cpp:108
hipExtModuleLaunchKernel
HIP_PUBLIC_API hipError_t hipExtModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX, uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ, uint32_t localWorkSizeX, uint32_t localWorkSizeY, uint32_t localWorkSizeZ, size_t sharedMemBytes, hipStream_t hStream, void **kernelParams, void **extra, hipEvent_t startEvent=nullptr, hipEvent_t stopEvent=nullptr, uint32_t flags=0)
launches kernel f with launch parameters and shared memory on stream with arguments passed to kernelp...
Definition: hip_module.cpp:296