-
Notifications
You must be signed in to change notification settings - Fork 8
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
75aa653
commit b75b033
Showing
3 changed files
with
106 additions
and
0 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,92 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
#pragma once | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "ddc/chunk_span.hpp" | ||
#include "ddc/kokkos_allocator.hpp" | ||
|
||
namespace ddc { | ||
|
||
/// Returns a new `Chunk` with the same layout as `src` allocated on the memory space `Space::memory_space`. | ||
template <class Space, class ElementType, class Support, class Layout, class MemorySpace> | ||
auto create_mirror( | ||
Space const& space, | ||
ChunkSpan<ElementType, Support, Layout, MemorySpace> const& src) | ||
{ | ||
return Chunk<ElementType, Support, KokkosAllocator<ElementType, typename Space::memory_space>>( | ||
src.domain()); | ||
} | ||
|
||
/// Returns a new host `Chunk` with the same layout as `src`. | ||
template <class ElementType, class Support, class Layout, class MemorySpace> | ||
auto create_mirror(ChunkSpan<ElementType, Support, Layout, MemorySpace> const& src) | ||
{ | ||
return create_mirror(Kokkos::DefaultHostExecutionSpace(), src); | ||
} | ||
|
||
/// Returns a new `Chunk` with the same layout as `src` allocated on the memory space `Space::memory_space` and operates a deep copy between the two. | ||
template <class Space, class ElementType, class Support, class Layout, class MemorySpace> | ||
auto create_mirror_and_copy( | ||
Space const& space, | ||
ChunkSpan<ElementType, Support, Layout, MemorySpace> const& src) | ||
{ | ||
Chunk<ElementType, Support, KokkosAllocator<ElementType, typename Space::memory_space>> chunk( | ||
src.domain()); | ||
deepcopy(chunk, src); | ||
return chunk; | ||
} | ||
|
||
/// Returns a new host `Chunk` with the same layout as `src` and operates a deep copy between the two. | ||
template <class ElementType, class Support, class Layout, class MemorySpace> | ||
auto create_mirror_and_copy(ChunkSpan<ElementType, Support, Layout, MemorySpace> const& src) | ||
{ | ||
return create_mirror_and_copy(Kokkos::DefaultHostExecutionSpace(), src); | ||
} | ||
|
||
/// If `src` is accessible from `space` then returns a copy of `src`, | ||
/// otherwise returns a new `Chunk` with the same layout as `src` allocated on the memory space `Space::memory_space`. | ||
template <class Space, class ElementType, class Support, class Layout, class MemorySpace> | ||
auto create_mirror_view( | ||
Space const& space, | ||
ChunkSpan<ElementType, Support, Layout, MemorySpace> const& src) | ||
{ | ||
if constexpr (Kokkos::SpaceAccessibility<Space, MemorySpace>::accessible) { | ||
return src; | ||
} else { | ||
return create_mirror(space, src); | ||
} | ||
} | ||
|
||
/// If `src` is host accessible then returns a copy of `src`, | ||
/// otherwise returns a new host `Chunk` with the same layout. | ||
template <class ElementType, class Support, class Layout, class MemorySpace> | ||
auto create_mirror_view(ChunkSpan<ElementType, Support, Layout, MemorySpace> const& src) | ||
{ | ||
return create_mirror_view(Kokkos::DefaultHostExecutionSpace(), src); | ||
} | ||
|
||
/// If `src` is accessible from `space` then returns a copy of `src`, | ||
/// otherwise returns a new `Chunk` with the same layout as `src` allocated on the memory space `Space::memory_space` and operates a deep copy between the two. | ||
template <class Space, class ElementType, class Support, class Layout, class MemorySpace> | ||
auto create_mirror_view_and_copy( | ||
Space const& space, | ||
ChunkSpan<ElementType, Support, Layout, MemorySpace> const& src) | ||
{ | ||
if constexpr (Kokkos::SpaceAccessibility<Space, MemorySpace>::accessible) { | ||
return src; | ||
} else { | ||
return create_mirror_and_copy(space, src); | ||
} | ||
} | ||
|
||
/// If `src` is host accessible then returns a copy of `src`, | ||
/// otherwise returns a new host `Chunk` with the same layout as `src` and operates a deep copy between the two. | ||
template <class ElementType, class Support, class Layout, class MemorySpace> | ||
auto create_mirror_view_and_copy(ChunkSpan<ElementType, Support, Layout, MemorySpace> const& src) | ||
{ | ||
return create_mirror_view_and_copy(Kokkos::DefaultHostExecutionSpace(), src); | ||
} | ||
|
||
} // 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