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_ROCclr__ && defined(__cplusplus)
113 #if defined(__HIP_PLATFORM_HCC__) && GENERIC_GRID_LAUNCH == 1 && defined(__HCC__)
114 //kernel_descriptor and hip_impl::make_kernarg are in "grid_launch_GGL.hpp"
115 
116 namespace hip_impl {
117 inline
118 __attribute__((visibility("hidden")))
119 void hipExtLaunchKernelGGLImpl(
120  std::uintptr_t function_address,
121  const dim3& numBlocks,
122  const dim3& dimBlocks,
123  std::uint32_t sharedMemBytes,
124  hipStream_t stream,
125  hipEvent_t startEvent,
126  hipEvent_t stopEvent,
127  std::uint32_t flags,
128  void** kernarg) {
129 
130  const auto& kd = hip_impl::get_program_state()
131  .kernel_descriptor(function_address, target_agent(stream));
132 
133  hipExtModuleLaunchKernel(kd, numBlocks.x * dimBlocks.x,
134  numBlocks.y * dimBlocks.y,
135  numBlocks.z * dimBlocks.z,
136  dimBlocks.x, dimBlocks.y, dimBlocks.z,
137  sharedMemBytes, stream, nullptr, kernarg,
138  startEvent, stopEvent, flags);
139 }
140 } // namespace hip_impl
141 
142 template <typename... Args, typename F = void (*)(Args...)>
143 inline
144 void hipExtLaunchKernelGGL(F kernel, const dim3& numBlocks,
145  const dim3& dimBlocks, std::uint32_t sharedMemBytes,
146  hipStream_t stream, hipEvent_t startEvent,
147  hipEvent_t stopEvent, std::uint32_t flags,
148  Args... args) {
149  hip_impl::hip_init();
150  auto kernarg =
151  hip_impl::make_kernarg(kernel, std::tuple<Args...>{std::move(args)...});
152  std::size_t kernarg_size = kernarg.size();
153 
154  void* config[]{
155  HIP_LAUNCH_PARAM_BUFFER_POINTER,
156  kernarg.data(),
157  HIP_LAUNCH_PARAM_BUFFER_SIZE,
158  &kernarg_size,
159  HIP_LAUNCH_PARAM_END};
160 
161  hip_impl::hipExtLaunchKernelGGLImpl(reinterpret_cast<std::uintptr_t>(kernel),
162  numBlocks, dimBlocks, sharedMemBytes,
163  stream, startEvent, stopEvent, flags,
164  &config[0]);
165 }
166 #endif // !__HIP_ROCclr__ && defined(__cplusplus)
167 
168 // doxygen end AMD-specific features
172 #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:296
Definition: hip_runtime_api.h:273
Definition: hip_runtime.h:210
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
Definition: hip_hcc_internal.h:759
Definition: hip_hcc_internal.h:580
HIP_PUBLIC_API hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc)
Return hc::accelerator associated with the specified deviceId.
Definition: hip_hcc.cpp:2512
Definition: hip_ext.h:29