Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
CommonUtils.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* CommonUtils.cc (C) 2000-2024 */
9/* */
10/* Fonctions/Classes utilitaires communes à tout les runtimes. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/accelerator/CommonUtils.h"
15
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/MemoryUtils.h"
18
19#if defined(ARCANE_COMPILING_HIP)
20#include "arcane/accelerator/hip/HipAccelerator.h"
21#endif
22#if defined(ARCANE_COMPILING_CUDA)
23#include "arcane/accelerator/cuda/CudaAccelerator.h"
24#endif
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane::Accelerator::impl
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35#if defined(ARCANE_COMPILING_CUDA)
36
37cudaStream_t CudaUtils::
38toNativeStream(const RunQueue* queue)
39{
41 if (queue)
42 p = queue->executionPolicy();
44 ARCANE_FATAL("RunQueue is not a CUDA queue");
45 cudaStream_t* s = reinterpret_cast<cudaStream_t*>(queue->platformStream());
46 if (!s)
47 ARCANE_FATAL("Null stream");
48 return *s;
49}
50
51cudaStream_t CudaUtils::
52toNativeStream(const RunQueue& queue)
53{
54 return toNativeStream(&queue);
55}
56
57#endif
58
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
62#if defined(ARCANE_COMPILING_HIP)
63
64hipStream_t HipUtils::
65toNativeStream(const RunQueue* queue)
66{
68 if (queue)
69 p = queue->executionPolicy();
70 if (p != eExecutionPolicy::HIP)
71 ARCANE_FATAL("RunQueue is not a HIP queue");
72 hipStream_t* s = reinterpret_cast<hipStream_t*>(queue->platformStream());
73 if (!s)
74 ARCANE_FATAL("Null stream");
75 return *s;
76}
77
78hipStream_t HipUtils::
79toNativeStream(const RunQueue& queue)
80{
81 return toNativeStream(&queue);
82}
83
84#endif
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
89#if defined(ARCANE_COMPILING_SYCL)
90
91sycl::queue SyclUtils::
92toNativeStream(const RunQueue* queue)
93{
95 if (queue)
96 p = queue->executionPolicy();
98 ARCANE_FATAL("RunQueue is not a SYCL queue");
99 sycl::queue* s = reinterpret_cast<sycl::queue*>(queue->platformStream());
100 if (!s)
101 ARCANE_FATAL("Null stream");
102 return *s;
103}
104
105sycl::queue SyclUtils::
106toNativeStream(const RunQueue& queue)
107{
108 return toNativeStream(&queue);
109}
110
111#endif
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
115
117_copyToAsync(Span<std::byte> destination, Span<const std::byte> source, const RunQueue& queue)
118{
119#if defined(ARCANE_COMPILING_CUDA)
120 cudaStream_t stream = CudaUtils::toNativeStream(queue);
121 ARCANE_CHECK_CUDA(::cudaMemcpyAsync(destination.data(), source.data(), source.size(), cudaMemcpyDeviceToHost, stream));
122#elif defined(ARCANE_COMPILING_HIP)
123 hipStream_t stream = HipUtils::toNativeStream(queue);
124 ARCANE_CHECK_HIP(::hipMemcpyAsync(destination.data(), source.data(), source.size(), hipMemcpyDefault, stream));
125#else
126 ARCANE_UNUSED(destination);
127 ARCANE_UNUSED(source);
128 ARCANE_UNUSED(queue);
129 ARCANE_FATAL("No valid implementation for copy");
130#endif
131}
132
133/*---------------------------------------------------------------------------*/
134/*---------------------------------------------------------------------------*/
135
136GenericDeviceStorage::
137GenericDeviceStorage()
138: m_storage(MemoryUtils::getDeviceOrHostAllocator())
139{
140}
141
142/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144
145} // namespace Arcane::Accelerator::impl
146
147/*---------------------------------------------------------------------------*/
148/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
File d'exécution pour un accélérateur.
void _copyToAsync(Span< std::byte > destination, Span< const std::byte > source, const RunQueue &queue)
Copie l'instance dans dest_ptr.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Definition Span.h:209
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
Definition Span.h:419
Vue d'un tableau d'éléments de type T.
Definition Span.h:510
eExecutionPolicy
Politique d'exécution pour un Runner.
@ SYCL
Politique d'exécution utilisant l'environnement SYCL.
@ HIP
Politique d'exécution utilisant l'environnement HIP.
@ None
Aucune politique d'exécution.
@ CUDA
Politique d'exécution utilisant l'environnement CUDA.