Arcane  v4.1.0.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
core/RunCommandLaunchInfo.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* RunCommandLaunchInfo.h (C) 2000-2025 */
9/* */
10/* Informations pour l'exécution d'une 'RunCommand'. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ACCELERATOR_CORE_RUNCOMMANDLAUNCHINFO_H
13#define ARCANE_ACCELERATOR_CORE_RUNCOMMANDLAUNCHINFO_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/base/Profiling.h"
18#include "arccore/base/ForLoopRunInfo.h"
19
20#include "arcane/accelerator/core/KernelLaunchArgs.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::Accelerator::Impl
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30/*!
31 * \internal
32 * \brief Object temporaire pour conserver les informations d'exécution d'une
33 * commande et regrouper les tests.
34 */
35class ARCANE_ACCELERATOR_CORE_EXPORT RunCommandLaunchInfo
36{
37 // Les fonctions suivantes permettent de lancer les kernels.
38 template <typename SyclKernel, typename Lambda, typename LambdaArgs, typename... ReducerArgs>
39 friend void _applyKernelSYCL(RunCommandLaunchInfo& launch_info, SyclKernel kernel, Lambda& func,
40 const LambdaArgs& args, const ReducerArgs&... reducer_args);
41 template <typename CudaKernel, typename Lambda, typename LambdaArgs, typename... RemainingArgs>
42 friend void _applyKernelCUDA(RunCommandLaunchInfo& launch_info, const CudaKernel& kernel, Lambda& func,
43 const LambdaArgs& args, [[maybe_unused]] const RemainingArgs&... other_args);
44 template <typename HipKernel, typename Lambda, typename LambdaArgs, typename... RemainingArgs>
45 friend void _applyKernelHIP(RunCommandLaunchInfo& launch_info, const HipKernel& kernel, const Lambda& func,
46 const LambdaArgs& args, [[maybe_unused]] const RemainingArgs&... other_args);
47
48 public:
49
50 using ThreadBlockInfo = KernelLaunchArgs;
51
52 public:
53
54 RunCommandLaunchInfo(RunCommand& command, Int64 total_loop_size);
55 ~RunCommandLaunchInfo();
56 RunCommandLaunchInfo(const RunCommandLaunchInfo&) = delete;
57 RunCommandLaunchInfo operator=(const RunCommandLaunchInfo&) = delete;
58
59 public:
60
61 eExecutionPolicy executionPolicy() const { return m_exec_policy; }
62
63 /*!
64 * \brief Indique qu'on commence l'exécution de la commande.
65 *
66 * Doit toujours être appelé avant de lancer la commande pour être
67 * sur que cette méthode est appelée en cas d'exception.
68 */
69 void beginExecute();
70
71 /*!
72 * \brief Signale la fin de l'exécution.
73 *
74 * Si la file associée à la commande est asynchrone, la commande
75 * peut continuer à s'exécuter après cet appel.
76 */
77 void endExecute();
78
79 /*!
80 * \brief Informations sur le nombre de block/thread/grille du noyau à lancer.
81 *
82 * Cette valeur n'est valide que pour si la commande est associée à un accélérateur.
83 */
84 KernelLaunchArgs kernelLaunchArgs() const { return m_kernel_launch_args; }
85
86 //! Calcule et retourne les informations pour les boucles multi-thread
87 ParallelLoopOptions computeParallelLoopOptions() const;
88
89 /*!
90 * \brief Informations d'exécution de la boucle.
91 *
92 * Ces informations ne sont valides que si executionPolicy()==eExecutionPolicy::Thread
93 * et si beginExecute() a été appelé.
94 */
95 const ForLoopRunInfo& loopRunInfo() const { return m_loop_run_info; }
96
97 //! Taille totale de la boucle
98 Int64 totalLoopSize() const { return m_total_loop_size; }
99
100 private:
101
102 RunCommand& m_command;
103 bool m_has_exec_begun = false;
104 bool m_is_notify_end_kernel_done = false;
106 KernelLaunchArgs m_kernel_launch_args;
107 ForLoopRunInfo m_loop_run_info;
108 Int64 m_total_loop_size = 0;
109 impl::RunQueueImpl* m_queue_impl = nullptr;
110
111 private:
112
113 Int32 _sharedMemorySize() const;
114 KernelLaunchArgs _threadBlockInfo(const void* func, Int32 shared_memory_size) const;
115 NativeStream _internalNativeStream();
116 void _doEndKernelLaunch();
117 KernelLaunchArgs _computeKernelLaunchArgs() const;
118
119 // Pour test uniquement avec CUDA
120 bool _isUseCooperativeLaunch() const;
121 bool _isUseCudaLaunchKernel() const;
122
123 private:
124
125 void _computeLoopRunInfo();
126
127 // Pour SYCL: enregistre l'évènement associé à la dernière commande de la file
128 // \a sycl_event_ptr est de type 'sycl::event*'.
129 void _addSyclEvent(void* sycl_event_ptr);
130};
131
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
135} // End namespace Arcane::Accelerator::impl
136
137/*---------------------------------------------------------------------------*/
138/*---------------------------------------------------------------------------*/
139
140#endif
Type opaque pour encapsuler une 'stream' native.
friend void _applyKernelCUDA(RunCommandLaunchInfo &launch_info, const CudaKernel &kernel, Lambda &func, const LambdaArgs &args, const RemainingArgs &... other_args)
Fonction générique pour exécuter un kernel CUDA.
void beginExecute()
Indique qu'on commence l'exécution de la commande.
void endExecute()
Signale la fin de l'exécution.
Int64 totalLoopSize() const
Taille totale de la boucle.
KernelLaunchArgs kernelLaunchArgs() const
Informations sur le nombre de block/thread/grille du noyau à lancer.
const ForLoopRunInfo & loopRunInfo() const
Informations d'exécution de la boucle.
friend void _applyKernelHIP(RunCommandLaunchInfo &launch_info, const HipKernel &kernel, const Lambda &func, const LambdaArgs &args, const RemainingArgs &... other_args)
Fonction générique pour exécuter un kernel HIP.
Gestion d'une commande sur accélérateur.
Informations d'exécution d'une boucle.
Options d'exécution d'une boucle parallèle en multi-thread.
eExecutionPolicy
Politique d'exécution pour un Runner.
@ Sequential
Politique d'exécution séquentielle.
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.