Skip to content

Commit

Permalink
Merge pull request #33 from lanl/mauneyc/update/execquery
Browse files Browse the repository at this point in the history
Draft: Add portable query for exec space
  • Loading branch information
dholladay00 authored Apr 3, 2023
2 parents 5782f9b + e82175b commit 2319b01
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc/sphinx/src/using.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ with `to` being the target location, from being the source location, and size_by
the size of the transfer in bytes. This has implemenatations for kokkos and none
portability strategies.

It may be useful to query the execution space, for example to know where memory needs to be copied.
To this end, a compile-time constant boolean can be queried:

.. cpp:var:: PortsOfCall::EXECUTION_IS_HOST

which is `true` if the host execution space can trivially access device memory space. For example,
for `PORTABILITY_STRATEGY_CUDA`, `PortsOfCall::EXECUTION_IS_HOST == false`.

portable_errors.hpp
^^^^^^^^^^^^^^^^^^^^

Expand Down
12 changes: 12 additions & 0 deletions ports-of-call/portability.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ typedef float Real;
typedef double Real;
#endif

namespace PortsOfCall{
// compile-time constant to check if execution of memory space
// will be done on the host or is offloaded
#if defined(PORTABILITY_STRATEGY_KOKKOS)
inline constexpr bool EXECUTION_IS_HOST{Kokkos::SpaceAccessibility<Kokkos::DefaultExecutionSpace::memory_space,Kokkos::HostSpace>::accessible};
#elif defined(PORTABILITY_STRATEGY_CUDA)
inline constexpr bool EXECUTION_IS_HOST{false};
#else
inline constexpr bool EXECUTION_IS_HOST{true};
#endif
} // PortsOfCall

template <typename T>
void portableCopyToDevice(T * const to, T const * const from, size_t const size_bytes) {
auto const length = size_bytes / sizeof(T);
Expand Down
16 changes: 16 additions & 0 deletions test/test_portsofcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
#define CATCH_CONFIG_RUNNER
#include "catch2/catch.hpp"

TEST_CASE("EXECUTION_IS_HOST is set correctly",
"[PortsOfCall]") {
// testing this is maybe nontrivial?
auto isHost = PortsOfCall::EXECUTION_IS_HOST;

#if defined(PORTABILITY_STRATEGY_KOKKOS)
auto checkHost = std::is_same<Kokkos::DefaultExecutionSpace, Kokkos::HostSpace::execution_space>::value;
REQUIRE( isHost == checkHost );
#elif defined(PORTABILITY_STRATEGY_CUDA)
REQUIRE( isHost == false );
#else
REQUIRE( isHost == true );
#endif

}

// this test is lifted directly from `spiner`;
// and there appears to be a significant amount of
// ports-of-call testing done there.
Expand Down

0 comments on commit 2319b01

Please sign in to comment.