29#ifndef HIP_INCLUDE_HIP_AMD_DETAIL_HIP_RUNTIME_H
30#define HIP_INCLUDE_HIP_AMD_DETAIL_HIP_RUNTIME_H
32#include <hip/amd_detail/amd_hip_common.h>
34#if !defined(__HIPCC_RTC__)
54const char* amd_dbgapi_get_build_name();
63const char* amd_dbgapi_get_git_hash();
72size_t amd_dbgapi_get_build_id();
81#if !defined(__HIPCC_RTC__)
91#if !__HIP_NO_STD_DEFS__
92typedef unsigned int uint32_t;
93typedef unsigned long long uint64_t;
94typedef signed int int32_t;
95typedef signed long long int64_t;
105#if __HIP_CLANG_ONLY__
107#if !defined(__align__)
108#define __align__(x) __attribute__((aligned(x)))
111#define CUDA_SUCCESS hipSuccess
113#if !defined(__HIPCC_RTC__)
114#include <hip/hip_runtime_api.h>
115#include <hip/amd_detail/amd_hip_atomic.h>
116#include <hip/amd_detail/amd_device_functions.h>
117#include <hip/amd_detail/amd_surface_functions.h>
118#include <hip/amd_detail/texture_fetch_functions.h>
119#include <hip/amd_detail/texture_indirect_functions.h>
120extern int HIP_TRACE_API;
124#include <hip/amd_detail/hip_ldg.h>
130#if defined(__KALMAR_ACCELERATOR__) && !defined(__HCC_ACCELERATOR__)
131#define __HCC_ACCELERATOR__ __KALMAR_ACCELERATOR__
135#if (defined(__HCC_ACCELERATOR__) && (__HCC_ACCELERATOR__ != 0)) || __HIP_DEVICE_COMPILE__
139#define __HIP_ARCH_HAS_GLOBAL_INT32_ATOMICS__ (1)
140#define __HIP_ARCH_HAS_GLOBAL_FLOAT_ATOMIC_EXCH__ (1)
141#define __HIP_ARCH_HAS_SHARED_INT32_ATOMICS__ (1)
142#define __HIP_ARCH_HAS_SHARED_FLOAT_ATOMIC_EXCH__ (1)
143#define __HIP_ARCH_HAS_FLOAT_ATOMIC_ADD__ (1)
146#define __HIP_ARCH_HAS_GLOBAL_INT64_ATOMICS__ (1)
147#define __HIP_ARCH_HAS_SHARED_INT64_ATOMICS__ (1)
150#define __HIP_ARCH_HAS_DOUBLES__ (1)
153#define __HIP_ARCH_HAS_WARP_VOTE__ (1)
154#define __HIP_ARCH_HAS_WARP_BALLOT__ (1)
155#define __HIP_ARCH_HAS_WARP_SHUFFLE__ (1)
156#define __HIP_ARCH_HAS_WARP_FUNNEL_SHIFT__ (0)
159#define __HIP_ARCH_HAS_THREAD_FENCE_SYSTEM__ (1)
160#define __HIP_ARCH_HAS_SYNC_THREAD_EXT__ (0)
163#define __HIP_ARCH_HAS_SURFACE_FUNCS__ (0)
164#define __HIP_ARCH_HAS_3DGRID__ (1)
165#define __HIP_ARCH_HAS_DYNAMIC_PARALLEL__ (0)
170#define launch_bounds_impl0(requiredMaxThreadsPerBlock) \
171 __attribute__((amdgpu_flat_work_group_size(1, requiredMaxThreadsPerBlock)))
172#define launch_bounds_impl1(requiredMaxThreadsPerBlock, minBlocksPerMultiprocessor) \
173 __attribute__((amdgpu_flat_work_group_size(1, requiredMaxThreadsPerBlock), \
174 amdgpu_waves_per_eu(minBlocksPerMultiprocessor)))
175#define select_impl_(_1, _2, impl_, ...) impl_
176#define __launch_bounds__(...) \
177 select_impl_(__VA_ARGS__, launch_bounds_impl1, launch_bounds_impl0, )(__VA_ARGS__)
179#if !defined(__HIPCC_RTC__)
180__host__ inline void* __get_dynamicgroupbaseptr() {
return nullptr; }
191#if !defined(__HIPCC_RTC__)
192#define HIP_KERNEL_NAME(...) __VA_ARGS__
193#define HIP_SYMBOL(X) X
195typedef int hipLaunchParm;
197template <std::size_t n,
typename... Ts,
198 typename std::enable_if<n ==
sizeof...(Ts)>::type* =
nullptr>
199void pArgs(
const std::tuple<Ts...>&,
void*) {}
201template <std::size_t n,
typename... Ts,
202 typename std::enable_if<n !=
sizeof...(Ts)>::type* =
nullptr>
203void pArgs(
const std::tuple<Ts...>& formals,
void** _vargs) {
204 using T =
typename std::tuple_element<n, std::tuple<Ts...> >::type;
206 static_assert(!std::is_reference<T>{},
207 "A __global__ function cannot have a reference as one of its "
209#if defined(HIP_STRICT)
210 static_assert(std::is_trivially_copyable<T>{},
211 "Only TriviallyCopyable types can be arguments to a __global__ "
214 _vargs[n] =
const_cast<void*
>(
reinterpret_cast<const void*
>(&std::get<n>(formals)));
215 return pArgs<n + 1>(formals, _vargs);
218template <
typename... Formals,
typename... Actuals>
219std::tuple<Formals...> validateArgsCountType(
void (*kernel)(Formals...), std::tuple<Actuals...>(actuals)) {
220 static_assert(
sizeof...(Formals) ==
sizeof...(Actuals),
"Argument Count Mismatch");
221 std::tuple<Formals...> to_formals{std::move(actuals)};
225#if defined(HIP_TEMPLATE_KERNEL_LAUNCH)
226template <
typename... Args,
typename F = void (*)(Args...)>
227void hipLaunchKernelGGL(F kernel,
const dim3& numBlocks,
const dim3& dimBlocks,
228 std::uint32_t sharedMemBytes, hipStream_t stream, Args... args) {
229 constexpr size_t count =
sizeof...(Args);
230 auto tup_ = std::tuple<Args...>{args...};
231 auto tup = validateArgsCountType(kernel, tup_);
233 pArgs<0>(tup, _Args);
235 auto k =
reinterpret_cast<void*
>(kernel);
236 hipLaunchKernel(k, numBlocks, dimBlocks, _Args, sharedMemBytes, stream);
239#define hipLaunchKernelGGLInternal(kernelName, numBlocks, numThreads, memPerBlock, streamId, ...) \
241 kernelName<<<(numBlocks), (numThreads), (memPerBlock), (streamId)>>>(__VA_ARGS__); \
244#define hipLaunchKernelGGL(kernelName, ...) hipLaunchKernelGGLInternal((kernelName), __VA_ARGS__)
247#include <hip/hip_runtime_api.h>
250extern "C" __device__ __attribute__((
const)) size_t __ockl_get_local_id(
unsigned int);
251extern "C" __device__ __attribute__((const))
size_t __ockl_get_group_id(
unsigned int);
252extern "C" __device__ __attribute__((const))
size_t __ockl_get_local_size(
unsigned int);
253extern "C" __device__ __attribute__((const))
size_t __ockl_get_num_groups(
unsigned int);
254struct __HIP_BlockIdx {
256 std::uint32_t operator()(std::uint32_t x)
const noexcept {
return __ockl_get_group_id(x); }
258struct __HIP_BlockDim {
260 std::uint32_t operator()(std::uint32_t x)
const noexcept {
261 return __ockl_get_local_size(x);
264struct __HIP_GridDim {
266 std::uint32_t operator()(std::uint32_t x)
const noexcept {
267 return __ockl_get_num_groups(x);
270struct __HIP_ThreadIdx {
272 std::uint32_t operator()(std::uint32_t x)
const noexcept {
273 return __ockl_get_local_id(x);
277#if defined(__HIPCC_RTC__)
283 constexpr __device__ dim3(uint32_t _x = 1, uint32_t _y = 1, uint32_t _z = 1) : x(_x), y(_y), z(_z){};
288extern "C" __device__ __attribute__((
const)) size_t __ockl_get_global_size(
unsigned int);
291template <
typename F>
struct __HIP_Coordinates {
292 using R =
decltype(F{}(0));
295 __device__
operator R() const noexcept {
return F{}(0); }
296 __device__ R operator+=(
const R& rhs) {
return F{}(0) + rhs; }
299 __device__
operator R() const noexcept {
return F{}(1); }
300 __device__ R operator+=(
const R& rhs) {
return F{}(1) + rhs; }
303 __device__
operator R() const noexcept {
return F{}(2); }
304 __device__ R operator+=(
const R& rhs) {
return F{}(2) + rhs; }
307#if !defined(_MSC_VER)
308 __attribute__((weak))
310 __device__
static constexpr __X x{};
311#if !defined(_MSC_VER)
312 __attribute__((weak))
314 __device__
static constexpr __Y y{};
315#if !defined(_MSC_VER)
316 __attribute__((weak))
318 __device__
static constexpr __Z z{};
320 __device__
operator dim3()
const {
return dim3(x, y, z); }
324constexpr typename __HIP_Coordinates<F>::__X __HIP_Coordinates<F>::x;
326constexpr typename __HIP_Coordinates<F>::__Y __HIP_Coordinates<F>::y;
328constexpr typename __HIP_Coordinates<F>::__Z __HIP_Coordinates<F>::z;
332std::uint32_t operator*(__HIP_Coordinates<__HIP_GridDim>::__X,
333 __HIP_Coordinates<__HIP_BlockDim>::__X)
noexcept {
334 return __ockl_get_global_size(0);
338std::uint32_t operator*(__HIP_Coordinates<__HIP_BlockDim>::__X,
339 __HIP_Coordinates<__HIP_GridDim>::__X)
noexcept {
340 return __ockl_get_global_size(0);
344std::uint32_t operator*(__HIP_Coordinates<__HIP_GridDim>::__Y,
345 __HIP_Coordinates<__HIP_BlockDim>::__Y)
noexcept {
346 return __ockl_get_global_size(1);
350std::uint32_t operator*(__HIP_Coordinates<__HIP_BlockDim>::__Y,
351 __HIP_Coordinates<__HIP_GridDim>::__Y)
noexcept {
352 return __ockl_get_global_size(1);
356std::uint32_t operator*(__HIP_Coordinates<__HIP_GridDim>::__Z,
357 __HIP_Coordinates<__HIP_BlockDim>::__Z)
noexcept {
358 return __ockl_get_global_size(2);
362std::uint32_t operator*(__HIP_Coordinates<__HIP_BlockDim>::__Z,
363 __HIP_Coordinates<__HIP_GridDim>::__Z)
noexcept {
364 return __ockl_get_global_size(2);
367static constexpr __HIP_Coordinates<__HIP_BlockDim> blockDim{};
368static constexpr __HIP_Coordinates<__HIP_BlockIdx> blockIdx{};
369static constexpr __HIP_Coordinates<__HIP_GridDim> gridDim{};
370static constexpr __HIP_Coordinates<__HIP_ThreadIdx> threadIdx{};
373extern "C" __device__ __attribute__((
const)) size_t __ockl_get_local_id(
unsigned int);
374#define hipThreadIdx_x (__ockl_get_local_id(0))
375#define hipThreadIdx_y (__ockl_get_local_id(1))
376#define hipThreadIdx_z (__ockl_get_local_id(2))
378extern "C" __device__ __attribute__((
const)) size_t __ockl_get_group_id(
unsigned int);
379#define hipBlockIdx_x (__ockl_get_group_id(0))
380#define hipBlockIdx_y (__ockl_get_group_id(1))
381#define hipBlockIdx_z (__ockl_get_group_id(2))
383extern "C" __device__ __attribute__((
const)) size_t __ockl_get_local_size(
unsigned int);
384#define hipBlockDim_x (__ockl_get_local_size(0))
385#define hipBlockDim_y (__ockl_get_local_size(1))
386#define hipBlockDim_z (__ockl_get_local_size(2))
388extern "C" __device__ __attribute__((
const)) size_t __ockl_get_num_groups(
unsigned int);
389#define hipGridDim_x (__ockl_get_num_groups(0))
390#define hipGridDim_y (__ockl_get_num_groups(1))
391#define hipGridDim_z (__ockl_get_num_groups(2))
393#if !defined(__HIPCC_RTC__)
394#include <hip/amd_detail/amd_math_functions.h>
397#if __HIP_HCC_COMPAT_MODE__
399#pragma push_macro("__DEFINE_HCC_FUNC")
400#define __DEFINE_HCC_FUNC(hc_fun,hip_var) \
401inline __device__ __attribute__((always_inline)) unsigned int hc_get_##hc_fun(unsigned int i) { \
410__DEFINE_HCC_FUNC(workitem_id, threadIdx)
411__DEFINE_HCC_FUNC(group_id, blockIdx)
412__DEFINE_HCC_FUNC(group_size, blockDim)
413__DEFINE_HCC_FUNC(num_groups, gridDim)
414#pragma pop_macro("__DEFINE_HCC_FUNC")
416extern "C" __device__ __attribute__((
const)) size_t __ockl_get_global_id(
unsigned int);
417inline __device__ __attribute__((always_inline))
unsigned int
418hc_get_workitem_absolute_id(
int dim)
420 return (
unsigned int)__ockl_get_global_id(dim);
425#if !__CLANG_HIP_RUNTIME_WRAPPER_INCLUDED__
426#if !defined(__HIPCC_RTC__)
428#if !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__
429#pragma push_macro("__CUDA__")
431#include <__clang_cuda_math_forward_declares.h>
432#include <__clang_cuda_complex_builtins.h>
438#include <include/cuda_wrappers/algorithm>
439#include <include/cuda_wrappers/complex>
440#include <include/cuda_wrappers/new>
442#pragma pop_macro("__CUDA__")
#define __host__
Definition host_defines.h:166