-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 #44042 from fwyzard/make_tests_fail_gracefully_140x
Let tests fail gracefully if no devices are found [14.0.x]
- Loading branch information
Showing
32 changed files
with
599 additions
and
459 deletions.
There are no files selected for viewing
63 changes: 34 additions & 29 deletions
63
DataFormats/SiPixelClusterSoA/test/alpaka/Clusters_test.cc
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,45 +1,50 @@ | ||
#include <cstdlib> | ||
|
||
#include <alpaka/alpaka.hpp> | ||
|
||
#include "DataFormats/SiPixelClusterSoA/interface/alpaka/SiPixelClustersSoACollection.h" | ||
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersDevice.h" | ||
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersHost.h" | ||
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersSoA.h" | ||
|
||
#include "DataFormats/SiPixelClusterSoA/interface/alpaka/SiPixelClustersSoACollection.h" | ||
#include "FWCore/Utilities/interface/stringize.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/devices.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/host.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h" | ||
|
||
using namespace ALPAKA_ACCELERATOR_NAMESPACE; | ||
#include "Clusters_test.h" | ||
|
||
namespace ALPAKA_ACCELERATOR_NAMESPACE { | ||
namespace testClusterSoA { | ||
using namespace ALPAKA_ACCELERATOR_NAMESPACE; | ||
|
||
void runKernels(SiPixelClustersSoAView clust_view, Queue& queue); | ||
int main() { | ||
// Get the list of devices on the current platform | ||
auto const& devices = cms::alpakatools::devices<Platform>(); | ||
if (devices.empty()) { | ||
std::cerr << "No devices available for the " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) " backend, " | ||
"the test will be skipped.\n"; | ||
exit(EXIT_FAILURE); | ||
} | ||
} // namespace ALPAKA_ACCELERATOR_NAMESPACE | ||
|
||
int main() { | ||
const auto host = cms::alpakatools::host(); | ||
const auto device = cms::alpakatools::devices<Platform>()[0]; | ||
Queue queue(device); | ||
|
||
// Inner scope to deallocate memory before destroying the stream | ||
{ | ||
// Instantiate tracks on device. PortableDeviceCollection allocates | ||
// SoA on device automatically. | ||
SiPixelClustersSoACollection clusters_d(100, queue); | ||
testClusterSoA::runKernels(clusters_d.view(), queue); | ||
|
||
// Instantate tracks on host. This is where the data will be | ||
// copied to from device. | ||
SiPixelClustersHost clusters_h(clusters_d.view().metadata().size(), queue); | ||
|
||
std::cout << clusters_h.view().metadata().size() << std::endl; | ||
alpaka::memcpy(queue, clusters_h.buffer(), clusters_d.const_buffer()); | ||
alpaka::wait(queue); | ||
// Run the test on each device | ||
for (const auto& device : devices) { | ||
Queue queue(device); | ||
|
||
// Inner scope to deallocate memory before destroying the stream | ||
{ | ||
// Instantiate tracks on device. PortableDeviceCollection allocates | ||
// SoA on device automatically. | ||
SiPixelClustersSoACollection clusters_d(100, queue); | ||
testClusterSoA::runKernels(clusters_d.view(), queue); | ||
|
||
// Instantate tracks on host. This is where the data will be | ||
// copied to from device. | ||
SiPixelClustersHost clusters_h(clusters_d.view().metadata().size(), queue); | ||
|
||
std::cout << clusters_h.view().metadata().size() << std::endl; | ||
alpaka::memcpy(queue, clusters_h.buffer(), clusters_d.const_buffer()); | ||
alpaka::wait(queue); | ||
} | ||
} | ||
|
||
return 0; | ||
return EXIT_SUCCESS; | ||
} |
79 changes: 40 additions & 39 deletions
79
DataFormats/SiPixelClusterSoA/test/alpaka/Clusters_test.dev.cc
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,49 +1,50 @@ | ||
#include "DataFormats/SiPixelClusterSoA/interface/alpaka/SiPixelClustersSoACollection.h" | ||
#include <alpaka/alpaka.hpp> | ||
|
||
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersDevice.h" | ||
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersHost.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h" | ||
#include "DataFormats/SiPixelClusterSoA/interface/alpaka/SiPixelClustersSoACollection.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/traits.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h" | ||
|
||
#include "Clusters_test.h" | ||
|
||
using namespace alpaka; | ||
|
||
namespace ALPAKA_ACCELERATOR_NAMESPACE { | ||
|
||
using namespace cms::alpakatools; | ||
namespace testClusterSoA { | ||
|
||
class TestFillKernel { | ||
public: | ||
template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>> | ||
ALPAKA_FN_ACC void operator()(TAcc const& acc, SiPixelClustersSoAView clust_view) const { | ||
for (int32_t j : uniform_elements(acc, clust_view.metadata().size())) { | ||
clust_view[j].moduleStart() = j; | ||
clust_view[j].clusInModule() = j * 2; | ||
clust_view[j].moduleId() = j * 3; | ||
clust_view[j].clusModuleStart() = j * 4; | ||
} | ||
namespace ALPAKA_ACCELERATOR_NAMESPACE::testClusterSoA { | ||
|
||
class TestFillKernel { | ||
public: | ||
template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>> | ||
ALPAKA_FN_ACC void operator()(TAcc const& acc, SiPixelClustersSoAView clust_view) const { | ||
for (int32_t j : cms::alpakatools::uniform_elements(acc, clust_view.metadata().size())) { | ||
clust_view[j].moduleStart() = j; | ||
clust_view[j].clusInModule() = j * 2; | ||
clust_view[j].moduleId() = j * 3; | ||
clust_view[j].clusModuleStart() = j * 4; | ||
} | ||
}; | ||
|
||
class TestVerifyKernel { | ||
public: | ||
template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>> | ||
ALPAKA_FN_ACC void operator()(TAcc const& acc, SiPixelClustersSoAConstView clust_view) const { | ||
for (uint32_t j : uniform_elements(acc, clust_view.metadata().size())) { | ||
assert(clust_view[j].moduleStart() == j); | ||
assert(clust_view[j].clusInModule() == j * 2); | ||
assert(clust_view[j].moduleId() == j * 3); | ||
assert(clust_view[j].clusModuleStart() == j * 4); | ||
} | ||
} | ||
}; | ||
|
||
class TestVerifyKernel { | ||
public: | ||
template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>> | ||
ALPAKA_FN_ACC void operator()(TAcc const& acc, SiPixelClustersSoAConstView clust_view) const { | ||
for (uint32_t j : cms::alpakatools::uniform_elements(acc, clust_view.metadata().size())) { | ||
assert(clust_view[j].moduleStart() == j); | ||
assert(clust_view[j].clusInModule() == j * 2); | ||
assert(clust_view[j].moduleId() == j * 3); | ||
assert(clust_view[j].clusModuleStart() == j * 4); | ||
} | ||
}; | ||
|
||
void runKernels(SiPixelClustersSoAView clust_view, Queue& queue) { | ||
uint32_t items = 64; | ||
uint32_t groups = divide_up_by(clust_view.metadata().size(), items); | ||
auto workDiv = make_workdiv<Acc1D>(groups, items); | ||
alpaka::exec<Acc1D>(queue, workDiv, TestFillKernel{}, clust_view); | ||
alpaka::exec<Acc1D>(queue, workDiv, TestVerifyKernel{}, clust_view); | ||
} | ||
}; | ||
|
||
void runKernels(SiPixelClustersSoAView clust_view, Queue& queue) { | ||
uint32_t items = 64; | ||
uint32_t groups = cms::alpakatools::divide_up_by(clust_view.metadata().size(), items); | ||
auto workDiv = cms::alpakatools::make_workdiv<Acc1D>(groups, items); | ||
alpaka::exec<Acc1D>(queue, workDiv, TestFillKernel{}, clust_view); | ||
alpaka::exec<Acc1D>(queue, workDiv, TestVerifyKernel{}, clust_view); | ||
} | ||
|
||
} // namespace testClusterSoA | ||
} // namespace ALPAKA_ACCELERATOR_NAMESPACE | ||
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::testClusterSoA |
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,13 @@ | ||
#ifndef DataFormats_SiPixelClusterSoA_test_alpaka_Clusters_test_h | ||
#define DataFormats_SiPixelClusterSoA_test_alpaka_Clusters_test_h | ||
|
||
#include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersSoA.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
|
||
namespace ALPAKA_ACCELERATOR_NAMESPACE::testClusterSoA { | ||
|
||
void runKernels(SiPixelClustersSoAView clust_view, Queue& queue); | ||
|
||
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::testClusterSoA | ||
|
||
#endif // DataFormats_SiPixelClusterSoA_test_alpaka_Clusters_test_h |
75 changes: 40 additions & 35 deletions
75
DataFormats/SiPixelDigiSoA/test/alpaka/DigiErrors_test.cc
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,54 +1,59 @@ | ||
#include <alpaka/alpaka.hpp> | ||
#include <cstdlib> | ||
#include <unistd.h> | ||
|
||
#include <alpaka/alpaka.hpp> | ||
|
||
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsDevice.h" | ||
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsHost.h" | ||
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsSoA.h" | ||
#include "DataFormats/SiPixelDigiSoA/interface/alpaka/SiPixelDigiErrorsSoACollection.h" | ||
|
||
#include "FWCore/Utilities/interface/stringize.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/devices.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/host.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/memory.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/traits.h" | ||
|
||
using namespace ALPAKA_ACCELERATOR_NAMESPACE; | ||
#include "DigiErrors_test.h" | ||
|
||
namespace ALPAKA_ACCELERATOR_NAMESPACE { | ||
namespace testDigisSoA { | ||
using namespace ALPAKA_ACCELERATOR_NAMESPACE; | ||
|
||
void runKernels(SiPixelDigiErrorsSoAView digiErrors_view, Queue& queue); | ||
int main() { | ||
// Get the list of devices on the current platform | ||
auto const& devices = cms::alpakatools::devices<Platform>(); | ||
if (devices.empty()) { | ||
std::cerr << "No devices available for the " EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE) " backend, " | ||
"the test will be skipped.\n"; | ||
exit(EXIT_FAILURE); | ||
} | ||
} // namespace ALPAKA_ACCELERATOR_NAMESPACE | ||
|
||
int main() { | ||
const auto host = cms::alpakatools::host(); | ||
const auto device = cms::alpakatools::devices<Platform>()[0]; | ||
Queue queue(device); | ||
|
||
// Inner scope to deallocate memory before destroying the stream | ||
{ | ||
// Instantiate tracks on device. PortableDeviceCollection allocates | ||
// SoA on device automatically. | ||
SiPixelDigiErrorsSoACollection digiErrors_d(1000, queue); | ||
testDigisSoA::runKernels(digiErrors_d.view(), queue); | ||
|
||
// Instantate tracks on host. This is where the data will be | ||
// copied to from device. | ||
SiPixelDigiErrorsHost digiErrors_h(digiErrors_d.view().metadata().size(), queue); | ||
alpaka::memcpy(queue, digiErrors_h.buffer(), digiErrors_d.const_buffer()); | ||
std::cout << "digiErrors_h.view().metadata().size(): " << digiErrors_h.view().metadata().size() << std::endl; | ||
std::cout << "digiErrors_h.view()[100].pixelErrors().rawId: " << digiErrors_h.view()[100].pixelErrors().rawId | ||
<< std::endl; | ||
std::cout << "digiErrors_h.view()[100].pixelErrors().word: " << digiErrors_h.view()[100].pixelErrors().word | ||
<< std::endl; | ||
std::cout << "digiErrors_h.view()[100].pixelErrors().errorType: " | ||
<< digiErrors_h.view()[100].pixelErrors().errorType << std::endl; | ||
std::cout << "digiErrors_h.view()[100].pixelErrors().fedId: " << digiErrors_h.view()[100].pixelErrors().fedId | ||
<< std::endl; | ||
alpaka::wait(queue); | ||
// Run the test on each device | ||
for (const auto& device : devices) { | ||
Queue queue(device); | ||
|
||
// Inner scope to deallocate memory before destroying the stream | ||
{ | ||
// Instantiate tracks on device. PortableDeviceCollection allocates | ||
// SoA on device automatically. | ||
SiPixelDigiErrorsSoACollection digiErrors_d(1000, queue); | ||
testDigisSoA::runKernels(digiErrors_d.view(), queue); | ||
|
||
// Instantate tracks on host. This is where the data will be | ||
// copied to from device. | ||
SiPixelDigiErrorsHost digiErrors_h(digiErrors_d.view().metadata().size(), queue); | ||
alpaka::memcpy(queue, digiErrors_h.buffer(), digiErrors_d.const_buffer()); | ||
std::cout << "digiErrors_h.view().metadata().size(): " << digiErrors_h.view().metadata().size() << std::endl; | ||
std::cout << "digiErrors_h.view()[100].pixelErrors().rawId: " << digiErrors_h.view()[100].pixelErrors().rawId | ||
<< std::endl; | ||
std::cout << "digiErrors_h.view()[100].pixelErrors().word: " << digiErrors_h.view()[100].pixelErrors().word | ||
<< std::endl; | ||
std::cout << "digiErrors_h.view()[100].pixelErrors().errorType: " | ||
<< digiErrors_h.view()[100].pixelErrors().errorType << std::endl; | ||
std::cout << "digiErrors_h.view()[100].pixelErrors().fedId: " << digiErrors_h.view()[100].pixelErrors().fedId | ||
<< std::endl; | ||
alpaka::wait(queue); | ||
} | ||
} | ||
|
||
return 0; | ||
return EXIT_SUCCESS; | ||
} |
79 changes: 40 additions & 39 deletions
79
DataFormats/SiPixelDigiSoA/test/alpaka/DigiErrors_test.dev.cc
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,50 +1,51 @@ | ||
#include <alpaka/alpaka.hpp> | ||
|
||
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsDevice.h" | ||
#include "DataFormats/SiPixelDigiSoA/interface/alpaka/SiPixelDigiErrorsSoACollection.h" | ||
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsHost.h" | ||
#include "DataFormats/SiPixelDigiSoA/interface/alpaka/SiPixelDigiErrorsSoACollection.h" | ||
#include "DataFormats/SiPixelRawData/interface/SiPixelErrorCompact.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/traits.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/workdivision.h" | ||
|
||
#include "DigiErrors_test.h" | ||
|
||
using namespace alpaka; | ||
|
||
namespace ALPAKA_ACCELERATOR_NAMESPACE { | ||
|
||
using namespace cms::alpakatools; | ||
namespace testDigisSoA { | ||
|
||
class TestFillKernel { | ||
public: | ||
template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>> | ||
ALPAKA_FN_ACC void operator()(TAcc const& acc, SiPixelDigiErrorsSoAView digiErrors_view) const { | ||
for (uint32_t j : elements_with_stride(acc, digiErrors_view.metadata().size())) { | ||
digiErrors_view[j].pixelErrors().rawId = j; | ||
digiErrors_view[j].pixelErrors().word = j; | ||
digiErrors_view[j].pixelErrors().errorType = j; | ||
digiErrors_view[j].pixelErrors().fedId = j; | ||
} | ||
namespace ALPAKA_ACCELERATOR_NAMESPACE::testDigisSoA { | ||
|
||
class TestFillKernel { | ||
public: | ||
template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>> | ||
ALPAKA_FN_ACC void operator()(TAcc const& acc, SiPixelDigiErrorsSoAView digiErrors_view) const { | ||
for (uint32_t j : cms::alpakatools::uniform_elements(acc, digiErrors_view.metadata().size())) { | ||
digiErrors_view[j].pixelErrors().rawId = j; | ||
digiErrors_view[j].pixelErrors().word = j; | ||
digiErrors_view[j].pixelErrors().errorType = j; | ||
digiErrors_view[j].pixelErrors().fedId = j; | ||
} | ||
}; | ||
|
||
class TestVerifyKernel { | ||
public: | ||
template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>> | ||
ALPAKA_FN_ACC void operator()(TAcc const& acc, SiPixelDigiErrorsSoAConstView digiErrors_view) const { | ||
for (uint32_t j : elements_with_stride(acc, digiErrors_view.metadata().size())) { | ||
assert(digiErrors_view[j].pixelErrors().rawId == j); | ||
assert(digiErrors_view[j].pixelErrors().word == j); | ||
assert(digiErrors_view[j].pixelErrors().errorType == j % 256); | ||
assert(digiErrors_view[j].pixelErrors().fedId == j % 256); | ||
} | ||
} | ||
}; | ||
|
||
class TestVerifyKernel { | ||
public: | ||
template <typename TAcc, typename = std::enable_if_t<isAccelerator<TAcc>>> | ||
ALPAKA_FN_ACC void operator()(TAcc const& acc, SiPixelDigiErrorsSoAConstView digiErrors_view) const { | ||
for (uint32_t j : cms::alpakatools::uniform_elements(acc, digiErrors_view.metadata().size())) { | ||
assert(digiErrors_view[j].pixelErrors().rawId == j); | ||
assert(digiErrors_view[j].pixelErrors().word == j); | ||
assert(digiErrors_view[j].pixelErrors().errorType == j % 256); | ||
assert(digiErrors_view[j].pixelErrors().fedId == j % 256); | ||
} | ||
}; | ||
|
||
void runKernels(SiPixelDigiErrorsSoAView digiErrors_view, Queue& queue) { | ||
uint32_t items = 64; | ||
uint32_t groups = divide_up_by(digiErrors_view.metadata().size(), items); | ||
auto workDiv = make_workdiv<Acc1D>(groups, items); | ||
alpaka::exec<Acc1D>(queue, workDiv, TestFillKernel{}, digiErrors_view); | ||
alpaka::exec<Acc1D>(queue, workDiv, TestVerifyKernel{}, digiErrors_view); | ||
} | ||
}; | ||
|
||
void runKernels(SiPixelDigiErrorsSoAView digiErrors_view, Queue& queue) { | ||
uint32_t items = 64; | ||
uint32_t groups = cms::alpakatools::divide_up_by(digiErrors_view.metadata().size(), items); | ||
auto workDiv = cms::alpakatools::make_workdiv<Acc1D>(groups, items); | ||
alpaka::exec<Acc1D>(queue, workDiv, TestFillKernel{}, digiErrors_view); | ||
alpaka::exec<Acc1D>(queue, workDiv, TestVerifyKernel{}, digiErrors_view); | ||
} | ||
|
||
} // namespace testDigisSoA | ||
} // namespace ALPAKA_ACCELERATOR_NAMESPACE | ||
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::testDigisSoA |
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,13 @@ | ||
#ifndef DataFormats_SiPixelDigiSoA_test_alpaka_DigiErrors_test_h | ||
#define DataFormats_SiPixelDigiSoA_test_alpaka_DigiErrors_test_h | ||
|
||
#include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsSoA.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
|
||
namespace ALPAKA_ACCELERATOR_NAMESPACE::testDigisSoA { | ||
|
||
void runKernels(SiPixelDigiErrorsSoAView digiErrors_view, Queue& queue); | ||
|
||
} // namespace ALPAKA_ACCELERATOR_NAMESPACE::testDigisSoA | ||
|
||
#endif // DataFormats_SiPixelDigiSoA_test_alpaka_DigiErrors_test_h |
Oops, something went wrong.