17namespace alpaka::onAcc::internal
20 template<
typename T_Storage,
typename T_Type>
21 struct GlobalDeviceMemoryWrapper;
30 template<
typename T_Api, alpaka::concepts::DeviceKind T_DeviceKind>
33 auto operator()(T_Api api, T_DeviceKind deviceType)
const;
37 static auto makePlatform(
auto api, alpaka::concepts::DeviceKind
auto deviceType)
44 template<
typename T_Platform>
47 uint32_t operator()(T_Platform& platform)
const
49 return platform.getDeviceCount();
56 template<
typename T_Platform>
59 auto operator()(
auto& platform, uint32_t idx)
const
61 return platform.makeDevice(idx);
68 template<
typename T_Any>
71 auto operator()(T_Any
const& any)
const
73 return any.getDevice();
78 inline constexpr auto getDevice(
auto&& any)
83 struct GetNativeHandle
85 template<
typename T_Any>
88 auto operator()(T_Any
const& any)
const
90 return any.getNativeHandle();
95 inline auto getNativeHandle(
auto&& any)
102 template<
typename T_Device, alpaka::concepts::QueueKind T_QueueKind>
105 auto operator()(T_Device& device, T_QueueKind)
const
107 return device.makeQueue(T_QueueKind{});
114 template<
typename T_Device>
117 auto operator()(T_Device& device)
const
119 return device.makeEvent();
126 template<
typename T_Any>
129 void operator()(T_Any& any)
136 inline void wait(
auto&& any)
143 template<
typename T_Queue,
typename T_Event>
146 void operator()(T_Queue& queue, T_Event& event)
148 queue.waitFor(event);
153 inline void waitFor(
auto& queue,
auto& event)
158 struct IsEventComplete
160 template<
typename T_Any>
163 bool operator()(T_Any& any)
165 return any.isEventComplete();
170 inline bool isEventComplete(
auto&& any)
177 template<
typename T_Queue>
180 bool operator()(T_Queue& queue)
182 return queue.isQueueEmpty();
187 inline bool isQueueEmpty(
auto& queue)
196 onHost::concepts::ThreadOrFrameSpec T_LaunchCfg,
197 alpaka::concepts::KernelBundle T_KernelBundle>
200 void operator()(T_Queue& queue, T_LaunchCfg
const& launchCfg, T_KernelBundle
const& kernelBundle)
const
202 queue.enqueue(launchCfg, kernelBundle);
206 template<
typename T_Queue,
typename T_Task>
209 void operator()(T_Queue& queue, T_Task
const& task)
const
211 queue.enqueueHostFn(task);
215 template<
typename T_Queue,
typename T_Task>
216 struct HostTaskDeferred
218 void operator()(T_Queue& queue, T_Task
const& task)
const
220 queue.enqueueHostFnDeferred(task);
224 template<
typename T_Queue,
typename T_Task>
227 void operator()(T_Queue& queue, T_Task
const& fn)
const
229 queue.enqueueNativeFn(fn);
233 template<
typename T_Queue,
typename T_Event>
236 void operator()(T_Queue& queue, T_Event& event)
const
238 queue.enqueue(event);
243 inline void enqueueHostFn(
auto& queue,
auto const& task)
248 inline void enqueueHostFnDeferred(
auto& queue,
auto const& task)
253 template<
typename TKernelFn,
typename... TArgs>
256 onHost::concepts::ThreadOrFrameSpec
auto const& launchCfg,
265 struct AdjustThreadSpec
269 onHost::concepts::FrameSpec T_FrameSpec,
270 alpaka::concepts::KernelBundle T_KernelBundle>
274 T_Device
const& device,
275 T_FrameSpec
const& frameSpec,
276 T_KernelBundle
const& kernelBundle)
const
278 alpaka::unused(device, frameSpec.getExecutor(), kernelBundle);
279 return ThreadSpec{frameSpec.getNumFrames(), frameSpec.getFrameExtents(), frameSpec.getExecutor()};
284 template<
typename TKernelFn,
typename... TArgs>
285 static auto adjustThreadSpec(
287 onHost::concepts::FrameSpec
auto const& frameSpec,
290 return AdjustThreadSpec::
299 template<
typename T_Any>
302 decltype(
auto)
operator()(
auto&&
any)
const
304 return std::data(any);
308 static decltype(
auto) data(
auto&& any)
313 template<
typename T_Any>
316 return Op<
ALPAKA_TYPEOF(*anyHandle.get())>{}(*anyHandle.get());
322 template<
typename T_Type,
typename T_Any,
typename T_Extents>
325 void operator()(T_Any& any, T_Extents
const&)
const;
331 template<
typename T_Type,
typename T_Any,
typename T_Extents>
334 void operator()(T_Any& any, T_Extents
const&)
const;
340 template<
typename T_Type,
typename T_Any,
typename T_Extents>
343 void operator()(T_Any& any, T_Extents
const&)
const;
349 template<
typename T_Type,
typename T_Any,
typename T_Extents>
352 void operator()(T_Any& any, T_Extents
const&)
const;
364 struct IsDataAccessible
366 template<
typename T_Device,
typename T_Any>
369 bool operator()(T_Device& device, T_Any
const& any)
const;
372 template<
typename T_DataApi, alpaka::concepts::DeviceKind T_DeviceKind,
typename T_Any>
375 bool operator()(T_DataApi, T_DeviceKind, T_Any
const&)
const
384 template<
typename T_Queue,
typename T_Dest,
typename T_Source,
typename T_Extents>
387 void operator()(T_Queue& queue,
auto&&, T_Source
const&, T_Extents
const&)
const;
391 struct MemcpyDeviceGlobal
393 template<
typename T_Queue,
typename T_Dest,
typename T_Source>
402 void operator()(T_Queue& queue, T_Dest&&, T_Source&&)
const;
408 template<
typename T_Queue,
typename T_Dest,
typename T_Extents>
411 void operator()(T_Queue& queue,
auto&&, uint8_t, T_Extents
const&)
const;
417 template<
typename T_Queue,
typename T_Dest,
typename T_Value,
typename T_Extents>
420 void operator()(T_Queue& queue,
auto&&, T_Value, T_Extents
const&)
const;
424 struct GetDeviceProperties
426 template<
typename T_Any>
429 DeviceProperties operator()(
auto const& platform, uint32_t idx)
const;
431 DeviceProperties operator()(
auto const& device)
const;
435 struct GetFreeGlobalMemBytes
437 template<
typename T_Any>
440 size_t operator()(
auto const& device)
const
442 return device.getFreeGlobalMemBytes();
447 inline DeviceProperties getDeviceProperties(
auto const& platform, uint32_t idx)
449 return GetDeviceProperties::Op<
ALPAKA_TYPEOF(platform)>{}(platform, idx);
454 template<
typename T_Any>
457 decltype(
auto)
operator()(
auto&&
any)
const
459 return any.getExtents();
464 inline auto getExtents(
auto&& any)
469 template<
typename T_Any>
477 template<
typename T_Any>
480 decltype(
auto)
operator()(
auto&&
any)
const
482 return any.getPitches();
487 inline auto getPitches(
auto&& any)
492 template<
typename T_Any>
502 inline constexpr auto getFrameSpec(
503 auto const& internalDevice,
504 alpaka::concepts::Executor
auto executor,
505 alpaka::concepts::VectorOrScalar
auto const& extents)
507 static_assert(executor !=
exec::anyExecutor,
"'exec::anyExecutor' can not be used here");
508 Vec extentMd = extents;
513 auto props = internal::GetDeviceProperties::Op<
ALPAKA_TYPEOF(internalDevice)>{}(internalDevice);
514 IndexType
warpSize =
static_cast<IndexType
>(props.warpSize);
516 IndexType numFrameElements = 512;
519 ExtentVecType frameExtents = ExtentVecType::fill(1).rAssign(fastDimensionValue);
520 numFrameElements /= frameExtents.x();
522 while(numFrameElements > IndexType{1})
524 uint32_t maxIdx = ExtentVecType::dim() - 1u;
525 IndexType maxValue = 0;
526 for(
auto i = 0u; i < ExtentVecType::dim(); ++i)
528 auto v = extentMd[i] / frameExtents[i] / IndexType{2};
536 auto v = extentMd[maxIdx] / frameExtents[maxIdx] / IndexType{2};
537 if(v >= IndexType{1})
538 frameExtents[maxIdx] *= IndexType{2};
541 numFrameElements /= IndexType{2};
544 ExtentVecType numFrames =
divExZero(extentMd, frameExtents);
545 auto frameSpec =
FrameSpec{numFrames, frameExtents, executor};
556 template<
typename T_DataType>
557 inline constexpr auto getSimdFrameSpec(
558 auto const& internalDevice,
559 alpaka::concepts::Executor
auto executor,
560 alpaka::concepts::VectorOrScalar
auto const& extents)
562 static_assert(executor !=
exec::anyExecutor,
"'exec::anyExecutor' can not be used here");
563 Vec extentMd = extents;
564 auto deviceKind = alpaka::internal::getDeviceKind(internalDevice);
565 auto deviceApi = alpaka::internal::getApi(internalDevice);
571 ExtentVecType frameExtents = getFrameSpec(internalDevice, executor, extents).getFrameExtents();
573 IndexType elementsPerFrameItem
579 ExtentVecType numFrames
580 =
divExZero(extentMd, frameExtents * frameExtents.fill(1).rAssign(elementsPerFrameItem));
#define ALPAKA_ASSERT(...)
The assert can be explicit disabled by defining NDEBUG.
#define ALPAKA_TYPEOF(...)
Get the type of instance.
constexpr AnyExecutor anyExecutor
Automatic executor selection.
constexpr WarpSize warpSize
constexpr DeviceKind deviceKind
constexpr bool any(alpaka::onAcc::concepts::Acc auto const &acc, int32_t predicate)
Evaluates predicate for all active threads of the warp.
Functionality which is usable on the host CPU controller thread.
FrameSpec(T_NumFrames const &, T_FrameExtents const &) -> FrameSpec< alpaka::trait::getVec_t< T_NumFrames >, alpaka::trait::getVec_t< T_FrameExtents >, alpaka::exec::AnyExecutor >
std::shared_ptr< T > Handle
ThreadSpec(T_NumBlocks const &, T_NumThreads const &) -> ThreadSpec< alpaka::trait::getVec_t< T_NumBlocks >, alpaka::trait::getVec_t< T_NumThreads > >
void reduce(Queue< T_Device, T_QueueKind > const &queue, alpaka::concepts::Executor auto const exec, DataType const &neutralElement, alpaka::concepts::IMdSpan auto out, auto &&binaryReduceFn, auto &&in)
accumulate the results into a scalar value.
typename GetValueType< T >::type GetValueType_t
ALPAKA_FN_HOST_ACC constexpr auto divExZero(Integral a, Integral b) -> Integral
Returns the max(a / b, 1) as integer.
consteval uint32_t getNumElemPerThread(concepts::Api auto const api, alpaka::concepts::DeviceKind auto const deviceType)
Get the number of elements to compute per thread.
constexpr T roundDownToPowerOfTwo(T value)
round to the next power of two which is equal or lower to the value
ALPAKA_FN_HOST_ACC Vec(T_1, T_Args...) -> Vec< T_1, uint32_t(sizeof...(T_Args)+1u), ArrayStorage< T_1, uint32_t(sizeof...(T_Args)+1u)> >
ALPAKA_FN_HOST KernelBundle(TKernelFn const &, TArgs &&...) -> KernelBundle< TKernelFn, TArgs... >
User defined deduction guide with trailing return type. For CTAD during the construction.