Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
StridedLoopRanges.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/* StridedLoopRanges.h (C) 2000-2026 */
9/* */
10/* Management of kernel launch on accelerator. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_STRIDEDLOOPRANGES_H
13#define ARCCORE_COMMON_STRIDEDLOOPRANGES_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/common/CommonGlobal.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::Accelerator::Impl
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31/*!
32 * \brief Class to manage the decomposition of a loop into multiple parts.
33 */
34class ARCCORE_COMMON_EXPORT StridedLoopRangesBase
35{
36 public:
37
38 constexpr StridedLoopRangesBase(Int32 nb_stride, Int64 nb_orig_element)
39 : m_stride_value((nb_orig_element + (nb_stride - 1)) / nb_stride)
40 , m_nb_original_element(nb_orig_element)
41 , m_nb_stride(nb_stride)
42 {
43 }
44 constexpr StridedLoopRangesBase(Int64 nb_orig_element)
45 : m_stride_value(nb_orig_element)
46 , m_nb_original_element(nb_orig_element)
47 , m_nb_stride(1)
48 {
49 }
50
51 public:
52
53 constexpr Int32 nbStride() const { return m_nb_stride; }
54 constexpr Int64 nbOriginalElement() const { return m_nb_original_element; }
55 constexpr Int64 strideValue() const { return m_stride_value; }
56
57 void setNbStride(Int32 nb_stride) { _setNbStride(nb_stride); }
58
59 private:
60
61 //! Stride value
62 Int64 m_stride_value = 0;
63 //! Number of elements in the original loop
64 Int64 m_nb_original_element = 0;
65 //! Number of strides
66 Int32 m_nb_stride = 0;
67
68 private:
69
70 void _setNbStride(Int32 nb_stride)
71 {
72 m_nb_stride = nb_stride;
73 m_stride_value = (m_nb_original_element + (nb_stride - 1)) / nb_stride;
74 }
75};
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
80/*!
81 * \brief Class to manage the decomposition of a loop into multiple parts.
82 */
83template <typename LoopBoundType_>
84class StridedLoopRanges
85: public StridedLoopRangesBase
86{
87 public:
88
89 using LoopBoundType = LoopBoundType_;
90
91 public:
92
93 StridedLoopRanges(Int32 nb_grid_stride, const LoopBoundType& orig_loop)
94 : StridedLoopRangesBase(nb_grid_stride, orig_loop.nbElement())
95 , m_orig_loop(orig_loop)
96 {
97 }
98 StridedLoopRanges(const LoopBoundType& orig_loop)
99 : StridedLoopRangesBase(orig_loop.nbElement())
100 , m_orig_loop(orig_loop)
101 {
102 }
103 constexpr const LoopBoundType& originalLoop() const { return m_orig_loop; }
104
105 private:
106
107 LoopBoundType m_orig_loop;
108};
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113template <typename LoopBoundType> ARCCORE_HOST_DEVICE LoopBoundType::LoopIndexType
114arcaneGetLoopIndexCudaHip(StridedLoopRanges<LoopBoundType> loop_bounds, Int32 index)
115{
116 return arcaneGetLoopIndexCudaHip(loop_bounds.originalLoop(), index);
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
122} // namespace Arcane::Accelerator::Impl
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127#endif
Class to manage the decomposition of a loop into multiple parts.
std::int64_t Int64
Signed integer type of 64 bits.
std::int32_t Int32
Signed integer type of 32 bits.