You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<limits>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<sys/time.h>
#include<Kokkos_Core.hpp>
#defineOFFSET_LIST_MAX_SIZE100//----------------------------------------------------------------------------namespaceKokkos {
structLayoutSelective {
//! Tag this class as a kokkos array layouttypedef LayoutSelective array_layout;
size_t offset_list[OFFSET_LIST_MAX_SIZE];
size_t list_size;
enum { is_extent_constructible = false };
LayoutSelective() {
for (int i = 0; i < OFFSET_LIST_MAX_SIZE; i++) {
offset_list[i] = i;
}
}
LayoutSelective(LayoutSelective const& rhs) {
list_size = rhs.list_size;
for (int i = 0; i < list_size; i++) {
offset_list[i] = rhs.offset_list[i];
}
}
LayoutSelective(LayoutSelective&&) = default;
LayoutSelective& operator=(LayoutSelective const&) = default;
LayoutSelective& operator=(LayoutSelective&&) = default;
KOKKOS_INLINE_FUNCTION
explicitLayoutSelective(constsize_t ol_ [], constsize_t size_) {
list_size = size_;
for (int i = 0; i < list_size; i++) {
offset_list[i] = ol_[i];
}
}
size_toffset( size_t ndx ) const {
KOKKOS_ASSERT( ndx >= 0 && ndx < list_size);
return offset_list[ndx];
}
};
namespaceImpl {
template <classDimension>
structViewOffset<Dimension, Kokkos::LayoutSelective, void> {
public:using is_mapping_plugin = std::true_type;
using is_regular = std::false_type;
typedefsize_t size_type;
typedef Dimension dimension_type;
typedef Kokkos::LayoutSelective array_layout;
//----------------------------------------
dimension_type m_dim;
array_layout m_selective;
// rank 1template <typename I0>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0) const {
return m_selective.offset(i0);
}
// This ViewOffset and the underlying layout only supports rank 1 Views//----------------------------------------
KOKKOS_INLINE_FUNCTION
constexpr array_layout layout() const {
returnarray_layout();
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_0() const {
return m_dim.N0;
}
/* Cardinality of the domain index space */
KOKKOS_INLINE_FUNCTION
constexpr size_type size() const {
return m_dim.N0;
}
public:/* Span of the range space, largest stride * dimension */
KOKKOS_INLINE_FUNCTION
constexpr size_type span() const {
return m_dim.N0;
}
KOKKOS_INLINE_FUNCTION constexprboolspan_is_contiguous() const {
returnfalse;
}
/* Strides of dimensions */
KOKKOS_INLINE_FUNCTION constexpr size_type stride_0() const {
return1;
}
// Stride with [ rank ] value is the total lengthtemplate <typename iType>
KOKKOS_INLINE_FUNCTION voidstride(iType* const s) const {
if (0 < dimension_type::rank) {
s[0] = 1;
}
for (int i = 1; i < 8; i++) s[i] = 0;
s[dimension_type::rank] = span();
}
//----------------------------------------ViewOffset() {
printf("constructing empty offset\n");
}
ViewOffset(const ViewOffset&) = default;
ViewOffset& operator=(const ViewOffset&) = default;
ViewOffset(std::integral_constant<unsigned, 0> const&,
Kokkos::LayoutSelective const& rhs)
: m_dim(rhs.list_size, 0, 0, 0, 0, 0, 0, 0),
m_selective(rhs) {
printf("constructing new offset: %d \n", rhs.list_size);
}
};
} // namespace Impl
} // namespace KokkosclassInnerClass {
public:double data[100];
InnerClass() {
for (int i = 0; i < 100; i++) {
data[i] = (double)i;
}
}
voidupdate( double d ) {
for (int i = 0; i < 100; i++) {
data[i] += d;
}
}
};
typedef Kokkos::LayoutRight Layout;
typedef Kokkos::LayoutSelective SubLayout;
// Allocate y, x vectors and Matrix A on device.typedef Kokkos::View<InnerClass*, Layout> ViewVectorType;
typedef Kokkos::View<InnerClass*, SubLayout, Kokkos::MemoryUnmanaged> SubViewVectorType;
intmain( int argc, char* argv[] )
{
Kokkos::initialize( argc, argv );
{
ViewVectorType a("a", 100);
for (int i = 0; i < 100; i++) {
a(i).update((double)i);
}
size_t offsets [] = {20,40};
SubLayout sl(offsets, 2);
SubViewVectorType b(a.data(), sl );
printf("b0 value at 16: %g a20 at 16: %g \n", b(0).data[16], a(20).data[16]);
printf("b1 value at 16: %g a40 at 16: %g \n", b(1).data[16], a(40).data[16]);
printf("a20 prt: %lx b20 ptr: %lx \n", (unsignedlong)(a(20).data), (unsignedlong)(b(0).data));
}
Kokkos::finalize();
return0;
}
This doesn't work because the ViewMapping function reference_type reference( I0 i0 ); skips the offset and goes straight to the handle if the layout isn't LayoutStride. These templates should also look offset_type::is_regular to make this decision because an irregular layout needs to use the offset to get the proper index.
The text was updated successfully, but these errors were encountered:
consider the following example:
This doesn't work because the ViewMapping function
reference_type reference( I0 i0 );
skips the offset and goes straight to the handle if the layout isn't LayoutStride. These templates should also look offset_type::is_regular to make this decision because an irregular layout needs to use the offset to get the proper index.The text was updated successfully, but these errors were encountered: