14#include "arccore/common/accelerator/RunCommandLaunchInfo.h"
16#include "arccore/base/FatalErrorException.h"
17#include "arccore/base/CheckedConvert.h"
18#include "arccore/base/ConcurrencyBase.h"
20#include "arccore/common/accelerator/KernelLaunchArgs.h"
21#include "arccore/common/accelerator/RunCommand.h"
22#include "arccore/common/accelerator/NativeStream.h"
23#include "arccore/common/accelerator/internal/RunQueueImpl.h"
24#include "arccore/common/accelerator/internal/IRunnerRuntime.h"
25#include "arccore/common/accelerator/internal/RunCommandImpl.h"
30namespace Arcane::Accelerator::Impl
36void RunCommandLaunchInfo::
39 m_queue_impl = m_command._internalQueueImpl();
40 m_exec_policy = m_queue_impl->executionPolicy();
43 _computeInitialKernelLaunchArgs();
44 m_command._allocateReduceMemory(m_kernel_launch_args.nbBlockPerGrid());
46 m_is_forced_need_barrier = m_command.m_p->hasActiveReduction();
54RunCommandLaunchInfo(RunCommand& command,
Int64 total_loop_size)
56, m_total_loop_size(total_loop_size)
65RunCommandLaunchInfo(RunCommand& command, Int64 total_loop_size,
bool is_cooperative)
67, m_is_cooperative_launch(is_cooperative)
68, m_total_loop_size(total_loop_size)
77~RunCommandLaunchInfo() noexcept(false)
87void RunCommandLaunchInfo::
92 m_has_exec_begun =
true;
93 m_command._internalNotifyBeginLaunchKernel();
95 _computeLoopRunInfo();
106void RunCommandLaunchInfo::
109 if (!m_has_exec_begun)
110 ARCCORE_FATAL(
"beginExecute() has to be called before endExecute()");
111 _doEndKernelLaunch();
117void RunCommandLaunchInfo::
120 if (m_is_notify_end_kernel_done)
122 m_is_notify_end_kernel_done =
true;
123 m_command._internalNotifyEndLaunchKernel();
125 Impl::RunQueueImpl* q = m_queue_impl;
126 if (!q->isAsync() || m_is_need_barrier || m_is_forced_need_barrier)
127 q->_internalBarrier();
133NativeStream RunCommandLaunchInfo::
134_internalNativeStream()
136 return m_command._internalNativeStream();
145void RunCommandLaunchInfo::
146_computeInitialKernelLaunchArgs()
148 int threads_per_block = m_command.nbThreadPerBlock();
149 if (threads_per_block<=0)
150 threads_per_block = 256;
151 Int64 big_b = (m_total_loop_size + threads_per_block - 1) / threads_per_block;
152 int blocks_per_grid = CheckedConvert::toInt32(big_b);
153 m_kernel_launch_args = KernelLaunchArgs(blocks_per_grid, threads_per_block);
154 m_kernel_launch_args.setSharedMemorySize(m_command._sharedMemory());
155 m_kernel_launch_args.setIsCooperative(m_is_cooperative_launch);
162computeParallelLoopOptions()
const
165 const bool use_dynamic_compute =
true;
169 if (use_dynamic_compute && opt.
grainSize() == 0) {
175 Int32 grain_size =
static_cast<Int32>((double)m_total_loop_size / (nb_thread * 2.0));
188void RunCommandLaunchInfo::
192 m_loop_run_info =
ForLoopRunInfo(computeParallelLoopOptions(), lti);
193 m_loop_run_info.setExecStat(m_command._internalCommandExecStat());
207KernelLaunchArgs RunCommandLaunchInfo::
208_computeKernelLaunchArgs(
const void* func)
const
210 Impl::IRunnerRuntime* r = m_queue_impl->_internalRuntime();
212 return r->computeKernalLaunchArgs(m_kernel_launch_args, func,
219void RunCommandLaunchInfo::
220_addSyclEvent(
void* sycl_event_ptr)
222 m_command._internalNotifyBeginLaunchKernelSyclEvent(sycl_event_ptr);
228bool RunCommandLaunchInfo::
229_isUseCooperativeLaunch()
const
232 return m_is_cooperative_launch;
237bool RunCommandLaunchInfo::
238_isUseCudaLaunchKernel()
const
247void RunCommandLaunchInfo::
248_setIsNeedBarrier(
bool v)
250 m_is_need_barrier = v;
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
static Int32 maxAllowedThread()
Nombre maximum de threads autorisés pour le multi-threading.
Informations d'exécution d'une boucle.
Informations de trace pour une boucle 'for'.
Options d'exécution d'une boucle parallèle en multi-thread.
Integer grainSize() const
Taille d'un intervalle d'itération.
Int32 maxThread() const
Nombre maximal de threads autorisés.
void setGrainSize(Integer v)
Positionne la taille (approximative) d'un intervalle d'itération.
@ Thread
Politique d'exécution multi-thread.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indique si exec_policy correspond à un accélérateur.
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.