-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
638d138
commit 23756c6
Showing
7 changed files
with
195 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (C) The DDC development team, see COPYRIGHT.md file | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#pragma once | ||
|
||
#include <type_traits> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "ddc/chunk_common.hpp" | ||
#include "ddc/chunk_span.hpp" | ||
|
||
namespace ddc { | ||
|
||
/** Copy the content of a chunk span into another | ||
* @param[out] dst the chunk span in which to copy | ||
* @param[in] src the chunk span from which to copy | ||
* @return dst as a ChunkSpan | ||
*/ | ||
template < | ||
class ElementTypeDst, | ||
class SupportDst, | ||
class LayoutDst, | ||
class MemorySpaceDst, | ||
class ElementTypeSrc, | ||
class SupportSrc, | ||
class LayoutSrc, | ||
class MemorySpaceSrc> | ||
KOKKOS_FUNCTION auto deepcopy( | ||
ChunkSpan<ElementTypeDst, SupportDst, LayoutDst, MemorySpaceDst> const& dst, | ||
ChunkSpan<ElementTypeSrc, SupportSrc, LayoutSrc, MemorySpaceSrc> const& src) noexcept | ||
{ | ||
using ChunkDst = ChunkSpan<ElementTypeDst, SupportDst, LayoutDst, MemorySpaceDst>; | ||
using ChunkSrc = ChunkSpan<ElementTypeSrc, SupportSrc, LayoutSrc, MemorySpaceSrc>; | ||
static_assert( | ||
std::is_assignable_v<chunk_reference_t<ChunkDst>, chunk_reference_t<ChunkSrc>>, | ||
"Not assignable"); | ||
KOKKOS_ASSERT(dst.domain().extents() == src.domain().extents()); | ||
KOKKOS_ASSERT( | ||
(Kokkos::SpaceAccessibility<DDC_CURRENT_KOKKOS_SPACE, MemorySpaceSrc>::accessible)); | ||
KOKKOS_ASSERT( | ||
(Kokkos::SpaceAccessibility<DDC_CURRENT_KOKKOS_SPACE, MemorySpaceDst>::accessible)); | ||
for_each(dst.domain(), [&dst, &src](typename SupportDst::discrete_element_type const& elem) { | ||
dst(elem) = src(elem); | ||
}); | ||
return dst; | ||
} | ||
|
||
} // namespace ddc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (C) The DDC development team, see COPYRIGHT.md file | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#pragma once | ||
|
||
#include <type_traits> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "ddc/chunk_span.hpp" | ||
#include "ddc/detail/macros.hpp" | ||
#include "ddc/for_each.hpp" | ||
|
||
namespace ddc { | ||
|
||
/** Fill a chunk span with a given value | ||
* @param[out] dst the chunk span in which to copy | ||
* @param[in] value the value to fill `dst` | ||
* @return dst as a ChunkSpan | ||
*/ | ||
template <class ElementType, class Support, class Layout, class MemorySpace, class T> | ||
KOKKOS_FUNCTION auto fill( | ||
ChunkSpan<ElementType, Support, Layout, MemorySpace> const& dst, | ||
T const& value) noexcept | ||
{ | ||
static_assert( | ||
std::is_assignable_v< | ||
chunk_reference_t<ChunkSpan<ElementType, Support, Layout, MemorySpace>>, | ||
T>, | ||
"Not assignable"); | ||
KOKKOS_ASSERT((Kokkos::SpaceAccessibility<DDC_CURRENT_KOKKOS_SPACE, MemorySpace>::accessible)); | ||
for_each(dst.domain(), [&dst, &value](typename Support::discrete_element_type const& elem) { | ||
dst(elem) = value; | ||
}); | ||
return dst; | ||
} | ||
|
||
} // namespace ddc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (C) The DDC development team, see COPYRIGHT.md file | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <ddc/ddc.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace { | ||
|
||
struct DDimX; | ||
using DElemX = ddc::DiscreteElement<DDimX>; | ||
using DVectX = ddc::DiscreteVector<DDimX>; | ||
using DDomX = ddc::DiscreteDomain<DDimX>; | ||
|
||
static DElemX constexpr lbound_x(0); | ||
static DVectX constexpr nelems_x(10); | ||
|
||
} // namespace | ||
|
||
void test_nested_algorithms_for_each() | ||
{ | ||
DDomX ddom(lbound_x, nelems_x); | ||
ddc::Chunk chk(ddom, ddc::DeviceAllocator<int>()); | ||
ddc::ChunkSpan chks = chk.span_view(); | ||
ddc::parallel_for_each( | ||
ddc::DiscreteDomain<>(), | ||
KOKKOS_LAMBDA(ddc::DiscreteElement<>) { | ||
ddc::for_each(chks.domain(), [&](DElemX elem) { chks(elem) = 10; }); | ||
}); | ||
int res = ddc::parallel_transform_reduce(ddom, 0, ddc::reducer::sum<int>(), chks); | ||
EXPECT_EQ(res, 10 * ddom.size()); | ||
} | ||
|
||
TEST(NestedAlgorithms, ForEach) | ||
{ | ||
test_nested_algorithms_for_each(); | ||
} | ||
|
||
void test_nested_algorithms_transform_reduce() | ||
{ | ||
DDomX ddom(lbound_x, nelems_x); | ||
ddc::Chunk chk(ddom, ddc::DeviceAllocator<int>()); | ||
ddc::ChunkSpan chks = chk.span_view(); | ||
ddc::parallel_for_each( | ||
ddom, | ||
KOKKOS_LAMBDA(DElemX elem) { | ||
chks(elem) = ddc::transform_reduce( | ||
DDomX(lbound_x, DVectX(10)), | ||
0, | ||
ddc::reducer::sum<int>(), | ||
[&](DElemX) { return 1; }); | ||
}); | ||
int res = ddc::parallel_transform_reduce(ddom, 0, ddc::reducer::sum<int>(), chks); | ||
EXPECT_EQ(res, 10 * ddom.size()); | ||
} | ||
|
||
TEST(NestedAlgorithms, TransformReduce) | ||
{ | ||
test_nested_algorithms_transform_reduce(); | ||
} | ||
|
||
void test_nested_algorithms_fill() | ||
{ | ||
DDomX ddom(lbound_x, nelems_x); | ||
ddc::Chunk chk(ddom, ddc::DeviceAllocator<int>()); | ||
ddc::ChunkSpan chks = chk.span_view(); | ||
ddc::parallel_for_each( | ||
ddc::DiscreteDomain<>(), | ||
KOKKOS_LAMBDA(ddc::DiscreteElement<>) { ddc::fill(chks, 10); }); | ||
int res = ddc::parallel_transform_reduce(ddom, 0, ddc::reducer::sum<int>(), chks); | ||
EXPECT_EQ(res, 10 * ddom.size()); | ||
} | ||
|
||
TEST(NestedAlgorithms, Fill) | ||
{ | ||
test_nested_algorithms_fill(); | ||
} | ||
|
||
void test_nested_algorithms_deepcopy() | ||
{ | ||
DDomX ddom(lbound_x, nelems_x); | ||
ddc::Chunk chk(ddom, ddc::DeviceAllocator<int>()); | ||
ddc::ChunkSpan chks = chk.span_view(); | ||
ddc::parallel_fill(Kokkos::DefaultExecutionSpace(), chks, 10); | ||
ddc::Chunk chk2(ddom, ddc::DeviceAllocator<int>()); | ||
ddc::ChunkSpan chk2s = chk2.span_view(); | ||
ddc::parallel_for_each( | ||
ddc::DiscreteDomain<>(), | ||
KOKKOS_LAMBDA(ddc::DiscreteElement<>) { ddc::deepcopy(chk2s, chks); }); | ||
int res = ddc::parallel_transform_reduce(ddom, 0, ddc::reducer::sum<int>(), chk2s); | ||
EXPECT_EQ(res, 10 * ddom.size()); | ||
} | ||
|
||
TEST(NestedAlgorithms, Deepcopy) | ||
{ | ||
test_nested_algorithms_deepcopy(); | ||
} |