Skip to content

Commit cc8ac16

Browse files
Merge pull request #1210 from arcaneframework/dev/gg-add-generic-filtering
Add more generic overloads for accelerator filtering
2 parents 9e607ab + 5338a0e commit cc8ac16

File tree

3 files changed

+321
-63
lines changed

3 files changed

+321
-63
lines changed

arcane/src/arcane/accelerator/CommonUtils.h

+49-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* CommonUtils.h (C) 2000-2023 */
8+
/* CommonUtils.h (C) 2000-2024 */
99
/* */
1010
/* Fonctions/Classes utilitaires communes à tout les runtimes. */
1111
/*---------------------------------------------------------------------------*/
@@ -75,7 +75,7 @@ class GenericDeviceStorage
7575
size_t size() const { return m_size; }
7676
void allocate(size_t new_size)
7777
{
78-
if (new_size<m_size)
78+
if (new_size < m_size)
7979
return;
8080
deallocate();
8181
#if defined(ARCANE_COMPILING_CUDA)
@@ -132,6 +132,52 @@ class DeviceStorage
132132
GenericDeviceStorage m_storage;
133133
};
134134

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+
135181
/*---------------------------------------------------------------------------*/
136182
/*---------------------------------------------------------------------------*/
137183

0 commit comments

Comments
 (0)