-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41564 from makortel/alpakaBackendProduct
Make every Alpaka EDProducer to store an unsigned short int for the backend
- Loading branch information
Showing
16 changed files
with
147 additions
and
11 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
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<use name="alpaka"/> | ||
<use name="boost_header"/> | ||
<use name="FWCore/Utilities" source_only="1"/> | ||
<use name="FWCore/Utilities"/> | ||
<export> | ||
<lib name="1"/> | ||
</export> |
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,14 @@ | ||
#ifndef HeterogeneousCore_AlpakaInterface_interface_Backend_h | ||
#define HeterogeneousCore_AlpakaInterface_interface_Backend_h | ||
|
||
#include <string_view> | ||
|
||
namespace cms::alpakatools { | ||
// Enumeration whose value EDModules can put in the event | ||
enum class Backend : unsigned short { SerialSync = 0, CudaAsync = 1, ROCmAsync = 2, TbbAsync = 3, size }; | ||
|
||
Backend toBackend(std::string_view name); | ||
std::string_view toString(Backend backend); | ||
} // namespace cms::alpakatools | ||
|
||
#endif |
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
#include <cassert> | ||
|
||
#include <alpaka/alpaka.hpp> | ||
|
||
namespace cms::alpakatools { | ||
|
||
namespace detail { | ||
|
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,34 @@ | ||
#include "FWCore/Utilities/interface/Exception.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/Backend.h" | ||
|
||
#include <algorithm> | ||
#include <array> | ||
|
||
namespace { | ||
constexpr const std::array<std::string_view, static_cast<short>(cms::alpakatools::Backend::size)> backendNames = { | ||
{"SerialSync", "CudaAsync", "ROCmAsync", "TbbAsync"}}; | ||
} | ||
|
||
namespace cms::alpakatools { | ||
Backend toBackend(std::string_view name) { | ||
auto found = std::find(backendNames.begin(), backendNames.end(), name); | ||
if (found == backendNames.end()) { | ||
cms::Exception ex("EnumNotFound"); | ||
ex << "Invalid backend name '" << name << "'"; | ||
ex.addContext("Calling cms::alpakatools::toBackend()"); | ||
throw ex; | ||
} | ||
return static_cast<Backend>(std::distance(backendNames.begin(), found)); | ||
} | ||
|
||
std::string_view toString(Backend backend) { | ||
auto val = static_cast<unsigned short>(backend); | ||
if (val >= static_cast<unsigned short>(Backend::size)) { | ||
cms::Exception ex("InvalidEnumValue"); | ||
ex << "Invalid backend enum value " << val; | ||
ex.addContext("Calling cms::alpakatools::toString()"); | ||
throw ex; | ||
} | ||
return backendNames[val]; | ||
} | ||
} // namespace cms::alpakatools |
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,30 @@ | ||
#define CATCH_CONFIG_MAIN | ||
#include <catch.hpp> | ||
|
||
#include "HeterogeneousCore/AlpakaInterface/interface/Backend.h" | ||
|
||
TEST_CASE("Test cms::alpakatools::toBackend", "cms::alpakatools::Backend") { | ||
SECTION("Valid string") { | ||
REQUIRE(cms::alpakatools::toBackend("SerialSync") == cms::alpakatools::Backend::SerialSync); | ||
REQUIRE(cms::alpakatools::toBackend("CudaAsync") == cms::alpakatools::Backend::CudaAsync); | ||
REQUIRE(cms::alpakatools::toBackend("ROCmAsync") == cms::alpakatools::Backend::ROCmAsync); | ||
REQUIRE(cms::alpakatools::toBackend("TbbAsync") == cms::alpakatools::Backend::TbbAsync); | ||
} | ||
SECTION("Invalid string") { | ||
REQUIRE_THROWS_WITH(cms::alpakatools::toBackend("Nonexistent"), | ||
Catch::Contains("EnumNotFound") and Catch::Contains("Invalid backend name")); | ||
} | ||
} | ||
|
||
TEST_CASE("Test cms::alpakatools::toString", "cms::alpakatools::Backend") { | ||
SECTION("Valid enum") { | ||
REQUIRE(cms::alpakatools::toString(cms::alpakatools::Backend::SerialSync) == "SerialSync"); | ||
REQUIRE(cms::alpakatools::toString(cms::alpakatools::Backend::CudaAsync) == "CudaAsync"); | ||
REQUIRE(cms::alpakatools::toString(cms::alpakatools::Backend::ROCmAsync) == "ROCmAsync"); | ||
REQUIRE(cms::alpakatools::toString(cms::alpakatools::Backend::TbbAsync) == "TbbAsync"); | ||
} | ||
SECTION("Invalid enum") { | ||
REQUIRE_THROWS_WITH(cms::alpakatools::toString(cms::alpakatools::Backend::size), | ||
Catch::Contains("InvalidEnumValue") and Catch::Contains("Invalid backend enum value")); | ||
} | ||
} |
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