-
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.
Implement requireDevices() for ROCm devices
- Loading branch information
Showing
4 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
HeterogeneousCore/ROCmUtilities/interface/requireDevices.h
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,19 @@ | ||
#ifndef HeterogeneousCore_ROCmUtilities_interface_requireDevices_h | ||
#define HeterogeneousCore_ROCmUtilities_interface_requireDevices_h | ||
|
||
/** | ||
* These functions are meant to be called only from unit tests. | ||
*/ | ||
namespace cms { | ||
namespace rocmtest { | ||
|
||
/// In presence of ROCm devices, return true; otherwise print message and return false | ||
bool testDevices(); | ||
|
||
/// Print message and exit if there are no ROCm devices | ||
void requireDevices(); | ||
|
||
} // namespace rocmtest | ||
} // namespace cms | ||
|
||
#endif // HeterogeneousCore_ROCmUtilities_interface_requireDevices_h |
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 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
#include <hip/hip_runtime.h> | ||
|
||
#include "HeterogeneousCore/ROCmUtilities/interface/requireDevices.h" | ||
|
||
namespace cms::rocmtest { | ||
|
||
bool testDevices() { | ||
int devices = 0; | ||
auto status = hipGetDeviceCount(&devices); | ||
if (status != hipSuccess) { | ||
std::cerr << "Failed to initialise the ROCm runtime, the test will be skipped.\n"; | ||
return false; | ||
} | ||
if (devices == 0) { | ||
std::cerr << "No ROCm devices available, the test will be skipped.\n"; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void requireDevices() { | ||
if (not testDevices()) { | ||
exit(EXIT_SUCCESS); | ||
} | ||
} | ||
|
||
} // namespace cms::rocmtest |
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,7 +1,13 @@ | ||
<use name="HeterogeneousCore/ROCmUtilities"/> | ||
<iftool name="rocm"> | ||
<bin file="testHipCheck.cpp" name="testHipCheck"> | ||
<use name="catch2"/> | ||
<use name="rocm"/> | ||
<use name="HeterogeneousCore/ROCmUtilities"/> | ||
</bin> | ||
|
||
<bin file="testRequireROCmDevices.cpp" name="testRequireROCmDevices"> | ||
<use name="catch2"/> | ||
<use name="rocm"/> | ||
<use name="HeterogeneousCore/ROCmUtilities"/> | ||
</bin> | ||
</iftool> |
21 changes: 21 additions & 0 deletions
21
HeterogeneousCore/ROCmUtilities/test/testRequireROCmDevices.cpp
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,21 @@ | ||
// Catch2 headers | ||
#define CATCH_CONFIG_MAIN | ||
#include <catch.hpp> | ||
|
||
// ROCm headers | ||
#include <hip/hip_runtime.h> | ||
|
||
// CMSSW headers | ||
#include "HeterogeneousCore/ROCmUtilities/interface/hipCheck.h" | ||
#include "HeterogeneousCore/ROCmUtilities/interface/requireDevices.h" | ||
|
||
TEST_CASE("HeterogeneousCore/ROCmUtilities testRequireROCmDevices", "[testRequireROCmDevices]") { | ||
SECTION("Test requireDevices()") { | ||
cms::rocmtest::requireDevices(); | ||
|
||
int devices = 0; | ||
hipCheck(hipGetDeviceCount(&devices)); | ||
|
||
REQUIRE(devices > 0); | ||
} | ||
} |