Skip to content

Commit

Permalink
Fixes for Kokkos::Array (kokkos#6372)
Browse files Browse the repository at this point in the history
* WIP: Adding unit tests for Kokkos::Array

* Remove ScopedEnum tests (as they don't compile)

* Fix for empty() bug with contiguous and strided Kokkos::Array

* Fixed strided Kokkos::Array assignment operators

* Clean up unit tests

* Fix for char subscript warning during Kokkos::Array unit tests

* Changed Kokkos::Array<T, 0>::data() to return nullptr instead of
pointer(0), as this eliminates some compiler warnings

* Fixes for __int128 and CUDA-11.0.3 build

* Removed tests for __int128

* Fixed ch (which should be c8) for char8_t indexing tests

* Removed char and *char_t tests
(left unsigned char and signed char, as uint8_t and int8_t are
sometimes aliases for them)
Changed EnumBool to EnumShort as it is slightly more realistic
  • Loading branch information
nliber committed Sep 13, 2023
1 parent 7e35f10 commit 615fc1a
Show file tree
Hide file tree
Showing 3 changed files with 400 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/src/Kokkos_Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ struct Array<T, 0, Proxy> {
return *reinterpret_cast<const_pointer>(-1);
}

KOKKOS_INLINE_FUNCTION pointer data() { return pointer(0); }
KOKKOS_INLINE_FUNCTION const_pointer data() const { return const_pointer(0); }
KOKKOS_INLINE_FUNCTION pointer data() { return nullptr; }
KOKKOS_INLINE_FUNCTION const_pointer data() const { return nullptr; }

KOKKOS_DEFAULTED_FUNCTION ~Array() = default;
KOKKOS_DEFAULTED_FUNCTION Array() = default;
Expand Down Expand Up @@ -199,7 +199,7 @@ struct Array<T, KOKKOS_INVALID_INDEX, Array<>::contiguous> {
using const_pointer = std::add_const_t<T>*;

KOKKOS_INLINE_FUNCTION constexpr size_type size() const { return m_size; }
KOKKOS_INLINE_FUNCTION constexpr bool empty() const { return 0 != m_size; }
KOKKOS_INLINE_FUNCTION constexpr bool empty() const { return 0 == m_size; }
KOKKOS_INLINE_FUNCTION constexpr size_type max_size() const { return m_size; }

template <typename iType>
Expand Down Expand Up @@ -268,7 +268,7 @@ struct Array<T, KOKKOS_INVALID_INDEX, Array<>::strided> {
using const_pointer = std::add_const_t<T>*;

KOKKOS_INLINE_FUNCTION constexpr size_type size() const { return m_size; }
KOKKOS_INLINE_FUNCTION constexpr bool empty() const { return 0 != m_size; }
KOKKOS_INLINE_FUNCTION constexpr bool empty() const { return 0 == m_size; }
KOKKOS_INLINE_FUNCTION constexpr size_type max_size() const { return m_size; }

template <typename iType>
Expand Down Expand Up @@ -304,14 +304,14 @@ struct Array<T, KOKKOS_INVALID_INDEX, Array<>::strided> {
KOKKOS_INLINE_FUNCTION
Array& operator=(const Array& rhs) {
const size_t n = std::min(m_size, rhs.size());
for (size_t i = 0; i < n; ++i) m_elem[i] = rhs[i];
for (size_t i = 0; i < n; ++i) m_elem[i * m_stride] = rhs[i];
return *this;
}

template <size_t N, class P>
KOKKOS_INLINE_FUNCTION Array& operator=(const Array<T, N, P>& rhs) {
const size_t n = std::min(m_size, rhs.size());
for (size_t i = 0; i < n; ++i) m_elem[i] = rhs[i];
for (size_t i = 0; i < n; ++i) m_elem[i * m_stride] = rhs[i];
return *this;
}

Expand Down
1 change: 1 addition & 0 deletions core/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ foreach(Tag Threads;Serial;OpenMP;Cuda;HPX;OpenMPTarget;OpenACC;HIP;SYCL)
set(${Tag}_SOURCES1A)
foreach(Name
Abort
ArrayOps
AtomicOperations_complexdouble
AtomicOperations_complexfloat
AtomicOperations_double
Expand Down

0 comments on commit 615fc1a

Please sign in to comment.