|
1 | 1 | // -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
|
2 | 2 | //-----------------------------------------------------------------------------
|
3 |
| -// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com) |
| 3 | +// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com) |
4 | 4 | // See the top-level COPYRIGHT file for details.
|
5 | 5 | // SPDX-License-Identifier: Apache-2.0
|
6 | 6 | //-----------------------------------------------------------------------------
|
7 | 7 | /*---------------------------------------------------------------------------*/
|
8 |
| -/* CommonUtils.h (C) 2000-2023 */ |
| 8 | +/* CommonUtils.h (C) 2000-2024 */ |
9 | 9 | /* */
|
10 | 10 | /* Fonctions/Classes utilitaires communes à tout les runtimes. */
|
11 | 11 | /*---------------------------------------------------------------------------*/
|
@@ -75,7 +75,7 @@ class GenericDeviceStorage
|
75 | 75 | size_t size() const { return m_size; }
|
76 | 76 | void allocate(size_t new_size)
|
77 | 77 | {
|
78 |
| - if (new_size<m_size) |
| 78 | + if (new_size < m_size) |
79 | 79 | return;
|
80 | 80 | deallocate();
|
81 | 81 | #if defined(ARCANE_COMPILING_CUDA)
|
@@ -132,6 +132,52 @@ class DeviceStorage
|
132 | 132 | GenericDeviceStorage m_storage;
|
133 | 133 | };
|
134 | 134 |
|
| 135 | +/*---------------------------------------------------------------------------*/ |
| 136 | +/*---------------------------------------------------------------------------*/ |
| 137 | +/*! |
| 138 | + * \brief Itérateur sur un index. |
| 139 | + * |
| 140 | + * Permet d'itérer entre deux entiers. |
| 141 | + */ |
| 142 | +class IndexIterator |
| 143 | +{ |
| 144 | + public: |
| 145 | + |
| 146 | + using value_type = Int32; |
| 147 | + using iterator_category = std::random_access_iterator_tag; |
| 148 | + using reference = value_type&; |
| 149 | + using difference_type = ptrdiff_t; |
| 150 | + |
| 151 | + public: |
| 152 | + |
| 153 | + IndexIterator() = default; |
| 154 | + ARCCORE_HOST_DEVICE explicit IndexIterator(Int32 v) |
| 155 | + : m_value(v) |
| 156 | + {} |
| 157 | + |
| 158 | + public: |
| 159 | + |
| 160 | + ARCCORE_HOST_DEVICE IndexIterator& operator++() |
| 161 | + { |
| 162 | + ++m_value; |
| 163 | + return (*this); |
| 164 | + } |
| 165 | + ARCCORE_HOST_DEVICE IndexIterator operator+(Int32 x) const |
| 166 | + { |
| 167 | + return IndexIterator(m_value + x); |
| 168 | + } |
| 169 | + ARCCORE_HOST_DEVICE IndexIterator operator-(Int32 x) const |
| 170 | + { |
| 171 | + return IndexIterator(m_value - x); |
| 172 | + } |
| 173 | + ARCCORE_HOST_DEVICE Int32 operator*() const { return m_value; } |
| 174 | + ARCCORE_HOST_DEVICE Int32 operator[](Int32 x) const { return m_value + x; } |
| 175 | + |
| 176 | + private: |
| 177 | + |
| 178 | + Int32 m_value = 0; |
| 179 | +}; |
| 180 | + |
135 | 181 | /*---------------------------------------------------------------------------*/
|
136 | 182 | /*---------------------------------------------------------------------------*/
|
137 | 183 |
|
|
0 commit comments