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 #ifdef __HCC__
27 
28 // Forward declarations:
29 namespace hc {
30 class accelerator;
31 class accelerator_view;
32 }; // namespace hc
33 
34 
49 HIP_PUBLIC_API
50 hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator* acc);
51 
58 HIP_PUBLIC_API
59 hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view** av);
60 
61 #endif // #ifdef __HCC__
62 
92 HIP_PUBLIC_API
93 hipError_t hipExtModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
94  uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ,
95  uint32_t localWorkSizeX, uint32_t localWorkSizeY,
96  uint32_t localWorkSizeZ, size_t sharedMemBytes,
97  hipStream_t hStream, void** kernelParams, void** extra,
98  hipEvent_t startEvent = nullptr,
99  hipEvent_t stopEvent = nullptr,
100  uint32_t flags = 0);
101 
102 HIP_PUBLIC_API
103 hipError_t hipHccModuleLaunchKernel(hipFunction_t f, uint32_t globalWorkSizeX,
104  uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ,
105  uint32_t localWorkSizeX, uint32_t localWorkSizeY,
106  uint32_t localWorkSizeZ, size_t sharedMemBytes,
107  hipStream_t hStream, void** kernelParams, void** extra,
108  hipEvent_t startEvent = nullptr,
109  hipEvent_t stopEvent = nullptr)
110  __attribute__((deprecated("use hipExtModuleLaunchKernel instead")));
111 
112 #if !__HIP_VDI__ && defined(__cplusplus)
113 
114 namespace hip_impl {
115 inline
116 __attribute__((visibility("hidden")))
117 void hipExtLaunchKernelGGLImpl(
118  std::uintptr_t function_address,
119  const dim3& numBlocks,
120  const dim3& dimBlocks,
121  std::uint32_t sharedMemBytes,
122  hipStream_t stream,
123  hipEvent_t startEvent,
124  hipEvent_t stopEvent,
125  std::uint32_t flags,
126  void** kernarg) {
127 
128  const auto& kd = hip_impl::get_program_state()
129  .kernel_descriptor(function_address, target_agent(stream));
130 
131  hipExtModuleLaunchKernel(kd, numBlocks.x * dimBlocks.x,
132  numBlocks.y * dimBlocks.y,
133  numBlocks.z * dimBlocks.z,
134  dimBlocks.x, dimBlocks.y, dimBlocks.z,
135  sharedMemBytes, stream, nullptr, kernarg,
136  startEvent, stopEvent, flags);
137 }
138 } // namespace hip_impl
139 
140 template <typename... Args, typename F = void (*)(Args...)>
141 inline
142 void hipExtLaunchKernelGGL(F kernel, const dim3& numBlocks,
143  const dim3& dimBlocks, std::uint32_t sharedMemBytes,
144  hipStream_t stream, hipEvent_t startEvent,
145  hipEvent_t stopEvent, std::uint32_t flags,
146  Args... args) {
147  hip_impl::hip_init();
148  auto kernarg =
149  hip_impl::make_kernarg(kernel, std::tuple<Args...>{std::move(args)...});
150  std::size_t kernarg_size = kernarg.size();
151 
152  void* config[]{
153  HIP_LAUNCH_PARAM_BUFFER_POINTER,
154  kernarg.data(),
155  HIP_LAUNCH_PARAM_BUFFER_SIZE,
156  &kernarg_size,
157  HIP_LAUNCH_PARAM_END};
158 
159  hip_impl::hipExtLaunchKernelGGLImpl(reinterpret_cast<std::uintptr_t>(kernel),
160  numBlocks, dimBlocks, sharedMemBytes,
161  stream, startEvent, stopEvent, flags,
162  &config[0]);
163 }
164 #endif // !__HIP_VDI__ && defined(__cplusplus)
165 
166 // doxygen end AMD-specific features
170 #endif // #iidef HIP_INCLUDE_HIP_HIP_EXT_H
Definition: hip_module.cpp:108
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:282
Definition: hip_runtime_api.h:269
Definition: hip_runtime.h:202
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:2518
Definition: hip_hcc_internal.h:769
Definition: hip_hcc_internal.h:593
HIP_PUBLIC_API hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc)
Return hc::accelerator associated with the specified deviceId.
Definition: hip_hcc.cpp:2502
Definition: hip_ext.h:29