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 
60 HIP_PUBLIC_API
61 hipError_t hipExtModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
62  uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ,
63  uint32_t localWorkSizeX, uint32_t localWorkSizeY,
64  uint32_t localWorkSizeZ, size_t sharedMemBytes,
65  hipStream_t hStream, void** kernelParams, void** extra,
66  hipEvent_t startEvent = nullptr,
67  hipEvent_t stopEvent = nullptr,
68  uint32_t flags = 0);
69 
70 HIP_PUBLIC_API
71 hipError_t hipHccModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
72  uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ,
73  uint32_t localWorkSizeX, uint32_t localWorkSizeY,
74  uint32_t localWorkSizeZ, size_t sharedMemBytes,
75  hipStream_t hStream, void** kernelParams, void** extra,
76  hipEvent_t startEvent = nullptr,
77  hipEvent_t stopEvent = nullptr)
78  __attribute__((deprecated("use hipExtModuleLaunchKernel instead")));
79 
80 #if defined(__HIP_ROCclr__) && defined(__cplusplus)
81 
82 extern "C" hipError_t hipExtLaunchKernel(const void* function_address, dim3 numBlocks,
83  dim3 dimBlocks, void** args, size_t sharedMemBytes,
84  hipStream_t stream, hipEvent_t startEvent,
85  hipEvent_t stopEvent, int flags);
86 
87 template <typename... Args, typename F = void (*)(Args...)>
88 inline void hipExtLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
89  std::uint32_t sharedMemBytes, hipStream_t stream,
90  hipEvent_t startEvent, hipEvent_t stopEvent, std::uint32_t flags,
91  Args... args) {
92  constexpr size_t count = sizeof...(Args);
93  auto tup_ = std::tuple<Args...>{args...};
94  auto tup = validateArgsCountType(kernel, tup_);
95  void* _Args[count];
96  pArgs<0>(tup, _Args);
97 
98  auto k = reinterpret_cast<void*>(kernel);
99  hipExtLaunchKernel(k, numBlocks, dimBlocks, _Args, sharedMemBytes, stream, startEvent,
100  stopEvent, (int)flags);
101 }
102 #elif defined(__HIP_PLATFORM_HCC__) && GENERIC_GRID_LAUNCH == 1 && defined(__HCC__)
103 //kernel_descriptor and hip_impl::make_kernarg are in "grid_launch_GGL.hpp"
104 
105 namespace hip_impl {
106 inline
107 __attribute__((visibility("hidden")))
108 void hipExtLaunchKernelGGLImpl(
109  std::uintptr_t function_address,
110  const dim3& numBlocks,
111  const dim3& dimBlocks,
112  std::uint32_t sharedMemBytes,
113  hipStream_t stream,
114  hipEvent_t startEvent,
115  hipEvent_t stopEvent,
116  std::uint32_t flags,
117  void** kernarg) {
118 
119  const auto& kd = hip_impl::get_program_state()
120  .kernel_descriptor(function_address, target_agent(stream));
121 
122  hipExtModuleLaunchKernel(kd, numBlocks.x * dimBlocks.x,
123  numBlocks.y * dimBlocks.y,
124  numBlocks.z * dimBlocks.z,
125  dimBlocks.x, dimBlocks.y, dimBlocks.z,
126  sharedMemBytes, stream, nullptr, kernarg,
127  startEvent, stopEvent, flags);
128 }
129 } // namespace hip_impl
130 
131 template <typename... Args, typename F = void (*)(Args...)>
132 inline
133 void hipExtLaunchKernelGGL(F kernel, const dim3& numBlocks,
134  const dim3& dimBlocks, std::uint32_t sharedMemBytes,
135  hipStream_t stream, hipEvent_t startEvent,
136  hipEvent_t stopEvent, std::uint32_t flags,
137  Args... args) {
138  hip_impl::hip_init();
139  auto kernarg =
140  hip_impl::make_kernarg(kernel, std::tuple<Args...>{std::move(args)...});
141  std::size_t kernarg_size = kernarg.size();
142 
143  void* config[]{
144  HIP_LAUNCH_PARAM_BUFFER_POINTER,
145  kernarg.data(),
146  HIP_LAUNCH_PARAM_BUFFER_SIZE,
147  &kernarg_size,
148  HIP_LAUNCH_PARAM_END};
149 
150  hip_impl::hipExtLaunchKernelGGLImpl(reinterpret_cast<std::uintptr_t>(kernel),
151  numBlocks, dimBlocks, sharedMemBytes,
152  stream, startEvent, stopEvent, flags,
153  &config[0]);
154 }
155 #endif // !__HIP_ROCclr__ && defined(__cplusplus)
156 
157 // doxygen end AMD-specific features
161 #endif // #iidef HIP_INCLUDE_HIP_HIP_EXT_H
ihipEvent_t
Definition: hip_hcc_internal.h:759
ihipStream_t
Definition: hip_hcc_internal.h:580
dim3
Definition: hip_runtime_api.h:330
ihipModuleSymbol_t
Definition: hip_module.cpp:108