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