From 0cf87c11fe69169c2ef0ea93456b41cffbd8f0c0 Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Fri, 31 Mar 2023 15:51:28 -0600 Subject: [PATCH 1/5] add execspace check --- ports-of-call/portability.hpp | 12 ++++++++++++ test/test_portsofcall.cpp | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/ports-of-call/portability.hpp b/ports-of-call/portability.hpp index ae8e322f..73d43929 100644 --- a/ports-of-call/portability.hpp +++ b/ports-of-call/portability.hpp @@ -91,6 +91,18 @@ typedef float Real; typedef double Real; #endif +bool portableExecIsHost() +{ +#ifdef PORTABILITY_STRATEGY_KOKKOS + // check if default exec space is the same as the host exec space + return std::is_same::value; +#elif PORTABILITY_STRATEGY_CUDA + return false; +#else + return true; +#endif +} + template void portableCopyToDevice(T * const to, T const * const from, size_t const size_bytes) { auto const length = size_bytes / sizeof(T); diff --git a/test/test_portsofcall.cpp b/test/test_portsofcall.cpp index 732ea83b..ff9ba595 100644 --- a/test/test_portsofcall.cpp +++ b/test/test_portsofcall.cpp @@ -18,6 +18,22 @@ #define CATCH_CONFIG_RUNNER #include "catch2/catch.hpp" +TEST_CASE("portableExecIsHost() returns correctly", + "[portableExecIsHost]") { + // testing this is maybe nontrivial? + auto isHost = portableExecIsHost(); + +#ifdef PORTABILITY_STRATEGY_KOKKOS + auto checkHost = std::is_same::value; + REQUIRE( isHost == checkHost ); +#elif 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. From 72374b26c19bcd79922529df988315be4fbcbd6e Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Fri, 31 Mar 2023 16:05:22 -0600 Subject: [PATCH 2/5] do more explicit define check --- ports-of-call/portability.hpp | 4 ++-- test/test_portsofcall.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports-of-call/portability.hpp b/ports-of-call/portability.hpp index 73d43929..427f8f62 100644 --- a/ports-of-call/portability.hpp +++ b/ports-of-call/portability.hpp @@ -93,10 +93,10 @@ typedef double Real; bool portableExecIsHost() { -#ifdef PORTABILITY_STRATEGY_KOKKOS +#if defined(PORTABILITY_STRATEGY_KOKKOS) // check if default exec space is the same as the host exec space return std::is_same::value; -#elif PORTABILITY_STRATEGY_CUDA +#elif defined(PORTABILITY_STRATEGY_CUDA) return false; #else return true; diff --git a/test/test_portsofcall.cpp b/test/test_portsofcall.cpp index ff9ba595..b702dca5 100644 --- a/test/test_portsofcall.cpp +++ b/test/test_portsofcall.cpp @@ -23,10 +23,10 @@ TEST_CASE("portableExecIsHost() returns correctly", // testing this is maybe nontrivial? auto isHost = portableExecIsHost(); -#ifdef PORTABILITY_STRATEGY_KOKKOS +#if defined(PORTABILITY_STRATEGY_KOKKOS) auto checkHost = std::is_same::value; REQUIRE( isHost == checkHost ); -#elif PORTABILITY_STRATEGY_CUDA +#elif defined(PORTABILITY_STRATEGY_CUDA) REQUIRE( isHost == false ); #else REQUIRE( isHost == true ); From 1f6cd16471d9ddb19d99e17ea9ac75aa01e6a239 Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Mon, 3 Apr 2023 09:46:15 -0600 Subject: [PATCH 3/5] changed from function to constant, use kokkos::spaceaccessibility --- ports-of-call/portability.hpp | 12 +++++------- test/test_portsofcall.cpp | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ports-of-call/portability.hpp b/ports-of-call/portability.hpp index 427f8f62..23922cbf 100644 --- a/ports-of-call/portability.hpp +++ b/ports-of-call/portability.hpp @@ -91,17 +91,15 @@ typedef float Real; typedef double Real; #endif -bool portableExecIsHost() -{ +// compile-time constant to check if execution of memory space +// will be done on the host or is offloaded #if defined(PORTABILITY_STRATEGY_KOKKOS) - // check if default exec space is the same as the host exec space - return std::is_same::value; +inline constexpr bool execution_is_host{Kokkos::SpaceAccessibility::accessible}; #elif defined(PORTABILITY_STRATEGY_CUDA) - return false; +inline constexpr bool execution_is_host{false}; #else - return true; +inline constexpr bool execution_is_host{true}; #endif -} template void portableCopyToDevice(T * const to, T const * const from, size_t const size_bytes) { diff --git a/test/test_portsofcall.cpp b/test/test_portsofcall.cpp index b702dca5..60686b0b 100644 --- a/test/test_portsofcall.cpp +++ b/test/test_portsofcall.cpp @@ -18,10 +18,10 @@ #define CATCH_CONFIG_RUNNER #include "catch2/catch.hpp" -TEST_CASE("portableExecIsHost() returns correctly", - "[portableExecIsHost]") { +TEST_CASE("execution_is_host is set correctly", + "[portibility flags]") { // testing this is maybe nontrivial? - auto isHost = portableExecIsHost(); + auto isHost = execution_is_host; #if defined(PORTABILITY_STRATEGY_KOKKOS) auto checkHost = std::is_same::value; From 8204a9300ee492303a3737fd6c5883978c477021 Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Mon, 3 Apr 2023 11:43:54 -0600 Subject: [PATCH 4/5] namespaced, allcap --- ports-of-call/portability.hpp | 8 +++++--- test/test_portsofcall.cpp | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ports-of-call/portability.hpp b/ports-of-call/portability.hpp index 23922cbf..4f27d806 100644 --- a/ports-of-call/portability.hpp +++ b/ports-of-call/portability.hpp @@ -91,15 +91,17 @@ 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::accessible}; +inline constexpr bool EXECUTION_IS_HOST{Kokkos::SpaceAccessibility::accessible}; #elif defined(PORTABILITY_STRATEGY_CUDA) -inline constexpr bool execution_is_host{false}; +inline constexpr bool EXECUTION_IS_HOST{false}; #else -inline constexpr bool execution_is_host{true}; +inline constexpr bool EXECUTION_IS_HOST{true}; #endif +} // PortsOfCall template void portableCopyToDevice(T * const to, T const * const from, size_t const size_bytes) { diff --git a/test/test_portsofcall.cpp b/test/test_portsofcall.cpp index 60686b0b..8fb615f4 100644 --- a/test/test_portsofcall.cpp +++ b/test/test_portsofcall.cpp @@ -18,10 +18,10 @@ #define CATCH_CONFIG_RUNNER #include "catch2/catch.hpp" -TEST_CASE("execution_is_host is set correctly", - "[portibility flags]") { +TEST_CASE("EXECUTION_IS_HOST is set correctly", + "[PortsOfCall]") { // testing this is maybe nontrivial? - auto isHost = execution_is_host; + auto isHost = PortsOfCall::EXECUTION_IS_HOST; #if defined(PORTABILITY_STRATEGY_KOKKOS) auto checkHost = std::is_same::value; From e82175b00a3d6275e69feb9e608e78010ae8de33 Mon Sep 17 00:00:00 2001 From: Christopher Mauney Date: Mon, 3 Apr 2023 12:00:53 -0600 Subject: [PATCH 5/5] added docs --- doc/sphinx/src/using.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/sphinx/src/using.rst b/doc/sphinx/src/using.rst index db78e1e8..909611ea 100644 --- a/doc/sphinx/src/using.rst +++ b/doc/sphinx/src/using.rst @@ -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 ^^^^^^^^^^^^^^^^^^^^