Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
CommonAcceleratorGlobal.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* AcceleratorCoreGlobal.h (C) 2000-2026 */
9/* */
10/* General declarations for accelerator support. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_ACCELERATOR_COMMONACCELERATORCOREGLOBAL_H
13#define ARCCORE_COMMON_ACCELERATOR_COMMONACCELERATORCOREGLOBAL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/common/CommonGlobal.h"
18#include "arccore/trace/TraceGlobal.h"
19
20#include <iosfwd>
21
22/*!
23 * \file AcceleratorCoreGlobal.h
24 *
25 * This file contains the declarations of the types for the
26 * 'arcane_accelerator_core' component.
27 */
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35namespace Arcane::Accelerator
36{
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41class IAcceleratorMng;
42class Runner;
43class RunQueue;
44class RunQueuePool;
45class RunCommand;
46class RunQueueEvent;
49class MemoryCopyArgs;
51class DeviceId;
52class DeviceInfo;
54class ProfileRegion;
55class IDeviceInfoList;
57class ViewBuildInfo;
58class RunnerInternal;
59enum class eMemoryAdvice;
60
61namespace Impl
62{
63 class RuntimeStaticInfo;
64 class IRunnerRuntime;
65 // typedef for compatibility with older versions (October 2022)
66 using IRunQueueRuntime = IRunnerRuntime;
67 class IRunQueueStream;
68 class RunCommandImpl;
70 class ReduceMemoryImpl;
71 class RunQueueImpl;
72 class IRunQueueEventImpl;
73 class RunnerImpl;
74 class RunQueueImplStack;
75 class KernelLaunchArgs;
77 class NativeStream;
78 class CudaUtils;
79 class HipUtils;
80 class SyclUtils;
81} // namespace Impl
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
86/*!
87 * \brief Execution policy for a Runner.
88 */
90{
91 //! No execution policy
93 //! Sequential execution policy
95 //! Multi-threaded execution policy
97 //! Execution policy using the CUDA environment
99 //! Execution policy using the HIP environment
101 //! Execution policy using the SYCL environment
103};
104
105//! Prints the name of the execution policy
106extern "C++" ARCCORE_COMMON_EXPORT
107std::ostream&
108operator<<(std::ostream& o, eExecutionPolicy exec_policy);
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113/*!
114 * \brief Reduction operation policy on accelerators.
115 *
116 * \note Starting from Arcane version 3.15, only the Grid policy is available.
117 */
119{
120 /*!
121 * \brief Uses atomic operations between blocks.
122 *
123 * \deprecated This policy is no longer available. If specified, it will
124 * behave like eDeviceReducePolicy::Grid.
125 */
126 Atomic ARCCORE_DEPRECATED_REASON("Y2025: Use eDeviceReducePolicy::Grid instead") = 1,
127 //! Uses a compute kernel with synchronization between blocks.
129};
130
131/*---------------------------------------------------------------------------*/
132/*---------------------------------------------------------------------------*/
133
134/*!
135 * \brief Predefined priority levels for run queues
136 * on accelerators
137 */
138enum class eRunQueuePriority : int
139{
140 //! Uses 0 as the default value
142 //! An arbitrary negative value to define a high priority
143 High = -100,
144 //! An arbitrary positive value to define a low priority
145 Low = 100
146};
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151//! Memory type for a pointer
153{
154 //NOTE: The values are equivalent to cudaMemoryType. If
155 // these values are changed, the corresponding function
156 // in the runtime (getPointerAttribute()) must be changed.
157 Unregistered = 0,
158 Host = 1,
159 Device = 2,
160 Managed = 3
161};
162
163//! Prints the name of the memory type
164extern "C++" ARCCORE_COMMON_EXPORT
165std::ostream&
166operator<<(std::ostream& o, ePointerMemoryType mem_type);
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171/*!
172 * \brief Accessibility information of a memory address.
173 *
174 * Indicates whether a memory address is accessible on an accelerator or
175 * on the CPU.
176 *
177 * \sa getPointerAccessibility()
178 */
180{
181 //! Unknown accessibility
183 //! Not accessible
184 No = 1,
185 //! Accessible
186 Yes = 2
187};
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
192//! Indicates if \a exec_policy corresponds to an accelerator
193inline bool
195{
196 return exec_policy == eExecutionPolicy::CUDA || exec_policy == eExecutionPolicy::HIP || exec_policy == eExecutionPolicy::SYCL;
197}
198
199/*---------------------------------------------------------------------------*/
200/*---------------------------------------------------------------------------*/
201
202/*!
203 * \brief Accessibility of address \a ptr for execution on queue \a queue.
204 *
205 * If \a queue is null, returns ePointerAccessibility::Unknown.
206 * If \a ptr_attr is not null, it will be filled with pointer information
207 * as if Runner::fillPointerAttribute() had been called.
208 */
209extern "C++" ARCCORE_COMMON_EXPORT ePointerAccessibility
210getPointerAccessibility(RunQueue* queue, const void* ptr, PointerAttribute* ptr_attr = nullptr);
211
212/*!
213 * \brief Accessibility of address \a ptr for execution on \a runner.
214 *
215 * If \a runner is null, returns ePointerAccessibility::Unknown.
216 * If \a ptr_attr is not null, it will be filled with pointer information
217 * as if Runner::fillPointerAttribute() had been called.
218 */
219extern "C++" ARCCORE_COMMON_EXPORT ePointerAccessibility
220getPointerAccessibility(Runner* runner, const void* ptr, PointerAttribute* ptr_attr = nullptr);
221
222/*!
223 * \brief Accessibility of address \a ptr for execution policy\a policy.
224 *
225 * If \a ptr_attr is not null, it will be filled with pointer information
226 * as if Runner::fillPointerAttribute() had been called.
227 */
228extern "C++" ARCCORE_COMMON_EXPORT ePointerAccessibility
229getPointerAccessibility(eExecutionPolicy policy, const void* ptr, PointerAttribute* ptr_attr = nullptr);
230
231//! Accessibility of address \a ptr for execution on \a queue_or_runner_or_policy.
232template <typename T> inline ePointerAccessibility
233getPointerAccessibility(T& queue_or_runner_or_policy, const void* ptr, PointerAttribute* ptr_attr = nullptr)
234{
235 return getPointerAccessibility(&queue_or_runner_or_policy, ptr, ptr_attr);
236}
237
238/*---------------------------------------------------------------------------*/
239/*---------------------------------------------------------------------------*/
240
241} // namespace Arcane::Accelerator
242
243/*---------------------------------------------------------------------------*/
244/*---------------------------------------------------------------------------*/
245
246namespace Arcane::Accelerator::Impl
247{
248
249/*!
250 * \brief Checks if \a ptr is accessible for execution on \a queue.
251 *
252 * Raises a FatalErrorException if it is not.
253 */
254extern "C++" ARCCORE_COMMON_EXPORT void
255arcaneCheckPointerIsAccessible(const RunQueue* queue, const void* ptr,
256 const char* name, const TraceInfo& ti);
257
258/*!
259 * \brief Checks if \a ptr is accessible for execution on \a runner.
260 *
261 * Raises a FatalErrorException if it is not.
262 */
263extern "C++" ARCCORE_COMMON_EXPORT void
264arcaneCheckPointerIsAccessible(const Runner* runner, const void* ptr,
265 const char* name, const TraceInfo& ti);
266
267/*!
268 * \brief Checks if \a ptr is accessible for execution \a policy.
269 *
270 * Raises a FatalErrorException if it is not.
271 */
272extern "C++" ARCCORE_COMMON_EXPORT void
273arcaneCheckPointerIsAccessible(eExecutionPolicy policy, const void* ptr,
274 const char* name, const TraceInfo& ti);
275
276inline void
277arcaneCheckPointerIsAccessible(const RunQueue& queue, const void* ptr,
278 const char* name, const TraceInfo& ti)
279{
280 arcaneCheckPointerIsAccessible(&queue, ptr, name, ti);
281}
282
283inline void
284arcaneCheckPointerIsAccessible(const Runner& runner, const void* ptr,
285 const char* name, const TraceInfo& ti)
286{
287 arcaneCheckPointerIsAccessible(&runner, ptr, name, ti);
288}
289
290} // namespace Arcane::Accelerator::Impl
291
292/*---------------------------------------------------------------------------*/
293/*---------------------------------------------------------------------------*/
294
295/*!
296 * Macro that checks if \a ptr is accessible for a RunQueue or a Runner.
297 *
298 * Raises an exception if it is not.
299 */
300#define ARCCORE_CHECK_ACCESSIBLE_POINTER_ALWAYS(queue_or_runner_or_policy, ptr) \
301 ::Arcane::Accelerator::Impl::arcaneCheckPointerIsAccessible((queue_or_runner_or_policy), (ptr), #ptr, A_FUNCINFO)
302
303#define ARCANE_CHECK_ACCESSIBLE_POINTER_ALWAYS(queue_or_runner_or_policy, ptr) \
304 ARCANE_CHECK_ACCESSIBLE_POINTER_ALWAYS((queue_or_runner_or_policy), (ptr))
305
306/*---------------------------------------------------------------------------*/
307/*---------------------------------------------------------------------------*/
308
309#if defined(ARCCORE_CHECK)
310
311//! Macro that checks in check mode if \a ptr is accessible for a RunQueue or a Runner.
312#define ARCCORE_CHECK_ACCESSIBLE_POINTER(queue_or_runner_or_policy, ptr) \
313 ARCCORE_CHECK_ACCESSIBLE_POINTER_ALWAYS((queue_or_runner_or_policy), (ptr))
314
315#define ARCANE_CHECK_ACCESSIBLE_POINTER(queue_or_runner_or_policy, ptr) \
316 ARCCORE_CHECK_ACCESSIBLE_POINTER((queue_or_runner_or_policy), (ptr))
317
318//! Macro that checks in check mode if \a ptr is accessible for a RunQueue or a Runner.
319#else
320
321//! Macro that checks in check mode if \a ptr is accessible for a RunQueue or a Runner.
322#define ARCCORE_CHECK_ACCESSIBLE_POINTER(queue_or_runner_or_policy, ptr)
323
324#define ARCANE_CHECK_ACCESSIBLE_POINTER(queue_or_runner_or_policy, ptr)
325
326#endif
327
328/*---------------------------------------------------------------------------*/
329/*---------------------------------------------------------------------------*/
330
331namespace Arcane::Accelerator::impl
332{
333
334// For compatibility with older versions of Arcane.
335// To be deprecated by the end of 2026.
337} // namespace Arcane::Accelerator::impl
338
339/*---------------------------------------------------------------------------*/
340/*---------------------------------------------------------------------------*/
341
342#endif
Namespace for accelerator usage.
ePointerAccessibility getPointerAccessibility(eExecutionPolicy policy, const void *ptr, PointerAttribute *ptr_attr)
Accessibility of address ptr for execution policypolicy.
eDeviceReducePolicy
Reduction operation policy on accelerators.
@ Grid
Uses a compute kernel with synchronization between blocks.
@ Atomic
Uses atomic operations between blocks.
ePointerAccessibility
Accessibility information of a memory address.
ePointerMemoryType
Memory type for a pointer.
eExecutionPolicy
Execution policy for a Runner.
@ SYCL
Execution policy using the SYCL environment.
@ HIP
Execution policy using the HIP environment.
@ CUDA
Execution policy using the CUDA environment.
@ Thread
Multi-threaded execution policy.
eRunQueuePriority
Predefined priority levels for run queues on accelerators.
@ Low
An arbitrary positive value to define a low priority.
@ High
An arbitrary negative value to define a high priority.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indicates if exec_policy corresponds to an accelerator.
@ Host
The memory is on the host.
@ Device
The memory is on the accelerator.
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Output operator for a stream.