Skip to content

Commit

Permalink
[arccore,base] Corrige 'ARCCORE_HOST_DEVICE' manquant pour les foncti…
Browse files Browse the repository at this point in the history
…ons de test des dimensions des tableaux.
  • Loading branch information
grospelliergilles committed Jul 5, 2023
1 parent e4b644f commit 46b2172
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 30 deletions.
6 changes: 3 additions & 3 deletions arccore/src/base/arccore/base/ArccoreGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ typedef ARCCORE_TYPE_INT64 Int64;
/*---------------------------------------------------------------------------*/
/*
* Macros pour le support de la programmation hétérogène (CPU/GPU)
- ARCANE_DEVICE_CODE: indique une partie de code compilée uniquement sur le device
- ARCANE_HOST_DEVICE: indique que la méthode/variable est accessible à la fois
- ARCCORE_DEVICE_CODE: indique une partie de code compilée uniquement sur le device
- ARCCORE_HOST_DEVICE: indique que la méthode/variable est accessible à la fois
sur le device et l'hôte
- ARCANE_DEVICE: indique que la méthode/variable est accessible uniquement sur
- ARCCORE_DEVICE: indique que la méthode/variable est accessible uniquement sur
le device.
*/

Expand Down
86 changes: 59 additions & 27 deletions arccore/src/base/arccore/base/ArrayViewCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,48 @@ arccoreThrowNegativeSize [[noreturn]] (Int64 size);
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

//! Teste si \a size est positif ou nul et lance une exception si ce n'est pas le cas
inline constexpr ARCCORE_HOST_DEVICE void
arccoreCheckIsPositive(Int64 size)
{
if (size<0){
#ifdef ARCCORE_DEVICE_CODE
assert("'size' is negative");
#else
impl::arccoreThrowNegativeSize(size);
#endif
}
}

//! Teste si \a size est plus petit que ARCCORE_INTEGER_MAX et lance une exception si ce n'est pas le cas
inline constexpr ARCCORE_HOST_DEVICE void
arccoreCheckIsValidInteger(Int64 size)
{
if (size>=ARCCORE_INTEGER_MAX){
#ifdef ARCCORE_DEVICE_CODE
assert("'size' is bigger than ARCCORE_INTEGER_MAX");
#else
impl::arccoreThrowTooBigInteger(size);
#endif
}
}

//! Teste si \a size est plus petit que ARCCORE_INT64_MAX et lance une exception si ce n'est pas le cas
inline constexpr ARCCORE_HOST_DEVICE void
arccoreCheckIsValidInt64(size_t size)
{
if (size>=ARCCORE_INT64_MAX){
#ifdef ARCCORE_DEVICE_CODE
assert("'size' is bigger than ARCCORE_INT64_MAX");
#else
impl::arccoreThrowTooBigInt64(size);
#endif
}
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

} // End namespace Arccore::impl

namespace Arccore
Expand All @@ -153,11 +195,10 @@ namespace Arccore
* Si possible, retourne \a size convertie en un 'Integer'. Sinon, lance
* une exception de type ArgumentException.
*/
inline constexpr Integer
inline constexpr ARCCORE_HOST_DEVICE Integer
arccoreCheckArraySize(unsigned long long size)
{
if (size>=ARCCORE_INTEGER_MAX)
impl::arccoreThrowTooBigInteger(size);
impl::arccoreCheckIsValidInteger(size);
return static_cast<Integer>(size);
}

Expand All @@ -170,10 +211,8 @@ arccoreCheckArraySize(unsigned long long size)
inline constexpr Integer
arccoreCheckArraySize(long long size)
{
if (size>=ARCCORE_INTEGER_MAX)
impl::arccoreThrowTooBigInteger(size);
if (size<0)
impl::arccoreThrowNegativeSize(size);
impl::arccoreCheckIsValidInteger(size);
impl::arccoreCheckIsPositive(size);
return static_cast<Integer>(size);
}

Expand All @@ -186,8 +225,7 @@ arccoreCheckArraySize(long long size)
inline constexpr ARCCORE_BASE_EXPORT Integer
arccoreCheckArraySize(unsigned long size)
{
if (size>=ARCCORE_INTEGER_MAX)
impl::arccoreThrowTooBigInteger(size);
impl::arccoreCheckIsValidInteger(size);
return static_cast<Integer>(size);
}

Expand All @@ -198,13 +236,11 @@ arccoreCheckArraySize(unsigned long size)
* Si possible, retourne \a size convertie en un 'Integer'. Sinon, lance
* une exception de type ArgumentException.
*/
inline constexpr Integer
inline constexpr ARCCORE_HOST_DEVICE Integer
arccoreCheckArraySize(long size)
{
if (size>=ARCCORE_INTEGER_MAX)
impl::arccoreThrowTooBigInteger(size);
if (size<0)
impl::arccoreThrowNegativeSize(size);
impl::arccoreCheckIsValidInteger(size);
impl::arccoreCheckIsPositive(size);
return static_cast<Integer>(size);
}

Expand All @@ -214,11 +250,10 @@ arccoreCheckArraySize(long size)
* Si possible, retourne \a size convertie en un 'Integer'. Sinon, lance
* une exception de type ArgumentException.
*/
inline constexpr Integer
inline constexpr ARCCORE_HOST_DEVICE Integer
arccoreCheckArraySize(unsigned int size)
{
if (size>=ARCCORE_INTEGER_MAX)
impl::arccoreThrowTooBigInteger(size);
impl::arccoreCheckIsValidInteger(size);
return static_cast<Integer>(size);
}

Expand All @@ -228,13 +263,11 @@ arccoreCheckArraySize(unsigned int size)
* Si possible, retourne \a size convertie en un 'Integer'. Sinon, lance
* une exception de type ArgumentException.
*/
inline constexpr Integer
inline constexpr ARCCORE_HOST_DEVICE Integer
arccoreCheckArraySize(int size)
{
if (size>=ARCCORE_INTEGER_MAX)
impl::arccoreThrowTooBigInteger(size);
if (size<0)
impl::arccoreThrowNegativeSize(size);
impl::arccoreCheckIsValidInteger(size);
impl::arccoreCheckIsPositive(size);
return static_cast<Integer>(size);
}

Expand All @@ -245,11 +278,10 @@ arccoreCheckArraySize(int size)
* Si possible, retourne \a size convertie en un 'Int64'. Sinon, lance
* une exception de type ArgumentException.
*/
inline constexpr Int64
inline constexpr ARCCORE_HOST_DEVICE Int64
arccoreCheckLargeArraySize(size_t size)
{
if (size>=ARCCORE_INT64_MAX)
impl::arccoreThrowTooBigInt64(size);
impl::arccoreCheckIsValidInt64(size);
return static_cast<Int64>(size);
}

Expand All @@ -263,7 +295,7 @@ template<>
class ArraySizeChecker<Int32>
{
public:
template<typename SizeType>
template<typename SizeType> ARCCORE_HOST_DEVICE
static Int32 check(SizeType size)
{
return arccoreCheckArraySize(size);
Expand All @@ -275,7 +307,7 @@ template<>
class ArraySizeChecker<Int64>
{
public:
static Int64 check(std::size_t size)
static ARCCORE_HOST_DEVICE Int64 check(std::size_t size)
{
return arccoreCheckLargeArraySize(size);
}
Expand Down

0 comments on commit 46b2172

Please sign in to comment.