Arcane  v4.1.0.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
RunCommandLocalMemory.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/* RunCommandLocalMemory.h (C) 2000-2025 */
9/* */
10/* Mémoire locale à une RunCommand. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ACCELERATOR_RUNCOMMANDLOCALMEMORY_H
13#define ARCANE_ACCELERATOR_RUNCOMMANDLOCALMEMORY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/accelerator/AcceleratorGlobal.h"
18
19#include "arcane/accelerator/core/RunCommand.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::Accelerator::Impl
25{
26#if defined(ARCANE_COMPILING_CUDA) || defined(ARCANE_COMPILING_HIP)
27inline __device__ std::byte* _getAcceleratorSharedMemory()
28{
29 extern __shared__ Int64 shared_memory_ptr[];
30 return reinterpret_cast<std::byte*>(shared_memory_ptr);
31}
32#endif
33} // namespace Arcane::Accelerator::Impl
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38namespace Arcane::Accelerator
39{
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43/*!
44 * \internal
45 * \brief Mémoire locale (__shared__) à une RunCommand.
46 *
47 * \warning API en cours de définition. Ne pas utiliser en dehors d'Arcane.
48 */
49template <typename T>
50class RunCommandLocalMemory
51{
52 public:
53
54 RunCommandLocalMemory(RunCommand& command, Int32 size)
55 : m_size(size)
56 {
57 command._addSharedMemory(static_cast<Int32>(sizeof(T) * size));
58 }
59
60 constexpr ARCCORE_HOST_DEVICE SmallSpan<T> span()
61 {
62 return { m_ptr, m_size };
63 }
64
65#if defined(ARCANE_COMPILING_CUDA) || defined(ARCANE_COMPILING_HIP)
66 ARCCORE_DEVICE void _internalExecWorkItemAtBegin(Int32)
67 {
68 m_ptr = reinterpret_cast<T*>(Impl::_getAcceleratorSharedMemory());
69 }
70 ARCCORE_DEVICE void _internalExecWorkItemAtEnd(Int32){};
71#endif
72
73#if defined(ARCANE_COMPILING_SYCL)
74 // NOT YET SUPPORTED
75 void _internalExecWorkItemAtBegin(sycl::nd_item<1>){}
76 void _internalExecWorkItemAtEnd(sycl::nd_item<1>) {}
77#endif
78
79 void _internalReduceHost() {}
80
81 private:
82
83 T* m_ptr = nullptr;
84 Int32 m_size = 0;
85};
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90} // namespace Arcane::Accelerator
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95#endif
Gestion d'une commande sur accélérateur.
Vue d'un tableau d'éléments de type T.
Definition Span.h:774
Espace de nom pour l'utilisation des accélérateurs.
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.