Skip to content

Commit

Permalink
Merge pull request #64 from lanl/dholladay00/portable_copy
Browse files Browse the repository at this point in the history
Initial commit to remove kokkos specific code for copying views, base…
  • Loading branch information
Yurlungur authored Apr 5, 2023
2 parents 8f5970a + f470751 commit 3282337
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ include(content)
spiner_content_declare(ports-of-call
NAMESPACE spinerDeps
GIT_REPO https://github.com/lanl/ports-of-call
# NOTE: main as of Nov. 28 2022
GIT_TAG 3fffe08408b1ee754d0567a3de63cb47ce97d9f7
# most recent relase as of April 05, 2023
GIT_TAG v1.5.1
)

if(SPINER_USE_HDF)
Expand Down
1 change: 1 addition & 0 deletions spack-repo/packages/ports-of-call/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PortsOfCall(CMakePackage):
maintainers = ["rbberger"]

version("main", branch="main")
version("1.5.1", sha256="b1f0232cd6d2aac65385d77cc061ec5035283ea50d0f167e7003eae034effb78")
version("1.4.1", sha256="82d2c75fcca8bd613273fd4126749df68ccc22fbe4134ba673b4275f9972b78d")
version("1.4.0", sha256="e08ae556b7c30d14d77147d248d118cf5343a2e8c0847943385c602394bda0fa")
version("1.3.0", sha256="54b4a62539c23b1a345dd87c1eac65f4f69db4e50336cd81a15a627ce80ce7d9")
Expand Down
4 changes: 2 additions & 2 deletions spack-repo/packages/spiner/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Spiner(CMakePackage, CudaPackage):
depends_on("[email protected]:", when="@1.6.0:")
depends_on("[email protected]:2.13.9")
depends_on("[email protected]:", when="@:1.5.1")
depends_on("ports-of-call@1.3.0:", when="@1.6.0:")
depends_on("ports-of-call@1.5.1:", when="@1.6.0:")

# Currently the raw cuda backend of ports-of-call is not supported.
depends_on("ports-of-call portability_strategy=Kokkos", when="@:1.5.1 +kokkos")
Expand All @@ -63,7 +63,7 @@ class Spiner(CMakePackage, CudaPackage):
for _flag in ("~cuda", "+cuda", "~openmp", "+openmp"):
depends_on("[email protected]: " + _flag, when="+kokkos" + _flag)
depends_on(
"[email protected]: ~shared+wrapper+cuda_lambda+cuda_constexpr+cuda_relocatable_device_code",
"[email protected]: ~shared+wrapper+cuda_lambda+cuda_constexpr",
when="+cuda+kokkos",
)

Expand Down
36 changes: 10 additions & 26 deletions spiner/databox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,37 +294,21 @@ class DataBox {
return indices_[i];
}

// TODO(JMM): Add more code for more portability strategies
DataBox<T> getOnDevice() const { // getOnDevice is always a deep copy
#ifdef PORTABILITY_STRATEGY_KOKKOS
using HS = Kokkos::HostSpace;
using DMS = Kokkos::DefaultExecutionSpace::memory_space;
constexpr const bool execution_is_host{
Kokkos::SpaceAccessibility<DMS, HS>::accessible};
if (execution_is_host) {
DataBox<T> a;
a.copy(*this); // a.copy handles setting allocation status
return a;
// create device memory (host memory if no device)
T *device_data = (T *)PORTABLE_MALLOC(sizeBytes());
// copy to device
portableCopyToDevice(device_data, data_, sizeBytes());
// create new databox of size size
DataBox<T> a{device_data, dim(6), dim(5), dim(4), dim(3), dim(2), dim(1)};
a.copyShape(*this);
// set correct allocation status of the new databox
if (PortsOfCall::EXECUTION_IS_HOST) {
a.status_ = DataStatus::AllocatedHost;
} else {
using memUnmanaged = Kokkos::MemoryUnmanaged;
using HostView_t = Kokkos::View<T *, HS, memUnmanaged>;
using DeviceView_t = Kokkos::View<T *, memUnmanaged>;
using Kokkos::deep_copy;
T *device_data = (T *)PORTABLE_MALLOC(sizeBytes());
DeviceView_t devView(device_data, dataView_.GetSize());
HostView_t hostView(data_, dataView_.GetSize());
deep_copy(devView, hostView);
DataBox<T> a{devView.data(), dim(6), dim(5), dim(4),
dim(3), dim(2), dim(1)};
a.copyShape(*this);
a.status_ = DataStatus::AllocatedDevice;
return a;
}
#else // no kokkos
DataBox<T> a;
a.copy(*this); // a.copy handles allocation status.
return a;
#endif // kokkos
}

// TODO(JMM): Potentially use this for device-free
Expand Down

0 comments on commit 3282337

Please sign in to comment.